MXS-2304 Store config parameter container as value in monitor and service

This commit is contained in:
Esa Korhonen 2019-02-19 19:29:13 +02:00
parent 3fa4a85a1e
commit 2a63fb0776
15 changed files with 42 additions and 48 deletions

View File

@ -162,11 +162,11 @@ 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 = params->get_integer(MAX_BACKENDS);
m_write_server = params->get_server(WRITE_BACKEND);
m_print_on_routing = params->get_bool(PRINT_ON_ROUTING);
m_example_enum = params->get_enum(DUMMY, enum_example);
const MXS_CONFIG_PARAMETER& params = service->svc_config_param;
m_max_backends = params.get_integer(MAX_BACKENDS);
m_write_server = params.get_server(WRITE_BACKEND);
m_print_on_routing = params.get_bool(PRINT_ON_ROUTING);
m_example_enum = params.get_enum(DUMMY, enum_example);
RR_DEBUG("Settings read:");
RR_DEBUG("'%s': %d", MAX_BACKENDS, m_max_backends);

View File

@ -315,7 +315,7 @@ public:
uint64_t m_ticks {0}; /**< Number of performed monitoring intervals */
uint8_t m_journal_hash[SHA_DIGEST_LENGTH]; /**< SHA1 hash of the latest written journal */
MXS_CONFIG_PARAMETER* parameters = nullptr; /**< Configuration parameters */
MXS_CONFIG_PARAMETER parameters; /**< Configuration parameters */
std::vector<MXS_MONITORED_SERVER*> m_servers; /**< Monitored servers */
protected:

View File

@ -112,8 +112,7 @@ public:
bool enable_root; /**< Allow root user access */
bool localhost_match_wildcard_host; /**< Match localhost against wildcard
* */
MXS_CONFIG_PARAMETER* svc_config_param; /**< list of config params and values
* */
MXS_CONFIG_PARAMETER svc_config_param; /**< list of config params and values */
int svc_config_version; /**< Version number of configuration
* */
bool svc_do_shutdown; /**< tells the service to exit loops
@ -156,8 +155,7 @@ public:
protected:
SERVICE(const std::string& name,
const std::string& router_name)
: svc_config_param(new MXS_CONFIG_PARAMETER)
, m_name(name) /** Service name. */
: m_name(name) /** Service name. */
, m_router_name(router_name) /** Router module. */
{
}

View File

@ -4899,7 +4899,7 @@ void dump_if_changed(const MXS_MODULE_PARAM* params,
}
void dump_param_list(int file,
MXS_CONFIG_PARAMETER* list,
const MXS_CONFIG_PARAMETER* list,
const std::unordered_set<std::string>& ignored,
const MXS_MODULE_PARAM* common_params,
const MXS_MODULE_PARAM* module_params)

View File

@ -604,7 +604,7 @@ bool do_alter_monitor(Monitor* monitor, const char* key, const char* value)
}
std::lock_guard<std::mutex> guard(crt_lock);
monitor->parameters->set(key, value);
monitor->parameters.set(key, value);
bool success = true;
if (strcmp(key, CN_USER) == 0)
{
@ -695,7 +695,7 @@ bool runtime_alter_monitor(Monitor* monitor, const char* key, const char* value)
}
if (was_running)
{
MonitorManager::monitor_start(monitor, monitor->parameters);
MonitorManager::monitor_start(monitor, &monitor->parameters);
}
return success;
}
@ -729,10 +729,10 @@ bool runtime_alter_service(Service* service, const char* zKey, const char* zValu
if (service->router->configureInstance && service->capabilities & RCAP_TYPE_RUNTIME_CONFIG)
{
// Stash the old value in case the reconfiguration fails.
std::string old_value = service->svc_config_param->get_string(key);
std::string old_value = service->svc_config_param.get_string(key);
service_replace_parameter(service, key.c_str(), value.c_str());
if (!service->router->configureInstance(service->router_instance, service->svc_config_param))
if (!service->router->configureInstance(service->router_instance, &service->svc_config_param))
{
// Reconfiguration failed, restore the old value of the parameter
if (old_value.empty())
@ -2258,7 +2258,7 @@ Monitor* runtime_create_monitor_from_json(json_t* json)
}
else
{
MonitorManager::monitor_start(rval, rval->parameters);
MonitorManager::monitor_start(rval, &rval->parameters);
}
}
}
@ -2440,7 +2440,7 @@ bool runtime_alter_monitor_from_json(Monitor* monitor, json_t* new_json)
if (restart)
{
MonitorManager::monitor_start(monitor, monitor->parameters);
MonitorManager::monitor_start(monitor, &monitor->parameters);
}
}
}

