MXS-1992 Address review issues

This commit is contained in:
Johan Wikman
2018-08-07 09:52:23 +03:00
parent 1b521b16a9
commit fbb79adc52
2 changed files with 38 additions and 16 deletions

View File

@ -866,18 +866,20 @@ uint64_t qc_get_server_version();
/**
* Get the cache properties.
*
* @param properties[out] Cache properties.
*
* @return True, if caching is enabled, false otherwise.
* @param[out] properties Cache properties.
*/
bool qc_get_cache_properties(QC_CACHE_PROPERTIES* properties);
void qc_get_cache_properties(QC_CACHE_PROPERTIES* properties);
/**
* Set the cache properties.
*
* @param properties[in] Cache properties.
* @param properties Cache properties.
*
* @return True, if the properties could be set, false if at least
* one property is invalid or if the combination of property
* values is invalid.
*/
void qc_set_cache_properties(const QC_CACHE_PROPERTIES* properties);
bool qc_set_cache_properties(const QC_CACHE_PROPERTIES* properties);
/**
* Get cache statistics for the calling thread.

View File

@ -1195,25 +1195,28 @@ void qc_set_sql_mode(qc_sql_mode_t sql_mode)
}
}
bool qc_get_cache_properties(QC_CACHE_PROPERTIES* properties)
void 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)
bool qc_set_cache_properties(const QC_CACHE_PROPERTIES* properties)
{
bool rv = false;
if (properties->max_size >= 0)
{
this_unit.set_cache_max_size(properties->max_size);
rv = true;
}
else
{
MXS_WARNING("Ignored attempt to set size of query classifier "
MXS_ERROR("Ignoring attempt to set size of query classifier "
"cache to a negative value: %" PRIi64 ".",
properties->max_size);
}
return rv;
}
bool qc_get_cache_stats(QC_CACHE_STATS* pStats)
@ -1294,19 +1297,36 @@ json_t* get_params(json_t* pJson)
bool qc_alter_from_json(json_t* pJson)
{
bool rv = false;
json_t* pParams = get_params(pJson);
if (pParams)
{
rv = true;
QC_CACHE_PROPERTIES cache_properties;
qc_get_cache_properties(&cache_properties);
json_t* pValue;
if ((pValue = mxs_json_pointer(pParams, CN_CACHE_SIZE)))
{
QC_CACHE_PROPERTIES cache_properties = { json_integer_value(pValue) };
cache_properties.max_size = json_integer_value(pValue);
qc_set_cache_properties(&cache_properties);
if (cache_properties.max_size < 0)
{
// TODO: Log error here, but expose (config_runtime.cc) runtime_error() first.
rv = false;
}
}
return pParams != nullptr;
if (rv)
{
ss_debug(bool set =) qc_set_cache_properties(&cache_properties);
ss_dassert(set);
}
}
return rv;
}