MXS-1444: Add monitor parameter alteration
The parameter handling for monitors can now be done in a consistent manner by establishing a rule that the monitor owns the parameter object as long as it is running. This will allow parameters to be added and removed safely both from outside and inside monitors. Currently this functionality is only used by mysqlmon to disable failover after an attempt to perform a failover has failed.
This commit is contained in:
@ -273,6 +273,21 @@ const char* mon_get_event_name(mxs_monitor_event_t event);
|
||||
void lock_monitor_servers(MXS_MONITOR *monitor);
|
||||
void release_monitor_servers(MXS_MONITOR *monitor);
|
||||
|
||||
/**
|
||||
* Alter monitor parameters
|
||||
*
|
||||
* The monitor parameters should not be altered while the monitor is
|
||||
* running. To alter a parameter from outside a monitor module, stop the monitor,
|
||||
* do the alteration and then restart the monitor. The monitor "owns" the parameters
|
||||
* as long as it is running so if the monitor needs to change its own parameters,
|
||||
* it can do it without stopping itself.
|
||||
*
|
||||
* @param monitor Monitor whose parameter is altered
|
||||
* @param key Parameter name to alter
|
||||
* @param value New value for the parameter
|
||||
*/
|
||||
void mon_alter_parameter(MXS_MONITOR* monitor, const char* key, const char* value);
|
||||
|
||||
/**
|
||||
* @brief Handle state change events
|
||||
*
|
||||
|
@ -856,6 +856,8 @@ bool check_monitor_permissions(MXS_MONITOR* monitor, const char* query)
|
||||
*/
|
||||
void monitorAddParameters(MXS_MONITOR *monitor, MXS_CONFIG_PARAMETER *params)
|
||||
{
|
||||
spinlock_acquire(&monitor->lock);
|
||||
|
||||
while (params)
|
||||
{
|
||||
MXS_CONFIG_PARAMETER* old = config_get_param(monitor->parameters, params->name);
|
||||
@ -874,11 +876,16 @@ void monitorAddParameters(MXS_MONITOR *monitor, MXS_CONFIG_PARAMETER *params)
|
||||
|
||||
params = params->next;
|
||||
}
|
||||
|
||||
spinlock_release(&monitor->lock);
|
||||
}
|
||||
|
||||
bool monitorRemoveParameter(MXS_MONITOR *monitor, const char *key)
|
||||
{
|
||||
MXS_CONFIG_PARAMETER *prev = NULL;
|
||||
bool rval = false;
|
||||
|
||||
spinlock_acquire(&monitor->lock);
|
||||
|
||||
for (MXS_CONFIG_PARAMETER *p = monitor->parameters; p; p = p->next)
|
||||
{
|
||||
@ -887,19 +894,41 @@ bool monitorRemoveParameter(MXS_MONITOR *monitor, const char *key)
|
||||
if (p == monitor->parameters)
|
||||
{
|
||||
monitor->parameters = monitor->parameters->next;
|
||||
p->next = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
prev->next = p->next;
|
||||
p->next = NULL;
|
||||
}
|
||||
|
||||
p->next = NULL;
|
||||
config_parameter_free(p);
|
||||
return true;
|
||||
rval = true;
|
||||
break;
|
||||
}
|
||||
|
||||
prev = p;
|
||||
}
|
||||
return false;
|
||||
|
||||
spinlock_release(&monitor->lock);
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
void mon_alter_parameter(MXS_MONITOR* monitor, const char* key, const char* value)
|
||||
{
|
||||
spinlock_acquire(&monitor->lock);
|
||||
|
||||
for (MXS_CONFIG_PARAMETER* p = monitor->parameters; p; p = p->next)
|
||||
{
|
||||
if (strcmp(p->name, key) == 0)
|
||||
{
|
||||
MXS_FREE(p->value);
|
||||
p->value = MXS_STRDUP_A(value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
spinlock_release(&monitor->lock);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1531,6 +1560,8 @@ static bool create_monitor_config(const MXS_MONITOR *monitor, const char *filena
|
||||
return false;
|
||||
}
|
||||
|
||||
spinlock_acquire(&monitor->lock);
|
||||
|
||||
dprintf(file, "[%s]\n", monitor->name);
|
||||
dprintf(file, "%s=monitor\n", CN_TYPE);
|
||||
dprintf(file, "%s=%s\n", CN_MODULE, monitor->module_name);
|
||||
@ -1585,6 +1616,8 @@ static bool create_monitor_config(const MXS_MONITOR *monitor, const char *filena
|
||||
}
|
||||
}
|
||||
|
||||
spinlock_release(&monitor->lock);
|
||||
|
||||
close(file);
|
||||
|
||||
return true;
|
||||
|
@ -1878,6 +1878,8 @@ monitorMain(void *arg)
|
||||
MXS_ALERT("Failed to perform failover, disabling failover functionality. "
|
||||
"To enable failover functionality, manually set 'failover' to "
|
||||
"'true' for monitor '%s' via MaxAdmin or the REST API.", mon->name);
|
||||
|
||||
mon_alter_parameter(handle->monitor, CN_FAILOVER, "false");
|
||||
handle->failover = false;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user