Perform query classifier initialization implicitly

The setting up and the initialization of the query classifier has
now been separated. The gateway explicitly sets up the query
classifier (i.e. chooses which one to use and what arguments to
provide), but the actual initialization is performed as part of
the general module initialization.
This commit is contained in:
Johan Wikman
2017-01-05 19:24:58 +02:00
parent 530c0e9617
commit 8fc5bdc2f1
13 changed files with 116 additions and 96 deletions

View File

@ -83,21 +83,21 @@ bool qc_setup(const char* args)
return true;
}
bool qc_init(void)
int qc_dummy_process_init(void)
{
return true;
return 0;
}
void qc_end(void)
void qc_dummy_process_end(void)
{
}
bool qc_thread_init(void)
int qc_dummy_thread_init(void)
{
return true;
return 0;
}
void qc_thread_end(void)
void qc_dummy_thread_end(void)
{
}
@ -108,10 +108,10 @@ extern "C"
static QUERY_CLASSIFIER qc =
{
qc_setup,
qc_init,
qc_end,
qc_thread_init,
qc_thread_end,
qc_dummy_process_init,
qc_dummy_process_end,
qc_dummy_thread_init,
qc_dummy_thread_end,
qc_parse,
qc_get_type,
qc_get_operation,
@ -135,10 +135,10 @@ extern "C"
"Dummy Query Classifier",
"V1.0.0",
&qc,
NULL, /* Process init. */
NULL, /* Process finish. */
NULL, /* Thread init. */
NULL, /* Thread finish. */
qc_dummy_process_init,
qc_dummy_process_end,
qc_dummy_thread_init,
qc_dummy_thread_end,
{
{MXS_END_MODULE_PARAMS}
}

View File

@ -2477,7 +2477,7 @@ void configure_options(const char* datadir, const char* langdir)
server_options[IDX_DATADIR] = datadir_arg;
rv = sprintf(language_arg, "--language=%s", langdir);
ss_dassert(rv < OPTIONS_LANGUAGE_SIZE); // Ensured by qc_init().
ss_dassert(rv < OPTIONS_LANGUAGE_SIZE); // Ensured by qc_process_init().
server_options[IDX_LANGUAGE] = language_arg;
// To prevent warning of unused variable when built in release mode,
@ -2498,7 +2498,7 @@ bool qc_setup(const char* args)
return true;
}
bool qc_init(void)
int qc_mysql_process_init(void)
{
bool inited = false;
@ -2530,15 +2530,15 @@ bool qc_init(void)
}
}
return inited;
return inited ? 0 : -1;
}
void qc_end(void)
void qc_mysql_process_end(void)
{
mysql_library_end();
}
bool qc_thread_init(void)
int qc_mysql_thread_init(void)
{
bool inited = (mysql_thread_init() == 0);
@ -2547,10 +2547,10 @@ bool qc_thread_init(void)
MXS_ERROR("mysql_thread_init() failed.");
}
return inited;
return inited ? 0 : -1;
}
void qc_thread_end(void)
void qc_mysql_thread_end(void)
{
mysql_thread_end();
}
@ -2567,10 +2567,10 @@ MXS_MODULE* MXS_CREATE_MODULE()
static QUERY_CLASSIFIER qc =
{
qc_setup,
qc_init,
qc_end,
qc_thread_init,
qc_thread_end,
qc_mysql_process_init,
qc_mysql_process_end,
qc_mysql_thread_init,
qc_mysql_thread_end,
qc_parse,
qc_get_type,
qc_get_operation,
@ -2594,10 +2594,10 @@ MXS_MODULE* MXS_CREATE_MODULE()
"Query classifier based upon MySQL Embedded",
"V1.0.0",
&qc,
NULL, /* Process init. */
NULL, /* Process finish. */
NULL, /* Thread init. */
NULL, /* Thread finish. */
qc_mysql_process_init,
qc_mysql_process_end,
qc_mysql_thread_init,
qc_mysql_thread_end,
{
{MXS_END_MODULE_PARAMS}
}

View File

@ -2598,9 +2598,9 @@ void maxscaleUse(Parse* pParse, Token* pToken)
* API
*/
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 int qc_sqlite_process_init(void);
static void qc_sqlite_process_end(void);
static int qc_sqlite_thread_init(void);
static void qc_sqlite_thread_end(void);
static qc_parse_result_t qc_sqlite_parse(GWBUF* query);
static uint32_t qc_sqlite_get_type(GWBUF* query);
@ -2680,7 +2680,7 @@ static bool qc_sqlite_setup(const char* args)
return this_unit.setup;
}
static bool qc_sqlite_init(void)
static int qc_sqlite_process_init(void)
{
QC_TRACE();
assert(this_unit.setup);
@ -2692,7 +2692,7 @@ static bool qc_sqlite_init(void)
this_unit.initialized = true;
if (qc_sqlite_thread_init())
if (qc_sqlite_thread_init() == 0)
{
if (this_unit.log_level != QC_LOG_NOTHING)
{
@ -2731,10 +2731,10 @@ static bool qc_sqlite_init(void)
MXS_ERROR("Failed to initialize sqlite3.");
}
return this_unit.initialized;
return this_unit.initialized ? 0 : -1;
}
static void qc_sqlite_end(void)
static void qc_sqlite_process_end(void)
{
QC_TRACE();
ss_dassert(this_unit.initialized);
@ -2747,7 +2747,7 @@ static void qc_sqlite_end(void)
this_unit.initialized = false;
}
static bool qc_sqlite_thread_init(void)
static int qc_sqlite_thread_init(void)
{
QC_TRACE();
ss_dassert(this_unit.initialized);
@ -2798,7 +2798,7 @@ static bool qc_sqlite_thread_init(void)
(unsigned long) pthread_self(), rc, sqlite3_errstr(rc));
}
return this_thread.initialized;
return this_thread.initialized ? 0 : -1;
}
static void qc_sqlite_thread_end(void)
@ -3190,8 +3190,8 @@ MXS_MODULE* MXS_CREATE_MODULE()
static QUERY_CLASSIFIER qc =
{
qc_sqlite_setup,
qc_sqlite_init,
qc_sqlite_end,
qc_sqlite_process_init,
qc_sqlite_process_end,
qc_sqlite_thread_init,
qc_sqlite_thread_end,
qc_sqlite_parse,
@ -3217,10 +3217,10 @@ MXS_MODULE* MXS_CREATE_MODULE()
"Query classifier using sqlite.",
"V1.0.0",
&qc,
NULL, /* Process init. */
NULL, /* Process finish. */
NULL, /* Thread init. */
NULL, /* Thread finish. */
qc_sqlite_process_init,
qc_sqlite_process_end,
qc_sqlite_thread_init,
qc_sqlite_thread_end,
{
{MXS_END_MODULE_PARAMS}
}

View File

@ -46,8 +46,8 @@ int main(int argc, char** argv)
set_langdir(strdup("."));
set_process_datadir(strdup("/tmp"));
qc_init("qc_sqlite", NULL);
qc_thread_init();
qc_setup("qc_sqlite", NULL);
qc_process_init();
infile = fopen(argv[1],"rb");
outfile = fopen(argv[2],"wb");
@ -83,7 +83,6 @@ int main(int argc, char** argv)
}
fclose(infile);
fclose(outfile);
qc_thread_end();
qc_end();
qc_process_end();
return 0;
}

