diff --git a/include/maxscale/query_classifier.h b/include/maxscale/query_classifier.h index 200ff316f..101a6ce6d 100644 --- a/include/maxscale/query_classifier.h +++ b/include/maxscale/query_classifier.h @@ -127,7 +127,8 @@ typedef struct qc_field_info */ typedef struct query_classifier { - bool (*qc_init)(const char* args); + bool (*qc_setup)(const char* args); + bool (*qc_init)(void); void (*qc_end)(void); bool (*qc_thread_init)(void); diff --git a/query_classifier/qc_dummy/qc_dummy.cc b/query_classifier/qc_dummy/qc_dummy.cc index 946c93a9a..719edce2e 100644 --- a/query_classifier/qc_dummy/qc_dummy.cc +++ b/query_classifier/qc_dummy/qc_dummy.cc @@ -78,7 +78,12 @@ void qc_sqlite_get_field_info(GWBUF* query, const QC_FIELD_INFO** infos, size_t* *n_infos = 0; } -bool qc_init(const char* args) +bool qc_setup(const char* args) +{ + return true; +} + +bool qc_init(void) { return true; } @@ -102,6 +107,7 @@ extern "C" { static QUERY_CLASSIFIER qc = { + qc_setup, qc_init, qc_end, qc_thread_init, diff --git a/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc b/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc index 9366d0b01..2363c8691 100644 --- a/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc +++ b/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc @@ -2487,16 +2487,21 @@ void configure_options(const char* datadir, const char* langdir) } -bool qc_init(const char* args) +bool qc_setup(const char* args) { - bool inited = false; - if (args) { MXS_WARNING("qc_mysqlembedded: '%s' provided as arguments, " "even though no arguments are supported.", args); } + return true; +} + +bool qc_init(void) +{ + bool inited = false; + if (strlen(get_langdir()) >= PATH_MAX) { fprintf(stderr, "MaxScale: error: Language path is too long: %s.", get_langdir()); @@ -2561,6 +2566,7 @@ MXS_MODULE* MXS_CREATE_MODULE() { static QUERY_CLASSIFIER qc = { + qc_setup, qc_init, qc_end, qc_thread_init, diff --git a/query_classifier/qc_sqlite/qc_sqlite.c b/query_classifier/qc_sqlite/qc_sqlite.c index cbd33a078..f90bc34ea 100644 --- a/query_classifier/qc_sqlite/qc_sqlite.c +++ b/query_classifier/qc_sqlite/qc_sqlite.c @@ -100,6 +100,7 @@ typedef enum qc_log_level static struct { bool initialized; + bool setup; qc_log_level_t log_level; } this_unit; @@ -2596,7 +2597,8 @@ void maxscaleUse(Parse* pParse, Token* pToken) /** * API */ -static bool qc_sqlite_init(const char* args); +static bool qc_sqlite_setup(const char* args); +static bool qc_sqlite_init(void); static void qc_sqlite_end(void); static bool qc_sqlite_thread_init(void); static void qc_sqlite_thread_end(void); @@ -2628,10 +2630,10 @@ static bool get_key_and_value(char* arg, const char** pkey, const char** pvalue) static char ARG_LOG_UNRECOGNIZED_STATEMENTS[] = "log_unrecognized_statements"; -static bool qc_sqlite_init(const char* args) +static bool qc_sqlite_setup(const char* args) { QC_TRACE(); - assert(!this_unit.initialized); + assert(!this_unit.setup); qc_log_level_t log_level = QC_LOG_NOTHING; @@ -2672,20 +2674,31 @@ static bool qc_sqlite_init(const char* args) } } + this_unit.setup = true; + this_unit.log_level = log_level; + + return this_unit.setup; +} + +static bool qc_sqlite_init(void) +{ + QC_TRACE(); + assert(this_unit.setup); + assert(!this_unit.initialized); + if (sqlite3_initialize() == 0) { init_builtin_functions(); this_unit.initialized = true; - this_unit.log_level = log_level; if (qc_sqlite_thread_init()) { - if (log_level != QC_LOG_NOTHING) + if (this_unit.log_level != QC_LOG_NOTHING) { const char* message; - switch (log_level) + switch (this_unit.log_level) { case QC_LOG_NON_PARSED: message = "Statements that cannot be parsed completely are logged."; @@ -3176,6 +3189,7 @@ MXS_MODULE* MXS_CREATE_MODULE() { static QUERY_CLASSIFIER qc = { + qc_sqlite_setup, qc_sqlite_init, qc_sqlite_end, qc_sqlite_thread_init, diff --git a/query_classifier/test/compare.cc b/query_classifier/test/compare.cc index 8c51124c7..ba7847b2c 100644 --- a/query_classifier/test/compare.cc +++ b/query_classifier/test/compare.cc @@ -163,9 +163,9 @@ QUERY_CLASSIFIER* get_classifier(const char* zName, const char* zArgs) if (pClassifier) { - if (!pClassifier->qc_init(zArgs)) + if (!pClassifier->qc_setup(zArgs) || !pClassifier->qc_init()) { - cerr << "error: Could not init classifier " << zName << "." << endl; + cerr << "error: Could not setup or init classifier " << zName << "." << endl; qc_unload(pClassifier); pClassifier = 0; } diff --git a/server/core/query_classifier.c b/server/core/query_classifier.c index eabcefd1f..e7358f33f 100644 --- a/server/core/query_classifier.c +++ b/server/core/query_classifier.c @@ -54,7 +54,12 @@ bool qc_init(const char* plugin_name, const char* plugin_args) if (classifier) { - success = classifier->qc_init(plugin_args); + success = classifier->qc_setup(plugin_args); + + if (success) + { + success = classifier->qc_init(); + } } return success;