MXS-2304 Use get_integer() instead of config_get_integer()

This commit is contained in:
Esa Korhonen 2019-01-30 18:14:18 +02:00
parent 63b5eab89e
commit c8a84cebd0
20 changed files with 70 additions and 81 deletions

View File

@ -163,7 +163,7 @@ RRRouter::RRRouter(SERVICE* service)
RR_DEBUG("Creating instance.");
/* Read options specific to round robin router. */
MXS_CONFIG_PARAMETER* params = service->svc_config_param;
m_max_backends = config_get_integer(params, MAX_BACKENDS);
m_max_backends = params->get_integer(MAX_BACKENDS);
m_write_server = config_get_server(params, WRITE_BACKEND);
m_print_on_routing = config_get_bool(params, PRINT_ON_ROUTING);
m_example_enum = config_get_enum(params, DUMMY, enum_example);

View File

@ -239,6 +239,13 @@ public:
*/
const char* get_c_str(const std::string& key) const;
/**
* Get an integer value. Should be used for both MXS_MODULE_PARAM_INT and MXS_MODULE_PARAM_COUNT
* parameter types.
*
* @param key Parameter name
* @return Parameter parsed to integer. 0 if key was not found.
*/
int64_t get_integer(const std::string& key) const;
int64_t get_enum(const std::string& key, const MXS_ENUM_VALUE* enum_mapping) const;
@ -371,18 +378,6 @@ bool config_param_is_valid(const MXS_MODULE_PARAM* params,
*/
bool config_get_bool(const MXS_CONFIG_PARAMETER* params, const char* key);
/**
* @brief Get an integer value
*
* This is used for both MXS_MODULE_PARAM_INT and MXS_MODULE_PARAM_COUNT.
*
* @param params List of configuration parameters
* @param key Parameter name
*
* @return The integer value of the parameter or 0 if no parameter was found
*/
int config_get_integer(const MXS_CONFIG_PARAMETER* params, const char* key);
/**
* @brief Get a size in bytes
*

View File

@ -1728,12 +1728,6 @@ bool config_get_bool(const MXS_CONFIG_PARAMETER* params, const char* key)
return *value ? config_truth_value(value) : false;
}
int config_get_integer(const MXS_CONFIG_PARAMETER* params, const char* key)
{
const char* value = config_get_value_string(params, key);
return *value ? strtol(value, NULL, 10) : 0;
}
uint64_t config_get_size(const MXS_CONFIG_PARAMETER* params, const char* key)
{
const char* value = config_get_value_string(params, key);
@ -1912,7 +1906,8 @@ const char* MXS_CONFIG_PARAMETER::get_c_str(const std::string& key) const
int64_t MXS_CONFIG_PARAMETER::get_integer(const std::string& key) const
{
return config_get_integer(this, key.c_str());
string value = get_string(key);
return value.empty() ? 0 : strtoll(value.c_str(), NULL, 10);
}
int64_t MXS_CONFIG_PARAMETER::get_enum(const std::string& key, const MXS_ENUM_VALUE* enum_mapping) const
@ -2754,7 +2749,7 @@ bool config_create_ssl(const char* name,
ssl->ssl_method_type = (ssl_method_type_t)ssl_version;
ssl->ssl_init_done = false;
ssl->ssl_cert_verify_depth = config_get_integer(params, CN_SSL_CERT_VERIFY_DEPTH);
ssl->ssl_cert_verify_depth = params->get_integer(CN_SSL_CERT_VERIFY_DEPTH);
ssl->ssl_verify_peer_certificate = config_get_bool(params, CN_SSL_VERIFY_PEER_CERTIFICATE);
listener_set_certificates(ssl, ssl_cert, ssl_key, ssl_ca_cert);

View File

@ -187,16 +187,16 @@ Monitor::Monitor(const string& name, const string& module)
bool Monitor::configure_base(const MXS_CONFIG_PARAMETER* params)
{
m_settings.conn_settings.read_timeout = config_get_integer(params, CN_BACKEND_READ_TIMEOUT);
m_settings.conn_settings.write_timeout = config_get_integer(params, CN_BACKEND_WRITE_TIMEOUT);
m_settings.conn_settings.connect_timeout = config_get_integer(params, CN_BACKEND_CONNECT_TIMEOUT);
m_settings.conn_settings.connect_attempts = config_get_integer(params, CN_BACKEND_CONNECT_ATTEMPTS);
m_settings.interval = config_get_integer(params, CN_MONITOR_INTERVAL);
m_settings.journal_max_age = config_get_integer(params, CN_JOURNAL_MAX_AGE);
m_settings.script_timeout = config_get_integer(params, CN_SCRIPT_TIMEOUT);
m_settings.conn_settings.read_timeout = params->get_integer(CN_BACKEND_READ_TIMEOUT);
m_settings.conn_settings.write_timeout = params->get_integer(CN_BACKEND_WRITE_TIMEOUT);
m_settings.conn_settings.connect_timeout = params->get_integer(CN_BACKEND_CONNECT_TIMEOUT);
m_settings.conn_settings.connect_attempts = params->get_integer(CN_BACKEND_CONNECT_ATTEMPTS);
m_settings.interval = params->get_integer(CN_MONITOR_INTERVAL);
m_settings.journal_max_age = params->get_integer(CN_JOURNAL_MAX_AGE);
m_settings.script_timeout = params->get_integer(CN_SCRIPT_TIMEOUT);
m_settings.script = config_get_string(params, CN_SCRIPT);
m_settings.events = config_get_enum(params, CN_EVENTS, mxs_monitor_event_enum_values);
m_settings.disk_space_check_interval = config_get_integer(params, CN_DISK_SPACE_CHECK_INTERVAL);
m_settings.disk_space_check_interval = params->get_integer(CN_DISK_SPACE_CHECK_INTERVAL);
m_settings.conn_settings.username = config_get_string(params, CN_USER);
m_settings.conn_settings.password = config_get_string(params, CN_PASSWORD);

View File

@ -247,10 +247,10 @@ Server* Server::server_alloc(const char* name, MXS_CONFIG_PARAMETER* params)
sizeof(server->address));
}
server->port = config_get_integer(params, CN_PORT);
server->extra_port = config_get_integer(params, CN_EXTRA_PORT);
server->m_settings.persistpoolmax = config_get_integer(params, CN_PERSISTPOOLMAX);
server->m_settings.persistmaxtime = config_get_integer(params, CN_PERSISTMAXTIME);
server->port = params->get_integer(CN_PORT);
server->extra_port = params->get_integer(CN_EXTRA_PORT);
server->m_settings.persistpoolmax = params->get_integer(CN_PERSISTPOOLMAX);
server->m_settings.persistmaxtime = params->get_integer(CN_PERSISTMAXTIME);
server->proxy_protocol = config_get_bool(params, CN_PROXY_PROTOCOL);
server->is_active = true;
server->m_auth_instance = auth_instance;

View File

@ -186,20 +186,20 @@ Service::Service(const std::string& service_name,
snprintf(weightby, sizeof(weightby), "%s", m_weightby.c_str());
snprintf(version_string, sizeof(version_string), "%s", m_version_string.c_str());
max_retry_interval = config_get_integer(params, CN_MAX_RETRY_INTERVAL);
max_retry_interval = params->get_integer(CN_MAX_RETRY_INTERVAL);
users_from_all = config_get_bool(params, CN_AUTH_ALL_SERVERS);
localhost_match_wildcard_host = config_get_bool(params, CN_LOCALHOST_MATCH_WILDCARD_HOST);
retry_start = config_get_bool(params, CN_RETRY_ON_FAILURE);
enable_root = config_get_bool(params, CN_ENABLE_ROOT_USER);
conn_idle_timeout = config_get_integer(params, CN_CONNECTION_TIMEOUT);
max_connections = config_get_integer(params, CN_MAX_CONNECTIONS);
conn_idle_timeout = params->get_integer(CN_CONNECTION_TIMEOUT);
max_connections = params->get_integer(CN_MAX_CONNECTIONS);
log_auth_warnings = config_get_bool(params, CN_LOG_AUTH_WARNINGS);
strip_db_esc = config_get_bool(params, CN_STRIP_DB_ESC);
session_track_trx_state = config_get_bool(params, CN_SESSION_TRACK_TRX_STATE);
if (config_get_param(params, CN_RETAIN_LAST_STATEMENTS))
{
retain_last_statements = config_get_integer(params, CN_RETAIN_LAST_STATEMENTS);
retain_last_statements = params->get_integer(CN_RETAIN_LAST_STATEMENTS);
}
else
{

View File

@ -155,8 +155,8 @@ int test_add_parameter()
config_add_defaults(&ctx, params);
/** Test default values */
TEST(config_get_integer(ctx.parameters, "p1") == -123);
TEST(config_get_integer(ctx.parameters, "p2") == 123);
TEST(ctx.parameters->get_integer("p1") == -123);
TEST(ctx.parameters->get_integer("p2") == 123);
TEST(config_get_bool(ctx.parameters, "p3") == true);
TEST(strcmp(config_get_string(ctx.parameters, "p4"), "default") == 0);
TEST(config_get_enum(ctx.parameters, "p5", enum_values) == 1);
@ -177,8 +177,8 @@ int test_add_parameter()
config_add_defaults(&ctx, params);
TEST(config_get_integer(ctx.parameters, "p1") == -321);
TEST(config_get_integer(ctx.parameters, "p2") == 321);
TEST(ctx.parameters->get_integer("p1") == -321);
TEST(ctx.parameters->get_integer("p2") == 321);
TEST(config_get_param(ctx.parameters, "p3") && config_get_bool(ctx.parameters, "p3") == false);
TEST(strcmp(config_get_string(ctx.parameters, "p4"), "strange") == 0);
int val = config_get_enum(ctx.parameters, "p5", enum_values);

View File

@ -345,13 +345,13 @@ bool CacheFilter::process_params(MXS_CONFIG_PARAMETER* ppParams, CACHE_CONFIG& c
{
bool error = false;
config.debug = config_get_integer(ppParams, "debug");
config.hard_ttl = config_get_integer(ppParams, "hard_ttl");
config.soft_ttl = config_get_integer(ppParams, "soft_ttl");
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_count = config_get_integer(ppParams, "max_count");
config.max_count = ppParams->get_integer("max_count");
config.storage = MXS_STRDUP(config_get_string(ppParams, "storage"));
config.max_resultset_rows = config_get_integer(ppParams, "max_resultset_rows");
config.max_resultset_rows = ppParams->get_integer("max_resultset_rows");
config.max_resultset_size = config_get_size(ppParams, "max_resultset_size");
config.thread_model = static_cast<cache_thread_model_t>(config_get_enum(ppParams,
"cached_data",

View File

@ -89,8 +89,8 @@ public:
CCRFilter* new_instance = new(std::nothrow) CCRFilter;
if (new_instance)
{
new_instance->m_count = config_get_integer(params, "count");
new_instance->m_time = config_get_integer(params, "time");
new_instance->m_count = params->get_integer("count");
new_instance->m_time = params->get_integer("time");
new_instance->m_match = config_get_string(params, PARAM_MATCH);
new_instance->m_nomatch = config_get_string(params, PARAM_IGNORE);

View File

@ -233,15 +233,14 @@ static MXS_FILTER* createInstance(const char* name, MXS_CONFIG_PARAMETER* params
if (cinstance)
{
cinstance->name = name;
cinstance->config.max_resultset_rows = config_get_integer(params,
"max_resultset_rows");
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.m_return =
static_cast<maxrows_return_mode>(config_get_enum(params,
"max_resultset_return",
return_option_values));
cinstance->config.debug = config_get_integer(params, "debug");
cinstance->config.debug = params->get_integer("debug");
}
return (MXS_FILTER*)cinstance;

View File

@ -583,7 +583,7 @@ static MXS_FILTER* createInstance(const char* name, MXS_CONFIG_PARAMETER* params
my_instance->conn_stat = AMQP_STATUS_OK;
my_instance->rconn_intv = 1;
my_instance->port = config_get_integer(params, "port");
my_instance->port = params->get_integer("port");
my_instance->trgtype =
static_cast<log_trigger_t>(config_get_enum(params, "logging_trigger", trigger_values));
my_instance->log_all = config_get_bool(params, "logging_log_all");

View File

@ -63,10 +63,10 @@ ThrottleFilter::ThrottleFilter(const ThrottleConfig& config) : m_config(config)
ThrottleFilter* ThrottleFilter::create(const char* zName, MXS_CONFIG_PARAMETER* pParams)
{
int max_qps = config_get_integer(pParams, MAX_QPS_CFG);
int sample_msecs = config_get_integer(pParams, SAMPLING_DURATION_CFG);
int throttle_msecs = config_get_integer(pParams, THROTTLE_DURATION_CFG);
int cont_msecs = config_get_integer(pParams, CONTINUOUS_DURATION_CFG);
int max_qps = pParams->get_integer(MAX_QPS_CFG);
int sample_msecs = pParams->get_integer(SAMPLING_DURATION_CFG);
int throttle_msecs = pParams->get_integer(THROTTLE_DURATION_CFG);
int cont_msecs = pParams->get_integer(CONTINUOUS_DURATION_CFG);
bool config_ok = true;
if (max_qps < 2)

View File

@ -212,7 +212,7 @@ static MXS_FILTER* createInstance(const char* name, MXS_CONFIG_PARAMETER* params
if (my_instance)
{
my_instance->sessions = 0;
my_instance->topN = config_get_integer(params, "count");
my_instance->topN = params->get_integer("count");
my_instance->match = config_copy_string(params, "match");
my_instance->exclude = config_copy_string(params, "exclude");
my_instance->source = config_copy_string(params, "source");

View File

@ -47,8 +47,8 @@ bool ClustrixMonitor::configure(const MXS_CONFIG_PARAMETER* pParams)
m_health_urls.clear();
m_nodes.clear();
m_config.set_cluster_monitor_interval(config_get_integer(pParams, CLUSTER_MONITOR_INTERVAL_NAME));
m_config.set_health_check_threshold(config_get_integer(pParams, HEALTH_CHECK_THRESHOLD_NAME));
m_config.set_cluster_monitor_interval(pParams->get_integer(CLUSTER_MONITOR_INTERVAL_NAME));
m_config.set_health_check_threshold(pParams->get_integer(HEALTH_CHECK_THRESHOLD_NAME));
check_hub_and_refresh_nodes();

View File

@ -195,14 +195,14 @@ bool MariaDBMonitor::configure(const MXS_CONFIG_PARAMETER* params)
m_ignore_external_masters = config_get_bool(params, "ignore_external_masters");
m_detect_standalone_master = config_get_bool(params, CN_DETECT_STANDALONE_MASTER);
m_assume_unique_hostnames = config_get_bool(params, CN_ASSUME_UNIQUE_HOSTNAMES);
m_failcount = config_get_integer(params, CN_FAILCOUNT);
m_failover_timeout = config_get_integer(params, CN_FAILOVER_TIMEOUT);
m_switchover_timeout = config_get_integer(params, CN_SWITCHOVER_TIMEOUT);
m_failcount = params->get_integer(CN_FAILCOUNT);
m_failover_timeout = params->get_integer(CN_FAILOVER_TIMEOUT);
m_switchover_timeout = params->get_integer(CN_SWITCHOVER_TIMEOUT);
m_auto_failover = config_get_bool(params, CN_AUTO_FAILOVER);
m_auto_rejoin = config_get_bool(params, CN_AUTO_REJOIN);
m_enforce_read_only_slaves = config_get_bool(params, CN_ENFORCE_READONLY);
m_verify_master_failure = config_get_bool(params, CN_VERIFY_MASTER_FAILURE);
m_master_failure_timeout = config_get_integer(params, CN_MASTER_FAILURE_TIMEOUT);
m_master_failure_timeout = params->get_integer(CN_MASTER_FAILURE_TIMEOUT);
m_promote_sql_file = config_get_string(params, CN_PROMOTION_SQL_FILE);
m_demote_sql_file = config_get_string(params, CN_DEMOTION_SQL_FILE);
m_switchover_on_low_disk_space = config_get_bool(params, CN_SWITCHOVER_ON_LOW_DISK_SPACE);

View File

@ -135,9 +135,9 @@ Avro::Avro(SERVICE* service, MXS_CONFIG_PARAMETER* params, SERVICE* source, SRow
, current_pos(4)
, binlog_fd(-1)
, trx_count(0)
, trx_target(config_get_integer(params, "group_trx"))
, trx_target(params->get_integer("group_trx"))
, row_count(0)
, row_target(config_get_integer(params, "group_rows"))
, row_target(params->get_integer("group_rows"))
, task_handle(0)
, handler(service, handler, config_get_compiled_regex(params, "match", 0, NULL),
config_get_compiled_regex(params, "exclude", 0, NULL))
@ -152,7 +152,7 @@ Avro::Avro(SERVICE* service, MXS_CONFIG_PARAMETER* params, SERVICE* source, SRow
sizeof(filename),
BINLOG_NAMEFMT,
filestem.c_str(),
config_get_integer(params, "start_index"));
static_cast<int>(params->get_integer("start_index")));
binlog_name = filename;
MXS_NOTICE("Reading MySQL binlog files from %s", binlogdir.c_str());

View File

@ -339,29 +339,29 @@ static MXS_ROUTER* createInstance(SERVICE* service, MXS_CONFIG_PARAMETER* params
strcpy(inst->binlog_name, "");
strcpy(inst->prevbinlog, "");
inst->initbinlog = config_get_integer(params, "file");
inst->initbinlog = params->get_integer("file");
inst->short_burst = config_get_integer(params, "shortburst");
inst->long_burst = config_get_integer(params, "longburst");
inst->short_burst = params->get_integer("shortburst");
inst->long_burst = params->get_integer("longburst");
inst->burst_size = config_get_size(params, "burstsize");
inst->binlogdir = config_copy_string(params, "binlogdir");
inst->heartbeat = config_get_integer(params, "heartbeat");
inst->retry_interval = config_get_integer(params, "connect_retry");
inst->retry_limit = config_get_integer(params, "master_retry_count");
inst->ssl_cert_verification_depth = config_get_integer(params, "ssl_cert_verification_depth");
inst->heartbeat = params->get_integer("heartbeat");
inst->retry_interval = params->get_integer("connect_retry");
inst->retry_limit = params->get_integer("master_retry_count");
inst->ssl_cert_verification_depth = params->get_integer("ssl_cert_verification_depth");
inst->mariadb10_compat = config_get_bool(params, "mariadb10-compatibility");
inst->maxwell_compat = config_get_bool(params, "maxwell-compatibility");
inst->trx_safe = config_get_bool(params, "transaction_safety");
inst->fileroot = config_copy_string(params, "filestem");
/* Server id */
inst->serverid = config_get_integer(params, "server_id");
inst->serverid = params->get_integer("server_id");
/* Identity options */
inst->set_master_version = config_copy_string(params, "master_version");
inst->set_master_hostname = config_copy_string(params, "master_hostname");
inst->set_slave_hostname = config_copy_string(params, "slave_hostname");
inst->masterid = config_get_integer(params, "master_id");
inst->masterid = params->get_integer("master_id");
inst->set_master_server_id = inst->masterid != 0;
inst->master_uuid = config_copy_string(params, "master_uuid");
inst->set_master_uuid = inst->master_uuid != NULL;

View File

@ -64,7 +64,7 @@ HintRouter* HintRouter::create(SERVICE* pService, MXS_CONFIG_PARAMETER* params)
DEFAULT_ACTION,
default_action_values);
string default_server(config_get_string(params, DEFAULT_SERVER));
int max_slaves = config_get_integer(params, MAX_SLAVES);
int max_slaves = params->get_integer(MAX_SLAVES);
return new HintRouter(pService, default_action, default_server, max_slaves);
}

View File

@ -143,21 +143,21 @@ struct Config
, master_failure_mode(
(enum failure_mode)config_get_enum(
params, "master_failure_mode", master_failure_mode_values))
, max_sescmd_history(config_get_integer(params, "max_sescmd_history"))
, max_sescmd_history(params->get_integer("max_sescmd_history"))
, disable_sescmd_history(config_get_bool(params, "disable_sescmd_history"))
, master_accept_reads(config_get_bool(params, "master_accept_reads"))
, strict_multi_stmt(config_get_bool(params, "strict_multi_stmt"))
, strict_sp_calls(config_get_bool(params, "strict_sp_calls"))
, retry_failed_reads(config_get_bool(params, "retry_failed_reads"))
, connection_keepalive(config_get_integer(params, "connection_keepalive"))
, max_slave_replication_lag(config_get_integer(params, "max_slave_replication_lag"))
, connection_keepalive(params->get_integer("connection_keepalive"))
, max_slave_replication_lag(params->get_integer("max_slave_replication_lag"))
, rw_max_slave_conn_percent(0)
, max_slave_connections(0)
, causal_reads(config_get_bool(params, "causal_reads"))
, causal_reads_timeout(config_get_string(params, "causal_reads_timeout"))
, master_reconnection(config_get_bool(params, "master_reconnection"))
, delayed_retry(config_get_bool(params, "delayed_retry"))
, delayed_retry_timeout(config_get_integer(params, "delayed_retry_timeout"))
, delayed_retry_timeout(params->get_integer("delayed_retry_timeout"))
, transaction_replay(config_get_bool(params, "transaction_replay"))
, trx_max_size(config_get_size(params, "transaction_replay_max_size"))
, optimistic_trx(config_get_bool(params, "optimistic_trx"))

View File

@ -19,7 +19,7 @@ namespace schemarouter
{
Config::Config(MXS_CONFIG_PARAMETER* conf)
: refresh_min_interval(config_get_integer(conf, "refresh_interval"))
: refresh_min_interval(conf->get_integer("refresh_interval"))
, refresh_databases(config_get_bool(conf, "refresh_databases"))
, debug(config_get_bool(conf, "debug"))
, ignore_regex(config_get_compiled_regex(conf, "ignore_databases_regex", 0, NULL))