View File

@ -314,10 +314,10 @@ int main(int argc, char** argv)
if (mxs_log_init(NULL, ".", MXS_LOG_TARGET_DEFAULT))
{
if (qc_init(lib, NULL))
if (qc_setup(lib, NULL) && qc_process_init())
{
rc = run(input_name, expected_name);
qc_end();
qc_process_end();
}
else
{

View File

@ -163,7 +163,7 @@ QUERY_CLASSIFIER* get_classifier(const char* zName, const char* zArgs)
if (pClassifier)
{
if (!pClassifier->qc_setup(zArgs) || !pClassifier->qc_init())
if (!pClassifier->qc_setup(zArgs) || (pClassifier->qc_process_init() != 0))
{
cerr << "error: Could not setup or init classifier " << zName << "." << endl;
qc_unload(pClassifier);
@ -178,7 +178,7 @@ void put_classifier(QUERY_CLASSIFIER* pClassifier)
{
if (pClassifier)
{
pClassifier->qc_end();
pClassifier->qc_process_end();
qc_unload(pClassifier);
}
}

View File

@ -41,7 +41,7 @@ int main()
set_libdir(strdup("../qc_sqlite"));
if (qc_init("qc_sqlite", NULL))
if (qc_setup("qc_sqlite", NULL) && qc_process_init())
{
const char s[] = "SELECT @@global.max_allowed_packet";
@ -53,7 +53,7 @@ int main()
// code generator.
qc_parse(stmt);
qc_end();
qc_process_end();
rv = EXIT_SUCCESS;
}