From ce715e03aafad8c1b3fd7c1b6fcd05db0ccdf93d Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Mon, 27 Aug 2018 16:02:29 +0300 Subject: [PATCH] MXS-2026 Make QC default initialization simpler In test-programs and alike, QC can now be initialized with one function instead of three. --- include/maxscale/query_classifier.h | 43 +++++++++++++++++++++++++---- server/core/query_classifier.cc | 33 ++++++++++++++++++++++ 2 files changed, 70 insertions(+), 6 deletions(-) diff --git a/include/maxscale/query_classifier.h b/include/maxscale/query_classifier.h index 10339b8aa..3172cad50 100644 --- a/include/maxscale/query_classifier.h +++ b/include/maxscale/query_classifier.h @@ -462,21 +462,52 @@ typedef struct QC_CACHE_STATS * * MaxScale calls this function, so plugins should not do that. * - * @param qc_cache If non-NULL, specifies the properties of the QC cache. - * @param sql_mode The default sql mode. - * @param plugin_name The name of the plugin from which the query classifier - * should be loaded. - * @param plugin_args The arguments to be provided to the query classifier. + * @param cache_properties If non-NULL, specifies the properties of the QC cache. + * @param sql_mode The default sql mode. + * @param plugin_name The name of the plugin from which the query classifier + * should be loaded. + * @param plugin_args The arguments to be provided to the query classifier. * * @return True if the query classifier could be loaded and initialized, * false otherwise. * - * @see qc_end qc_thread_init + * @see qc_process_init qc_thread_init */ bool qc_setup(const QC_CACHE_PROPERTIES* cache_properties, qc_sql_mode_t sql_mode, const char* plugin_name, const char* plugin_args); +/** + * Loads and setups the default query classifier, and performs + * process and thread initialization. + * + * This is primary intended for making the setup of stand-alone + * test-programs simpler. + * + * @param cache_properties If non-NULL, specifies the properties of the QC cache. + * @param sql_mode The default sql mode. + * @param plugin_name The name of the plugin from which the query classifier + * should be loaded. + * @param plugin_args The arguments to be provided to the query classifier. + * + * @return True if the query classifier could be loaded and initialized, + * false otherwise. + * + * @see qc_end. + */ +bool qc_init(const QC_CACHE_PROPERTIES* cache_properties, + qc_sql_mode_t sql_mode, + const char* plugin_name, + const char* plugin_args); + +/** + * Performs thread and process finalization. + * + * This is primary intended for making the tear-down of stand-alone + * test-programs simpler. + */ +void qc_end(); + /** * Intializes the query classifier. * diff --git a/server/core/query_classifier.cc b/server/core/query_classifier.cc index c8fea18b1..ac2360840 100644 --- a/server/core/query_classifier.cc +++ b/server/core/query_classifier.cc @@ -415,6 +415,39 @@ bool qc_setup(const QC_CACHE_PROPERTIES* cache_properties, return (rv == QC_RESULT_OK) ? true : false; } +bool qc_init(const QC_CACHE_PROPERTIES* cache_properties, + qc_sql_mode_t sql_mode, + const char* plugin_name, + const char* plugin_args) +{ + QC_TRACE(); + + bool rc = qc_setup(cache_properties, sql_mode, plugin_name, plugin_args); + + if (rc) + { + rc = qc_process_init(QC_INIT_BOTH); + + if (rc) + { + rc = qc_thread_init(QC_INIT_BOTH); + + if (!rc) + { + qc_process_end(QC_INIT_BOTH); + } + } + } + + return rc; +} + +void qc_end() +{ + qc_thread_end(QC_INIT_BOTH); + qc_process_end(QC_INIT_BOTH); +} + bool qc_process_init(uint32_t kind) { QC_TRACE();