MXS-1992 Handle 'query_classifier_cache_size' parameter
No effect yet on the caching.
This commit is contained in:
parent
6d5210b4cb
commit
466e8a923c
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
*/
|
||||
|
||||
#include "internal/query_classifier.h"
|
||||
#include <inttypes.h>
|
||||
#include <algorithm>
|
||||
#include <unordered_map>
|
||||
#include <maxscale/alloc.h>
|
||||
@ -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
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user