From 466e8a923cc2d84c4b0557484cadd7f03d724661 Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Tue, 31 Jul 2018 09:44:41 +0300 Subject: [PATCH] MXS-1992 Handle 'query_classifier_cache_size' parameter No effect yet on the caching. --- include/maxscale/query_classifier.h | 1 + server/core/config.cc | 14 +++++++++++--- server/core/query_classifier.cc | 23 +++++++++++++---------- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/include/maxscale/query_classifier.h b/include/maxscale/query_classifier.h index c7f3d1a07..dbd4aa5a3 100644 --- a/include/maxscale/query_classifier.h +++ b/include/maxscale/query_classifier.h @@ -439,6 +439,7 @@ typedef struct query_classifier */ typedef struct QC_CACHE_PROPERTIES { + int64_t max_size; /** The maximum size of the cache. */ } QC_CACHE_PROPERTIES; /** diff --git a/server/core/config.cc b/server/core/config.cc index 21bec653f..ca957afa7 100644 --- a/server/core/config.cc +++ b/server/core/config.cc @@ -127,7 +127,7 @@ const char CN_PORT[] = "port"; const char CN_PROTOCOL[] = "protocol"; const char CN_QUERY_CLASSIFIER[] = "query_classifier"; const char CN_QUERY_CLASSIFIER_ARGS[] = "query_classifier_args"; -const char CN_QUERY_CLASSIFIER_CACHE[] = "query_classifier_cache"; +const char CN_QUERY_CLASSIFIER_CACHE_SIZE[] = "query_classifier_cache_size"; const char CN_QUERY_RETRIES[] = "query_retries"; const char CN_QUERY_RETRY_TIMEOUT[] = "query_retry_timeout"; const char CN_RELATIONSHIPS[] = "relationships"; @@ -2119,9 +2119,17 @@ handle_global_item(const char *name, const char *value) { gateway.qc_args = MXS_STRDUP_A(value); } - else if (strcmp(name, CN_QUERY_CLASSIFIER_CACHE) == 0) + else if (strcmp(name, CN_QUERY_CLASSIFIER_CACHE_SIZE) == 0) { - static QC_CACHE_PROPERTIES cache_properties; + static QC_CACHE_PROPERTIES cache_properties = { INT64_MAX }; + + cache_properties.max_size = get_suffixed_size(value); + + if (cache_properties.max_size < 0) + { + // Someone got carried away; we'll just silently adjust the value. + cache_properties.max_size = INT64_MAX; + } gateway.qc_cache_properties = &cache_properties; } diff --git a/server/core/query_classifier.cc b/server/core/query_classifier.cc index 28e0d126d..ab6b46104 100644 --- a/server/core/query_classifier.cc +++ b/server/core/query_classifier.cc @@ -12,6 +12,7 @@ */ #include "internal/query_classifier.h" +#include #include #include #include @@ -51,13 +52,13 @@ static struct this_unit QUERY_CLASSIFIER* classifier; qc_trx_parse_using_t qc_trx_parse_using; qc_sql_mode_t qc_sql_mode; - int32_t use_cached_result; + int64_t cache_max_size; } this_unit = { - nullptr, - QC_TRX_PARSE_USING_PARSER, - QC_SQL_MODE_DEFAULT, - 1 // TODO: Make this configurable + nullptr, // classifier + QC_TRX_PARSE_USING_PARSER, // qc_trx_parse_using + QC_SQL_MODE_DEFAULT, // qc_sql_mode + INT64_MAX // cache_max_size; TODO: Make this configurable }; class QCInfoCache; @@ -178,7 +179,7 @@ private: bool use_cached_result() { - return atomic_load_int32(&this_unit.use_cached_result) != 0; + return atomic_load_int64(&this_unit.cache_max_size) != 0; } bool has_not_been_parsed(GWBUF* pStmt) @@ -279,18 +280,20 @@ bool qc_setup(const QC_CACHE_PROPERTIES* cache_properties, { this_unit.qc_sql_mode = sql_mode; - bool use_cached_result = (cache_properties != nullptr); + int64_t cache_max_size = (cache_properties ? cache_properties->max_size : 0); + ss_dassert(cache_max_size >= 0); - if (use_cached_result) + if (cache_max_size) { - MXS_NOTICE("Query classification results are cached and reused."); + MXS_NOTICE("Query classification results are cached and reused, " + "cache max size: %" PRIi64 "", cache_max_size); } else { MXS_NOTICE("Query classification results are not cached."); } - this_unit.use_cached_result = use_cached_result; + this_unit.cache_max_size = cache_max_size; } else {