Fix alteration of new router parameters
If a router parameter has no default value, the previous value would be returned as an empty string. A debug assertion would be triggered when a parameter of this type was altered. When a new router parameter is encountered and the alteration fails, the modified value in the service need to be removed. Previously, the new value would have been stored in the service with an empty value which would have caused problems.
This commit is contained in:
@ -658,7 +658,6 @@ bool runtime_alter_service(SERVICE *service, const char* zKey, const char* zValu
|
||||
{
|
||||
// Stash the old value in case the reconfiguration fails.
|
||||
std::string old_value = config_get_string(service->svc_config_param, key.c_str());
|
||||
ss_dassert(!old_value.empty());
|
||||
service_replace_parameter(service, key.c_str(), value.c_str());
|
||||
|
||||
if (service->router->configureInstance(service->router_instance, service->svc_config_param))
|
||||
@ -668,7 +667,14 @@ bool runtime_alter_service(SERVICE *service, const char* zKey, const char* zValu
|
||||
else
|
||||
{
|
||||
// Reconfiguration failed, restore the old value of the parameter
|
||||
service_replace_parameter(service, key.c_str(), old_value.c_str());
|
||||
if (old_value.empty())
|
||||
{
|
||||
service_remove_parameter(service, key.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
service_replace_parameter(service, key.c_str(), old_value.c_str());
|
||||
}
|
||||
runtime_error("Reconfiguration of service '%s' failed. See log "
|
||||
"file for more details.", service->name);
|
||||
}
|
||||
|
@ -135,6 +135,14 @@ void service_update(SERVICE *service, char *router, char *user, char *auth);
|
||||
*/
|
||||
void service_add_parameters(SERVICE *service, const MXS_CONFIG_PARAMETER *param);
|
||||
|
||||
/**
|
||||
* @brief Remove service parameter
|
||||
*
|
||||
* @param service Service to modify
|
||||
* @param key Parameter to remove
|
||||
*/
|
||||
void service_remove_parameter(SERVICE *service, const char* key);
|
||||
|
||||
/**
|
||||
* @brief Replace service parameter
|
||||
*
|
||||
|
@ -1780,6 +1780,41 @@ void service_add_parameters(SERVICE *service, const char* key, const char* value
|
||||
service_add_parameters(service, &p);
|
||||
}
|
||||
|
||||
void service_remove_parameter(SERVICE *service, const char* key)
|
||||
{
|
||||
if (MXS_CONFIG_PARAMETER* params = service->svc_config_param)
|
||||
{
|
||||
MXS_CONFIG_PARAMETER* to_free = NULL;
|
||||
|
||||
if (strcasecmp(params->name, key) == 0)
|
||||
{
|
||||
service->svc_config_param = params->next;
|
||||
to_free = params;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (MXS_CONFIG_PARAMETER* p = params->next)
|
||||
{
|
||||
if (strcasecmp(p->name, key) == 0)
|
||||
{
|
||||
params->next = p->next;
|
||||
to_free = p;
|
||||
break;
|
||||
}
|
||||
|
||||
params = p;
|
||||
}
|
||||
}
|
||||
|
||||
if (to_free)
|
||||
{
|
||||
// Set next pointer to null to prevent freeing of other parameters
|
||||
to_free->next = NULL;
|
||||
config_parameter_free(to_free);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void service_replace_parameter(SERVICE *service, const char* key, const char* value)
|
||||
{
|
||||
for (MXS_CONFIG_PARAMETER* p = service->svc_config_param; p; p = p->next)
|
||||
|
Reference in New Issue
Block a user