MXS-2026 Separate QC process and thread initialization
qc_thread_init() must now explicitly be called in every thread and not just in other threads but the one where qc_process_init() is called. This change was caused by QC_INIT_SELF initialization actually being performed in query_classifier.cc. Before this change, there actually was a leak in the routing worker running in the main thread, the query classification cache was created twice.
This commit is contained in:
@ -441,19 +441,11 @@ bool qc_process_init(uint32_t kind)
|
||||
}
|
||||
}
|
||||
|
||||
bool rc = qc_thread_init(QC_INIT_SELF);
|
||||
bool rc = true;
|
||||
|
||||
if (rc)
|
||||
if (kind & QC_INIT_PLUGIN)
|
||||
{
|
||||
if (kind & QC_INIT_PLUGIN)
|
||||
{
|
||||
rc = this_unit.classifier->qc_process_init() == 0;
|
||||
|
||||
if (!rc)
|
||||
{
|
||||
qc_thread_end(QC_INIT_SELF);
|
||||
}
|
||||
}
|
||||
rc = this_unit.classifier->qc_process_init() == 0;
|
||||
}
|
||||
|
||||
return rc;
|
||||
@ -468,8 +460,6 @@ void qc_process_end(uint32_t kind)
|
||||
{
|
||||
this_unit.classifier->qc_process_end();
|
||||
}
|
||||
|
||||
qc_thread_end(QC_INIT_SELF);
|
||||
}
|
||||
|
||||
QUERY_CLASSIFIER* qc_load(const char* plugin_name)
|
||||
@ -502,12 +492,19 @@ bool qc_thread_init(uint32_t kind)
|
||||
|
||||
bool rc = false;
|
||||
|
||||
this_thread.pInfo_cache = new (std::nothrow) QCInfoCache;
|
||||
|
||||
if (this_thread.pInfo_cache)
|
||||
if (kind & QC_INIT_SELF)
|
||||
{
|
||||
mxb_assert(!this_thread.pInfo_cache);
|
||||
this_thread.pInfo_cache = new (std::nothrow) QCInfoCache;
|
||||
rc = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = true;
|
||||
}
|
||||
|
||||
if (rc)
|
||||
{
|
||||
if (kind & QC_INIT_PLUGIN)
|
||||
{
|
||||
rc = this_unit.classifier->qc_thread_init() == 0;
|
||||
@ -515,8 +512,11 @@ bool qc_thread_init(uint32_t kind)
|
||||
|
||||
if (!rc)
|
||||
{
|
||||
delete this_thread.pInfo_cache;
|
||||
this_thread.pInfo_cache = nullptr;
|
||||
if (kind & QC_INIT_SELF)
|
||||
{
|
||||
delete this_thread.pInfo_cache;
|
||||
this_thread.pInfo_cache = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -533,8 +533,11 @@ void qc_thread_end(uint32_t kind)
|
||||
this_unit.classifier->qc_thread_end();
|
||||
}
|
||||
|
||||
delete this_thread.pInfo_cache;
|
||||
this_thread.pInfo_cache = nullptr;
|
||||
if (kind & QC_INIT_SELF)
|
||||
{
|
||||
delete this_thread.pInfo_cache;
|
||||
this_thread.pInfo_cache = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
qc_parse_result_t qc_parse(GWBUF* query, uint32_t collect)
|
||||
|
||||
@ -186,9 +186,9 @@ int main(int argc, char* argv[])
|
||||
set_libdir(strdup("../../../query_classifier/qc_sqlite"));
|
||||
|
||||
// We have to setup something in order for the regexes to be compiled.
|
||||
if (qc_setup(NULL, QC_SQL_MODE_DEFAULT, "qc_sqlite", NULL) &&
|
||||
qc_process_init(QC_INIT_BOTH) &&
|
||||
qc_thread_init(QC_INIT_BOTH))
|
||||
if (qc_setup(NULL, QC_SQL_MODE_DEFAULT, "qc_sqlite", NULL)
|
||||
&& qc_process_init(QC_INIT_BOTH)
|
||||
&& qc_thread_init(QC_INIT_BOTH))
|
||||
{
|
||||
Tester tester(verbosity);
|
||||
|
||||
@ -218,6 +218,7 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
}
|
||||
|
||||
qc_thread_end(QC_INIT_BOTH);
|
||||
qc_process_end(QC_INIT_BOTH);
|
||||
}
|
||||
else
|
||||
|
||||
@ -423,9 +423,9 @@ int main(int argc, char* argv[])
|
||||
set_libdir(strdup("../../../query_classifier/qc_sqlite"));
|
||||
|
||||
// We have to setup something in order for the regexes to be compiled.
|
||||
if (qc_setup(NULL, QC_SQL_MODE_DEFAULT, "qc_sqlite", NULL) &&
|
||||
qc_process_init(QC_INIT_BOTH) &&
|
||||
qc_thread_init(QC_INIT_BOTH))
|
||||
if (qc_setup(NULL, QC_SQL_MODE_DEFAULT, "qc_sqlite", NULL)
|
||||
&& qc_process_init(QC_INIT_BOTH)
|
||||
&& qc_thread_init(QC_INIT_BOTH))
|
||||
{
|
||||
rc = EXIT_SUCCESS;
|
||||
|
||||
@ -451,6 +451,7 @@ int main(int argc, char* argv[])
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
qc_thread_end(QC_INIT_BOTH);
|
||||
qc_process_end(QC_INIT_BOTH);
|
||||
}
|
||||
else
|
||||
|
||||
@ -397,13 +397,14 @@ int main()
|
||||
pConfig->n_threads = 1;
|
||||
|
||||
set_libdir(MXS_STRDUP_A("../../../../../query_classifier/qc_sqlite/"));
|
||||
if (qc_setup(NULL, QC_SQL_MODE_DEFAULT, "qc_sqlite", "") &&
|
||||
qc_process_init(QC_INIT_BOTH) &&
|
||||
qc_thread_init(QC_INIT_BOTH))
|
||||
if (qc_setup(NULL, QC_SQL_MODE_DEFAULT, "qc_sqlite", "")
|
||||
&& qc_process_init(QC_INIT_BOTH)
|
||||
&& qc_thread_init(QC_INIT_BOTH))
|
||||
{
|
||||
set_libdir(MXS_STRDUP_A("../"));
|
||||
rc = test();
|
||||
|
||||
qc_thread_end(QC_INIT_BOTH);
|
||||
qc_process_end(QC_INIT_BOTH);
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user