View File

@ -235,7 +235,7 @@ bool get_suffixed_duration(const char* zValue,
// Dump a parameter list into a file as `key=value` pairs
void dump_param_list(int file,
MXS_CONFIG_PARAMETER* list,
const MXS_CONFIG_PARAMETER* list,
const std::unordered_set<std::string>& ignored,
const MXS_MODULE_PARAM* common_params,
const MXS_MODULE_PARAM* module_params);

View File

@ -184,7 +184,6 @@ Monitor::Monitor(const string& name, const string& module)
, m_module(module)
{
memset(m_journal_hash, 0, sizeof(m_journal_hash));
parameters = new MXS_CONFIG_PARAMETER;
}
void Monitor::stop()
@ -236,16 +235,15 @@ bool Monitor::configure_base(const MXS_CONFIG_PARAMETER* params)
if (!error)
{
// Store module name into parameter storage.
parameters->set(CN_MODULE, m_module);
parameters.set(CN_MODULE, m_module);
// Add all config settings to text-mode storage. Needed for serialization.
parameters->set_multiple(*params);
parameters.set_multiple(*params);
}
return !error;
}
Monitor::~Monitor()
{
delete parameters;
monitor_server_free_all(m_servers);
MXS_FREE((const_cast<char*>(m_name)));
}
@ -297,7 +295,7 @@ void monitor_start_all()
this_unit.foreach_monitor([](Monitor* monitor) {
if (monitor->m_active)
{
MonitorManager::monitor_start(monitor, monitor->parameters);
MonitorManager::monitor_start(monitor, &monitor->parameters);
}
return true;
});
@ -367,7 +365,7 @@ bool Monitor::add_server(Monitor* mon, SERVER* server)
if (old_state == MONITOR_STATE_RUNNING)
{
MonitorManager::monitor_start(mon, mon->parameters);
MonitorManager::monitor_start(mon, &mon->parameters);
}
}
@ -455,7 +453,7 @@ void Monitor::remove_server(Monitor* mon, SERVER* server)
if (old_state == MONITOR_STATE_RUNNING)
{
MonitorManager::monitor_start(mon, mon->parameters);
MonitorManager::monitor_start(mon, &mon->parameters);
}
}
@ -1436,7 +1434,7 @@ static bool create_monitor_config(const Monitor* monitor, const char* filename)
mxb_assert(mod);
dump_param_list(file,
monitor->parameters,
&monitor->parameters,
{CN_TYPE, CN_SERVERS},
config_monitor_params,
mod->parameters);
@ -1620,7 +1618,7 @@ json_t* monitor_parameters_to_json(const Monitor* monitor)
{
json_t* rval = json_object();
const MXS_MODULE* mod = get_module(monitor->m_module.c_str(), MODULE_MONITOR);
config_add_module_params_json(monitor->parameters,
config_add_module_params_json(&monitor->parameters,
{CN_TYPE, CN_MODULE, CN_SERVERS},
config_monitor_params,
mod->parameters,

View File

@ -272,7 +272,7 @@ HttpResponse cb_start_monitor(const HttpRequest& request)
Monitor* monitor = monitor_find(request.uri_part(1).c_str());
if (monitor)
{
MonitorManager::monitor_start(monitor, monitor->parameters);
MonitorManager::monitor_start(monitor, &monitor->parameters);
}
return HttpResponse(MHD_HTTP_NO_CONTENT);
}

View File

@ -273,8 +273,6 @@ Service::~Service()
dbref = dbref->next;
MXS_FREE(tmp);
}
delete svc_config_param;
}
void service_free(Service* service)
@ -1150,7 +1148,7 @@ int service_refresh_users(SERVICE* svc)
void service_add_parameters(Service* service, const MXS_CONFIG_PARAMETER* param)
{
service->svc_config_param->set_multiple(*param);
service->svc_config_param.set_multiple(*param);
}
void service_add_parameter(Service* service, const char* key, const char* value)
@ -1162,12 +1160,12 @@ void service_add_parameter(Service* service, const char* key, const char* value)
void service_remove_parameter(Service* service, const char* key)
{
service->svc_config_param->remove(key);
service->svc_config_param.remove(key);
}
void service_replace_parameter(Service* service, const char* key, const char* value)
{
service->svc_config_param->set(key, value);
service->svc_config_param.set(key, value);
}
/**
@ -1467,7 +1465,7 @@ bool Service::dump_config(const char* filename) const
mxb_assert(mod);
dump_param_list(file,
svc_config_param,
&svc_config_param,
{CN_TYPE, CN_FILTERS, CN_SERVERS},
config_service_params,
mod->parameters);
@ -1579,7 +1577,7 @@ json_t* service_parameters_to_json(const SERVICE* service)
json_t* rval = json_object();
const MXS_MODULE* mod = get_module(service->router_name(), MODULE_ROUTER);
config_add_module_params_json(service->svc_config_param,
config_add_module_params_json(&service->svc_config_param,
{CN_TYPE, CN_ROUTER, CN_SERVERS, CN_FILTERS},
config_service_params,
mod->parameters,

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 = parameters->get_bool(CN_AUTO_FAILOVER);
bool failover_setting = parameters.get_bool(CN_AUTO_FAILOVER);
if (failover_setting)
{
disable_setting(CN_AUTO_FAILOVER);

View File

@ -698,7 +698,7 @@ void MariaDBMonitor::assign_new_master(MariaDBServer* new_master)
*/
void MariaDBMonitor::disable_setting(const std::string& setting)
{
parameters->set(setting, "false");
parameters.set(setting, "false");
}
/**

View File

@ -61,12 +61,12 @@ using namespace maxscale;
*/
void Avro::read_source_service_options(SERVICE* source)
{
MXS_CONFIG_PARAMETER* params = source->svc_config_param;
binlogdir = params->get_string("binlogdir");
filestem = params->get_string("filestem");
MXS_CONFIG_PARAMETER& params = source->svc_config_param;
binlogdir = params.get_string("binlogdir");
filestem = params.get_string("filestem");
mxb_assert(!binlogdir.empty() && !filestem.empty());
for (const auto& opt : mxs::strtok(params->get_string("router_options"), ", \t"))
for (const auto& opt : mxs::strtok(params.get_string("router_options"), ", \t"))
{
auto kv = mxs::strtok(opt, "=");
@ -85,7 +85,7 @@ void Avro::read_source_service_options(SERVICE* source)
Avro* Avro::create(SERVICE* service, SRowEventHandler handler)
{
SERVICE* source_service = NULL;
std::string source_name = service->svc_config_param->get_string("source");
std::string source_name = service->svc_config_param.get_string("source");
if (!source_name.empty())
{
@ -115,7 +115,7 @@ Avro* Avro::create(SERVICE* service, SRowEventHandler handler)
}
}
return new(std::nothrow) Avro(service, service->svc_config_param, source_service, handler);
return new(std::nothrow) Avro(service, &service->svc_config_param, source_service, handler);
}
Avro::Avro(SERVICE* service, MXS_CONFIG_PARAMETER* params, SERVICE* source, SRowEventHandler handler)

View File

@ -60,10 +60,10 @@ static bool conversion_task_ctl(Avro* inst, bool start);
*/
MXS_ROUTER* createInstance(SERVICE* service, MXS_CONFIG_PARAMETER* params)
{
uint64_t block_size = service->svc_config_param->get_size("block_size");
uint64_t block_size = service->svc_config_param.get_size("block_size");
mxs_avro_codec_type codec = static_cast<mxs_avro_codec_type>(
service->svc_config_param->get_enum("codec", codec_values));
std::string avrodir = service->svc_config_param->get_string("avrodir");
service->svc_config_param.get_enum("codec", codec_values));
std::string avrodir = service->svc_config_param.get_string("avrodir");
SRowEventHandler handler(new AvroConverter(avrodir, block_size, codec));
Avro* router = Avro::create(service, handler);

View File

@ -2727,7 +2727,7 @@ static void shutdown_monitor(DCB* dcb, Monitor* monitor)
*/
static void restart_monitor(DCB* dcb, Monitor* monitor)
{
MonitorManager::monitor_start(monitor, monitor->parameters);
MonitorManager::monitor_start(monitor, &monitor->parameters);
}
/**

View File

@ -615,7 +615,7 @@ void exec_restart_monitor(DCB* dcb, MAXINFO_TREE* tree)
Monitor* monitor = monitor_find(tree->value);
if (monitor)
{
MonitorManager::monitor_start(monitor, monitor->parameters);
MonitorManager::monitor_start(monitor, &monitor->parameters);
maxinfo_send_ok(dcb);
}
else