From 882d3603552bd873ce538a7fa99c15f205fe6e14 Mon Sep 17 00:00:00 2001 From: Esa Korhonen Date: Thu, 31 Jan 2019 16:09:59 +0200 Subject: [PATCH] MXS-2304 Use get_size() instead of config_get_size() --- include/maxscale/config.hh | 30 +++++++++---------- server/core/config.cc | 8 ++--- server/modules/filter/cache/cachefilter.cc | 4 +-- server/modules/filter/maxrows/maxrows.cc | 3 +- .../modules/routing/avrorouter/avro_main.cc | 2 +- server/modules/routing/binlogrouter/blr.cc | 2 +- .../routing/readwritesplit/readwritesplit.hh | 2 +- 7 files changed, 24 insertions(+), 27 deletions(-) diff --git a/include/maxscale/config.hh b/include/maxscale/config.hh index 703b7de32..6c599a093 100644 --- a/include/maxscale/config.hh +++ b/include/maxscale/config.hh @@ -274,6 +274,20 @@ public: */ bool get_bool(const std::string& key) const; + /** + * @brief Get a size in bytes + * + * The value can have either one of the IEC binary prefixes or SI prefixes as + * a suffix. For example, the value 1Ki will be converted to 1024 bytes whereas + * 1k will be converted to 1000 bytes. Supported SI suffix values are k, m, g and t + * in both lower and upper case. Supported IEC binary suffix values are + * Ki, Mi, Gi and Ti both in upper and lower case. + * + * @param key Parameter name + * @return Number of bytes or 0 if no parameter was found + */ + uint64_t get_size(const std::string& key) const; + char* name; /**< The name of the parameter */ char* value; /**< The value of the parameter */ MXS_CONFIG_PARAMETER* next; /**< Next pointer in the linked list */ @@ -388,22 +402,6 @@ bool config_param_is_valid(const MXS_MODULE_PARAM* params, const char* value, const CONFIG_CONTEXT* context); -/** - * @brief Get a size in bytes - * - * The value can have either one of the IEC binary prefixes or SI prefixes as - * a suffix. For example, the value 1Ki will be converted to 1024 bytes whereas - * 1k will be converted to 1000 bytes. Supported SI suffix values are k, m, g and t - * in both lower and upper case. Supported IEC binary suffix values are - * Ki, Mi, Gi and Ti both in upper and lower case. - * - * @param params List of configuration parameters - * @param key Parameter name - * - * @return Number of bytes or 0 if no parameter was found - */ -uint64_t config_get_size(const MXS_CONFIG_PARAMETER* params, const char* key); - /** * @brief Get a string value * diff --git a/server/core/config.cc b/server/core/config.cc index 2b743bf45..5c5139330 100644 --- a/server/core/config.cc +++ b/server/core/config.cc @@ -1760,11 +1760,11 @@ bool MXS_CONFIG_PARAMETER::get_bool(const std::string& key) const return param_value.empty() ? false : config_truth_value(param_value.c_str()); } -uint64_t config_get_size(const MXS_CONFIG_PARAMETER* params, const char* key) +uint64_t MXS_CONFIG_PARAMETER::get_size(const std::string& key) const { - const char* value = config_get_value_string(params, key); - uint64_t intval; - MXB_AT_DEBUG(bool rval = ) get_suffixed_size(value, &intval); + string param_value = get_string(key); + uint64_t intval = 0; + MXB_AT_DEBUG(bool rval = ) get_suffixed_size(param_value.c_str(), &intval); mxb_assert(rval); return intval; } diff --git a/server/modules/filter/cache/cachefilter.cc b/server/modules/filter/cache/cachefilter.cc index 4f260954f..02d013fda 100644 --- a/server/modules/filter/cache/cachefilter.cc +++ b/server/modules/filter/cache/cachefilter.cc @@ -348,11 +348,11 @@ bool CacheFilter::process_params(MXS_CONFIG_PARAMETER* ppParams, CACHE_CONFIG& c config.debug = ppParams->get_integer("debug"); config.hard_ttl = ppParams->get_integer("hard_ttl"); config.soft_ttl = ppParams->get_integer("soft_ttl"); - config.max_size = config_get_size(ppParams, "max_size"); + config.max_size = ppParams->get_size("max_size"); config.max_count = ppParams->get_integer("max_count"); config.storage = MXS_STRDUP(config_get_string(ppParams, "storage")); config.max_resultset_rows = ppParams->get_integer("max_resultset_rows"); - config.max_resultset_size = config_get_size(ppParams, "max_resultset_size"); + config.max_resultset_size = ppParams->get_size("max_resultset_size"); config.thread_model = static_cast(ppParams->get_enum("cached_data", parameter_cached_data_values)); config.selects = static_cast(ppParams->get_enum("selects", diff --git a/server/modules/filter/maxrows/maxrows.cc b/server/modules/filter/maxrows/maxrows.cc index f891e18e1..94c88ba2a 100644 --- a/server/modules/filter/maxrows/maxrows.cc +++ b/server/modules/filter/maxrows/maxrows.cc @@ -234,8 +234,7 @@ static MXS_FILTER* createInstance(const char* name, MXS_CONFIG_PARAMETER* params { cinstance->name = name; cinstance->config.max_resultset_rows = params->get_integer("max_resultset_rows"); - cinstance->config.max_resultset_size = config_get_size(params, - "max_resultset_size"); + cinstance->config.max_resultset_size = params->get_size("max_resultset_size"); cinstance->config.m_return = static_cast(params->get_enum("max_resultset_return", return_option_values)); diff --git a/server/modules/routing/avrorouter/avro_main.cc b/server/modules/routing/avrorouter/avro_main.cc index c1a30ab7e..6c69632a2 100644 --- a/server/modules/routing/avrorouter/avro_main.cc +++ b/server/modules/routing/avrorouter/avro_main.cc @@ -60,7 +60,7 @@ static bool conversion_task_ctl(Avro* inst, bool start); */ MXS_ROUTER* createInstance(SERVICE* service, MXS_CONFIG_PARAMETER* params) { - uint64_t block_size = config_get_size(service->svc_config_param, "block_size"); + uint64_t block_size = service->svc_config_param->get_size("block_size"); mxs_avro_codec_type codec = static_cast( service->svc_config_param->get_enum("codec", codec_values)); std::string avrodir = config_get_string(service->svc_config_param, "avrodir"); diff --git a/server/modules/routing/binlogrouter/blr.cc b/server/modules/routing/binlogrouter/blr.cc index 9c11997e5..d25a51ed3 100644 --- a/server/modules/routing/binlogrouter/blr.cc +++ b/server/modules/routing/binlogrouter/blr.cc @@ -343,7 +343,7 @@ static MXS_ROUTER* createInstance(SERVICE* service, MXS_CONFIG_PARAMETER* params inst->short_burst = params->get_integer("shortburst"); inst->long_burst = params->get_integer("longburst"); - inst->burst_size = config_get_size(params, "burstsize"); + inst->burst_size = params->get_size("burstsize"); inst->binlogdir = config_copy_string(params, "binlogdir"); inst->heartbeat = params->get_integer("heartbeat"); inst->retry_interval = params->get_integer("connect_retry"); diff --git a/server/modules/routing/readwritesplit/readwritesplit.hh b/server/modules/routing/readwritesplit/readwritesplit.hh index e8a3b8843..cfa4ec1b1 100644 --- a/server/modules/routing/readwritesplit/readwritesplit.hh +++ b/server/modules/routing/readwritesplit/readwritesplit.hh @@ -157,7 +157,7 @@ struct Config , delayed_retry(params->get_bool("delayed_retry")) , delayed_retry_timeout(params->get_integer("delayed_retry_timeout")) , transaction_replay(params->get_bool("transaction_replay")) - , trx_max_size(config_get_size(params, "transaction_replay_max_size")) + , trx_max_size(params->get_size("transaction_replay_max_size")) , optimistic_trx(params->get_bool("optimistic_trx")) { if (causal_reads)