QC: Setup and initialization separated

This is in preparation for using the general process/thread
initialization mechanism.
This commit is contained in:
Johan Wikman
2017-01-05 17:30:04 +02:00
parent a0181133fe
commit 530c0e9617
6 changed files with 46 additions and 14 deletions

View File

@ -127,7 +127,8 @@ typedef struct qc_field_info
*/ */
typedef struct query_classifier typedef struct query_classifier
{ {
bool (*qc_init)(const char* args); bool (*qc_setup)(const char* args);
bool (*qc_init)(void);
void (*qc_end)(void); void (*qc_end)(void);
bool (*qc_thread_init)(void); bool (*qc_thread_init)(void);

View File

@ -78,7 +78,12 @@ void qc_sqlite_get_field_info(GWBUF* query, const QC_FIELD_INFO** infos, size_t*
*n_infos = 0; *n_infos = 0;
} }
bool qc_init(const char* args) bool qc_setup(const char* args)
{
return true;
}
bool qc_init(void)
{ {
return true; return true;
} }
@ -102,6 +107,7 @@ extern "C"
{ {
static QUERY_CLASSIFIER qc = static QUERY_CLASSIFIER qc =
{ {
qc_setup,
qc_init, qc_init,
qc_end, qc_end,
qc_thread_init, qc_thread_init,

View File

@ -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) if (args)
{ {
MXS_WARNING("qc_mysqlembedded: '%s' provided as arguments, " MXS_WARNING("qc_mysqlembedded: '%s' provided as arguments, "
"even though no arguments are supported.", args); "even though no arguments are supported.", args);
} }
return true;
}
bool qc_init(void)
{
bool inited = false;
if (strlen(get_langdir()) >= PATH_MAX) if (strlen(get_langdir()) >= PATH_MAX)
{ {
fprintf(stderr, "MaxScale: error: Language path is too long: %s.", get_langdir()); 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 = static QUERY_CLASSIFIER qc =
{ {
qc_setup,
qc_init, qc_init,
qc_end, qc_end,
qc_thread_init, qc_thread_init,

View File

@ -100,6 +100,7 @@ typedef enum qc_log_level
static struct static struct
{ {
bool initialized; bool initialized;
bool setup;
qc_log_level_t log_level; qc_log_level_t log_level;
} this_unit; } this_unit;
@ -2596,7 +2597,8 @@ void maxscaleUse(Parse* pParse, Token* pToken)
/** /**
* API * 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 void qc_sqlite_end(void);
static bool qc_sqlite_thread_init(void); static bool qc_sqlite_thread_init(void);
static void qc_sqlite_thread_end(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 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(); QC_TRACE();
assert(!this_unit.initialized); assert(!this_unit.setup);
qc_log_level_t log_level = QC_LOG_NOTHING; 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) if (sqlite3_initialize() == 0)
{ {
init_builtin_functions(); init_builtin_functions();
this_unit.initialized = true; this_unit.initialized = true;
this_unit.log_level = log_level;
if (qc_sqlite_thread_init()) if (qc_sqlite_thread_init())
{ {
if (log_level != QC_LOG_NOTHING) if (this_unit.log_level != QC_LOG_NOTHING)
{ {
const char* message; const char* message;
switch (log_level) switch (this_unit.log_level)
{ {
case QC_LOG_NON_PARSED: case QC_LOG_NON_PARSED:
message = "Statements that cannot be parsed completely are logged."; message = "Statements that cannot be parsed completely are logged.";
@ -3176,6 +3189,7 @@ MXS_MODULE* MXS_CREATE_MODULE()
{ {
static QUERY_CLASSIFIER qc = static QUERY_CLASSIFIER qc =
{ {
qc_sqlite_setup,
qc_sqlite_init, qc_sqlite_init,
qc_sqlite_end, qc_sqlite_end,
qc_sqlite_thread_init, qc_sqlite_thread_init,

View File

@ -163,9 +163,9 @@ QUERY_CLASSIFIER* get_classifier(const char* zName, const char* zArgs)
if (pClassifier) 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); qc_unload(pClassifier);
pClassifier = 0; pClassifier = 0;
} }

View File

@ -54,7 +54,12 @@ bool qc_init(const char* plugin_name, const char* plugin_args)
if (classifier) if (classifier)
{ {
success = classifier->qc_init(plugin_args); success = classifier->qc_setup(plugin_args);
if (success)
{
success = classifier->qc_init();
}
} }
return success; return success;