Files
MaxScale/query_classifier/query_classifier.cc
Johan Wikman e840f92cbb Make query_classifier a wrapper.
The query_classifier library is now only a wrapper that loads an
actual query classifier implementation. Currently it is hardwired
to load qc_mysqlembedded, which implements the query classifier
API using MySQL embedded.

This will be changed, so that the library to load is specified
when qc_init() is called. That will then allow the query classifier
to be specified in the config file.

Currently there seems to be a conflict between the mysql_library_end()
call made in qc_mysqlembedded and the mysql_library_end() call made in
gateway.c. The reason is that they both finalize a shared library.
For the time being mysql_library_end() is not called in gateway.c.
This problem is likely to go away by switching from the client
library to the connector-c library.
2016-01-29 16:35:03 +02:00

178 lines
3.5 KiB
C++

/**
* @section LICENCE
*
* This file is distributed as part of the MariaDB Corporation MaxScale. It is
* free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the
* Free Software Foundation, version 2.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* Copyright MariaDB Corporation Ab
*
* @file
*
*/
#include <query_classifier.h>
#include <log_manager.h>
#include <modules.h>
//#define QC_TRACE_ENABLED
#undef QC_TRACE_ENABLED
#if defined(QC_TRACE_ENABLED)
#define QC_TRACE() MXS_NOTICE(__func__)
#else
#define QC_TRACE()
#endif
static const char default_qc_name[] = "qc_mysqlembedded";
static QUERY_CLASSIFIER* classifier;
bool qc_init(int argc, char** argv, char** groups)
{
QC_TRACE();
ss_dassert(!classifier);
bool success = false;
void* module = load_module(default_qc_name, MODULE_QUERY_CLASSIFIER);
if (module)
{
classifier = (QUERY_CLASSIFIER*) module;
MXS_NOTICE("%s loaded.", default_qc_name);
success = classifier->qc_init(argc, argv, groups);
}
else
{
MXS_ERROR("Could not load %s.", default_qc_name);
}
return success;
}
void qc_end()
{
QC_TRACE();
ss_dassert(classifier);
classifier->qc_end();
classifier = NULL;
}
bool qc_thread_init()
{
QC_TRACE();
ss_dassert(classifier);
return classifier->qc_thread_init();
}
void qc_thread_end()
{
QC_TRACE();
ss_dassert(classifier);
return classifier->qc_thread_end();
}
qc_query_type_t qc_get_type(GWBUF* query)
{
QC_TRACE();
ss_dassert(classifier);
return classifier->qc_get_type(query);
}
qc_query_op_t qc_get_operation(GWBUF* query)
{
QC_TRACE();
ss_dassert(classifier);
return classifier->qc_get_operation(query);
}
char* qc_get_created_table_name(GWBUF* query)
{
QC_TRACE();
ss_dassert(classifier);
return classifier->qc_get_created_table_name(query);
}
bool qc_is_drop_table_query(GWBUF* query)
{
QC_TRACE();
ss_dassert(classifier);
return classifier->qc_is_drop_table_query(query);
}
bool qc_is_real_query(GWBUF* query)
{
QC_TRACE();
ss_dassert(classifier);
return classifier->qc_is_real_query(query);
}
char** qc_get_table_names(GWBUF* query, int* tblsize, bool fullnames)
{
QC_TRACE();
ss_dassert(classifier);
return classifier->qc_get_table_names(query, tblsize, fullnames);
}
char* qc_get_canonical(GWBUF* query)
{
QC_TRACE();
ss_dassert(classifier);
return classifier->qc_get_canonical(query);
}
bool qc_query_has_clause(GWBUF* query)
{
QC_TRACE();
ss_dassert(classifier);
return classifier->qc_query_has_clause(query);
}
char* qc_get_qtype_str(qc_query_type_t qtype)
{
QC_TRACE();
ss_dassert(classifier);
return classifier->qc_get_qtype_str(qtype);
}
char* qc_get_affected_fields(GWBUF* query)
{
QC_TRACE();
ss_dassert(classifier);
return classifier->qc_get_affected_fields(query);
}
char** qc_get_database_names(GWBUF* query, int* sizep)
{
QC_TRACE();
ss_dassert(classifier);
return classifier->qc_get_database_names(query, sizep);
}