MXS-2304 Use get_bool() instead of config_get_bool()

This commit is contained in:
Esa Korhonen 2019-01-31 15:49:05 +02:00
parent 7cb969b0d9
commit b357717149
19 changed files with 76 additions and 78 deletions

View File

@ -165,7 +165,7 @@ RRRouter::RRRouter(SERVICE* service)
MXS_CONFIG_PARAMETER* params = service->svc_config_param;
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_print_on_routing = params->get_bool(PRINT_ON_ROUTING);
m_example_enum = params->get_enum(DUMMY, enum_example);
RR_DEBUG("Settings read:");

View File

@ -262,6 +262,18 @@ public:
*/
int64_t get_enum(const std::string& key, const MXS_ENUM_VALUE* enum_mapping) const;
/**
* @brief Get a boolean value
*
* The existence of the parameter should be checked with config_get_param() before
* calling this function to determine whether the return value represents an existing
* value or a missing value.
*
* @param key Parameter name
* @return The value as a boolean or false if none was found
*/
bool get_bool(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 */
@ -376,20 +388,6 @@ bool config_param_is_valid(const MXS_MODULE_PARAM* params,
const char* value,
const CONFIG_CONTEXT* context);
/**
* @brief Get a boolean value
*
* The existence of the parameter should be checked with config_get_param() before
* calling this function to determine whether the return value represents an existing
* value or a missing value.
*
* @param params List of configuration parameters
* @param key Parameter name
*
* @return The value as a boolean or false if none was found
*/
bool config_get_bool(const MXS_CONFIG_PARAMETER* params, const char* key);
/**
* @brief Get a size in bytes
*

View File

@ -1754,10 +1754,10 @@ MXS_CONFIG_PARAMETER* config_get_param(MXS_CONFIG_PARAMETER* params, const char*
return NULL;
}
bool config_get_bool(const MXS_CONFIG_PARAMETER* params, const char* key)
bool MXS_CONFIG_PARAMETER::get_bool(const std::string& key) const
{
const char* value = config_get_value_string(params, key);
return *value ? config_truth_value(value) : false;
string param_value = get_string(key);
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)
@ -2757,7 +2757,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 = params->get_integer(CN_SSL_CERT_VERIFY_DEPTH);
ssl->ssl_verify_peer_certificate = config_get_bool(params, CN_SSL_VERIFY_PEER_CERTIFICATE);
ssl->ssl_verify_peer_certificate = params->get_bool(CN_SSL_VERIFY_PEER_CERTIFICATE);
listener_set_certificates(ssl, ssl_cert, ssl_key, ssl_ca_cert);

View File

@ -251,7 +251,7 @@ Server* Server::server_alloc(const char* name, MXS_CONFIG_PARAMETER* params)
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->proxy_protocol = params->get_bool(CN_PROXY_PROTOCOL);
server->is_active = true;
server->m_auth_instance = auth_instance;
server->server_ssl = ssl;

View File

@ -187,15 +187,15 @@ Service::Service(const std::string& service_name,
snprintf(version_string, sizeof(version_string), "%s", m_version_string.c_str());
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);
users_from_all = params->get_bool(CN_AUTH_ALL_SERVERS);
localhost_match_wildcard_host = params->get_bool(CN_LOCALHOST_MATCH_WILDCARD_HOST);
retry_start = params->get_bool(CN_RETRY_ON_FAILURE);
enable_root = params->get_bool(CN_ENABLE_ROOT_USER);
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);
log_auth_warnings = params->get_bool(CN_LOG_AUTH_WARNINGS);
strip_db_esc = params->get_bool(CN_STRIP_DB_ESC);
session_track_trx_state = params->get_bool(CN_SESSION_TRACK_TRX_STATE);
if (config_get_param(params, CN_RETAIN_LAST_STATEMENTS))
{

View File

@ -157,7 +157,7 @@ int test_add_parameter()
/** Test default values */
TEST(ctx.parameters->get_integer("p1") == -123);
TEST(ctx.parameters->get_integer("p2") == 123);
TEST(config_get_bool(ctx.parameters, "p3") == true);
TEST(ctx.parameters->get_bool("p3") == true);
TEST(strcmp(config_get_string(ctx.parameters, "p4"), "default") == 0);
TEST(ctx.parameters->get_enum("p5", enum_values) == 1);
TEST(strcmp(config_get_string(ctx.parameters, "p6"), "/tmp") == 0);
@ -179,7 +179,7 @@ int test_add_parameter()
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(config_get_param(ctx.parameters, "p3") && ctx.parameters->get_bool("p3") == false);
TEST(strcmp(config_get_string(ctx.parameters, "p4"), "strange") == 0);
int val = ctx.parameters->get_enum("p5", enum_values);
TEST(val == 5);

View File

@ -359,7 +359,7 @@ bool CacheFilter::process_params(MXS_CONFIG_PARAMETER* ppParams, CACHE_CONFIG& c
parameter_selects_values));
config.cache_in_trxs = static_cast<cache_in_trxs_t>(ppParams->get_enum("cache_in_transactions",
parameter_cache_in_trxs_values));
config.enabled = config_get_bool(ppParams, "enabled");
config.enabled = ppParams->get_bool("enabled");
if (!config.storage)
{

View File

@ -1202,12 +1202,12 @@ Dbfw::Dbfw(MXS_CONFIG_PARAMETER* params)
, m_filename(config_get_string(params, "rules"))
, m_version(atomic_add(&global_version, 1))
{
if (config_get_bool(params, "log_match"))
if (params->get_bool("log_match"))
{
m_log_match |= FW_LOG_MATCH;
}
if (config_get_bool(params, "log_no_match"))
if (params->get_bool("log_no_match"))
{
m_log_match |= FW_LOG_NO_MATCH;
}

View File

@ -113,5 +113,5 @@ MaskingFilterConfig::warn_type_mismatch_t MaskingFilterConfig::get_warn_type_mis
// static
bool MaskingFilterConfig::get_prevent_function_usage(const MXS_CONFIG_PARAMETER* pParams)
{
return config_get_bool(pParams, prevent_function_usage_name);
return pParams->get_bool(prevent_function_usage_name);
}

View File

@ -586,8 +586,8 @@ static MXS_FILTER* createInstance(const char* name, MXS_CONFIG_PARAMETER* params
my_instance->port = params->get_integer("port");
my_instance->trgtype =
static_cast<log_trigger_t>(params->get_enum("logging_trigger", trigger_values));
my_instance->log_all = config_get_bool(params, "logging_log_all");
my_instance->strict_logging = config_get_bool(params, "logging_strict");
my_instance->log_all = params->get_bool("logging_log_all");
my_instance->strict_logging = params->get_bool("logging_strict");
my_instance->hostname = MXS_STRDUP_A(config_get_string(params, "hostname"));
my_instance->username = MXS_STRDUP_A(config_get_string(params, "username"));
my_instance->password = MXS_STRDUP_A(config_get_string(params, "password"));

View File

@ -230,8 +230,8 @@ QlaInstance::QlaInstance(const char* name, MXS_CONFIG_PARAMETER* params)
, log_file_data_flags(params->get_enum(PARAM_LOG_DATA, log_data_values))
, filebase(config_get_string(params, PARAM_FILEBASE))
, unified_fp(NULL)
, flush_writes(config_get_bool(params, PARAM_FLUSH))
, append(config_get_bool(params, PARAM_APPEND))
, flush_writes(params->get_bool(PARAM_FLUSH))
, append(params->get_bool(PARAM_APPEND))
, query_newline(config_get_string(params, PARAM_NEWLINE))
, separator(config_get_string(params, PARAM_SEPARATOR))
, write_warning_given(false)

View File

@ -210,7 +210,7 @@ static MXS_FILTER* createInstance(const char* name, MXS_CONFIG_PARAMETER* params
my_instance->replace = MXS_STRDUP_A(config_get_string(params, "replace"));
my_instance->source = config_copy_string(params, "source");
my_instance->user = config_copy_string(params, "user");
my_instance->log_trace = config_get_bool(params, "log_trace");
my_instance->log_trace = params->get_bool("log_trace");
const char* logfile = config_get_string(params, "log_file");

View File

@ -104,12 +104,12 @@ json_t* GaleraMonitor::diagnostics_json() const
bool GaleraMonitor::configure(const MXS_CONFIG_PARAMETER* params)
{
m_disableMasterFailback = config_get_bool(params, "disable_master_failback");
m_availableWhenDonor = config_get_bool(params, "available_when_donor");
m_disableMasterRoleSetting = config_get_bool(params, "disable_master_role_setting");
m_root_node_as_master = config_get_bool(params, "root_node_as_master");
m_use_priority = config_get_bool(params, "use_priority");
m_set_donor_nodes = config_get_bool(params, "set_donor_nodes");
m_disableMasterFailback = params->get_bool("disable_master_failback");
m_availableWhenDonor = params->get_bool("available_when_donor");
m_disableMasterRoleSetting = params->get_bool("disable_master_role_setting");
m_root_node_as_master = params->get_bool("root_node_as_master");
m_use_priority = params->get_bool("use_priority");
m_set_donor_nodes = params->get_bool("set_donor_nodes");
m_log_no_members = true;
/* Reset all data in the hashtable */

View File

@ -64,7 +64,7 @@ bool MariaDBMonitor::manual_switchover(SERVER* promotion_server, SERVER* demotio
{
string msg = string_printf(SWITCHOVER_FAIL,
op->demotion.target->name(), op->promotion.target->name());
bool failover_setting = config_get_bool(m_monitor->parameters, CN_AUTO_FAILOVER);
bool failover_setting = parameters->get_bool(CN_AUTO_FAILOVER);
if (failover_setting)
{
disable_setting(CN_AUTO_FAILOVER);

View File

@ -190,24 +190,24 @@ bool MariaDBMonitor::configure(const MXS_CONFIG_PARAMETER* params)
* added, removed and modified. */
reset_server_info();
m_detect_stale_master = config_get_bool(params, "detect_stale_master");
m_detect_stale_slave = config_get_bool(params, "detect_stale_slave");
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_detect_stale_master = params->get_bool("detect_stale_master");
m_detect_stale_slave = params->get_bool("detect_stale_slave");
m_ignore_external_masters = params->get_bool("ignore_external_masters");
m_detect_standalone_master = params->get_bool(CN_DETECT_STANDALONE_MASTER);
m_assume_unique_hostnames = params->get_bool(CN_ASSUME_UNIQUE_HOSTNAMES);
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_auto_failover = params->get_bool(CN_AUTO_FAILOVER);
m_auto_rejoin = params->get_bool(CN_AUTO_REJOIN);
m_enforce_read_only_slaves = params->get_bool(CN_ENFORCE_READONLY);
m_verify_master_failure = params->get_bool(CN_VERIFY_MASTER_FAILURE);
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);
m_maintenance_on_low_disk_space = config_get_bool(params, CN_MAINTENANCE_ON_LOW_DISK_SPACE);
m_handle_event_scheduler = config_get_bool(params, CN_HANDLE_EVENTS);
m_switchover_on_low_disk_space = params->get_bool(CN_SWITCHOVER_ON_LOW_DISK_SPACE);
m_maintenance_on_low_disk_space = params->get_bool(CN_MAINTENANCE_ON_LOW_DISK_SPACE);
m_handle_event_scheduler = params->get_bool(CN_HANDLE_EVENTS);
m_excluded_servers.clear();
bool settings_ok = true;

View File

@ -64,7 +64,7 @@ json_t* MMMonitor::diagnostics_json() const
bool MMMonitor::configure(const MXS_CONFIG_PARAMETER* params)
{
m_detectStaleMaster = config_get_bool(params, "detect_stale_master");
m_detectStaleMaster = params->get_bool("detect_stale_master");
return true;
}

View File

@ -349,9 +349,9 @@ static MXS_ROUTER* createInstance(SERVICE* service, MXS_CONFIG_PARAMETER* params
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->mariadb10_compat = params->get_bool("mariadb10-compatibility");
inst->maxwell_compat = params->get_bool("maxwell-compatibility");
inst->trx_safe = params->get_bool("transaction_safety");
inst->fileroot = config_copy_string(params, "filestem");
/* Server id */
@ -367,20 +367,20 @@ static MXS_ROUTER* createInstance(SERVICE* service, MXS_CONFIG_PARAMETER* params
inst->set_master_uuid = inst->master_uuid != NULL;
/* Slave Heartbeat */
inst->send_slave_heartbeat = config_get_bool(params, "send_slave_heartbeat");
inst->send_slave_heartbeat = params->get_bool("send_slave_heartbeat");
/* Semi-Sync support */
inst->request_semi_sync = config_get_bool(params, "semisync");
inst->request_semi_sync = params->get_bool("semisync");
inst->master_semi_sync = 0;
/* Enable MariaDB GTID tracking for slaves if MariaDB 10 compat is set */
inst->mariadb10_gtid = inst->mariadb10_compat;
/* Enable MariaDB GTID registration to master */
inst->mariadb10_master_gtid = config_get_bool(params, "mariadb10_master_gtid");
inst->mariadb10_master_gtid = params->get_bool("mariadb10_master_gtid");
/* Binlog encryption */
inst->encryption.enabled = config_get_bool(params, "encrypt_binlog");
inst->encryption.enabled = params->get_bool("encrypt_binlog");
inst->encryption.encryption_algorithm = params->get_enum("encryption_algorithm", enc_algo_values);
inst->encryption.key_management_filename = config_copy_string(params,
"encryption_key_file");

View File

@ -141,24 +141,24 @@ struct Config
, master_failure_mode(
(enum failure_mode)params->get_enum("master_failure_mode", master_failure_mode_values))
, max_sescmd_history(params->get_integer("max_sescmd_history"))
, prune_sescmd_history(config_get_bool(params, "prune_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"))
, prune_sescmd_history(params->get_bool("prune_sescmd_history"))
, disable_sescmd_history(params->get_bool("disable_sescmd_history"))
, master_accept_reads(params->get_bool("master_accept_reads"))
, strict_multi_stmt(params->get_bool("strict_multi_stmt"))
, strict_sp_calls(params->get_bool("strict_sp_calls"))
, retry_failed_reads(params->get_bool("retry_failed_reads"))
, 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(params->get_bool("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"))
, master_reconnection(params->get_bool("master_reconnection"))
, delayed_retry(params->get_bool("delayed_retry"))
, delayed_retry_timeout(params->get_integer("delayed_retry_timeout"))
, transaction_replay(config_get_bool(params, "transaction_replay"))
, transaction_replay(params->get_bool("transaction_replay"))
, trx_max_size(config_get_size(params, "transaction_replay_max_size"))
, optimistic_trx(config_get_bool(params, "optimistic_trx"))
, optimistic_trx(params->get_bool("optimistic_trx"))
{
if (causal_reads)
{

View File

@ -20,8 +20,8 @@ namespace schemarouter
Config::Config(MXS_CONFIG_PARAMETER* conf)
: refresh_min_interval(conf->get_integer("refresh_interval"))
, refresh_databases(config_get_bool(conf, "refresh_databases"))
, debug(config_get_bool(conf, "debug"))
, refresh_databases(conf->get_bool("refresh_databases"))
, debug(conf->get_bool("debug"))
, ignore_regex(config_get_compiled_regex(conf, "ignore_databases_regex", 0, NULL))
, ignore_match_data(ignore_regex ? pcre2_match_data_create_from_pattern(ignore_regex, NULL) : NULL)
, preferred_server(config_get_server(conf, "preferred_server"))