diff --git a/include/maxscale/query_classifier.h b/include/maxscale/query_classifier.h index c9d169cd5..c3fa64e76 100644 --- a/include/maxscale/query_classifier.h +++ b/include/maxscale/query_classifier.h @@ -863,6 +863,22 @@ void qc_set_server_version(uint64_t version); */ uint64_t qc_get_server_version(); +/** + * Get the cache properties. + * + * @param properties[out] Cache properties. + * + * @return True, if caching is enabled, false otherwise. + */ +bool qc_get_cache_properties(QC_CACHE_PROPERTIES* properties); + +/** + * Set the cache properties. + * + * @param properties[in] Cache properties. + */ +void qc_set_cache_properties(const QC_CACHE_PROPERTIES* properties); + /** * Get cache statistics for the calling thread. * diff --git a/server/core/query_classifier.cc b/server/core/query_classifier.cc index 79dca1226..3a6a6a4f5 100644 --- a/server/core/query_classifier.cc +++ b/server/core/query_classifier.cc @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include #include #include @@ -1192,6 +1194,27 @@ void qc_set_sql_mode(qc_sql_mode_t sql_mode) } } +bool qc_get_cache_properties(QC_CACHE_PROPERTIES* properties) +{ + properties->max_size = this_unit.cache_max_size(); + + return properties->max_size != 0; +} + +void qc_set_cache_properties(const QC_CACHE_PROPERTIES* properties) +{ + if (properties->max_size >= 0) + { + this_unit.set_cache_max_size(properties->max_size); + } + else + { + MXS_WARNING("Ignored attempt to set size of query classifier " + "cache to a negative value: %" PRIi64 ".", + properties->max_size); + } +} + bool qc_get_cache_stats(QC_CACHE_STATS* pStats) { QC_TRACE(); @@ -1231,3 +1254,19 @@ json_t* qc_get_cache_stats_as_json() return pStats; } + +std::unique_ptr qc_as_json(const char* zHost) +{ + json_t* pParams = json_object(); + json_object_set_new(pParams, "cache_size", json_integer(this_unit.cache_max_size())); + + json_t* pAttributes = json_object(); + json_object_set_new(pAttributes, CN_PARAMETERS, pParams); + + json_t* pSelf = json_object(); + json_object_set_new(pSelf, CN_ID, json_string("query_classifier")); + json_object_set_new(pSelf, CN_TYPE, json_string("query_classifier")); + json_object_set_new(pSelf, CN_ATTRIBUTES, pAttributes); + + return std::unique_ptr(mxs_json_resource(zHost, MXS_JSON_API_QC, pSelf)); +}