Use module parameters in monitors

All monitors now declare the parameters that they use. This allows the
core to check the validity of the parameters before they are passed to the
monitor. It also simplifies the processing of the parameters as they are
guaranteed to be valid.
This commit is contained in:
Markus Mäkelä
2017-01-04 11:54:30 +02:00
parent cefc253e2c
commit 5a290cb0b8
6 changed files with 54 additions and 87 deletions

View File

@ -1946,10 +1946,9 @@ check_config_objects(CONFIG_CONTEXT *context)
} }
else if (!strcmp(type, "monitor")) else if (!strcmp(type, "monitor"))
{ {
// TODO: Declare monitor parameters param_set = monitor_params;
//param_set = monitor_params; module = config_get_value(obj->parameters, "module");
//module = config_get_value(obj->parameters, "module"); module_type = MODULE_MONITOR;
//module_type = MODULE_MONITOR;
} }
else if (!strcmp(type, "filter")) else if (!strcmp(type, "filter"))
{ {

View File

@ -77,7 +77,15 @@ MXS_MODULE* MXS_CREATE_MODULE()
MONITOR_VERSION, MONITOR_VERSION,
"A Galera cluster monitor", "A Galera cluster monitor",
"V2.0.0", "V2.0.0",
&MyObject &MyObject,
{
{"disable_master_failback", MXS_MODULE_PARAM_BOOL, "false"},
{"available_when_donor", MXS_MODULE_PARAM_BOOL, "false"},
{"disable_master_role_setting", MXS_MODULE_PARAM_BOOL, "false"},
{"root_node_as_master", MXS_MODULE_PARAM_BOOL, "true"},
{"use_priority", MXS_MODULE_PARAM_BOOL, "false"},
{MXS_END_MODULE_PARAMS}
}
}; };
return &info; return &info;
@ -107,41 +115,21 @@ startMonitor(MONITOR *mon, const CONFIG_PARAMETER *params)
} }
handle->shutdown = 0; handle->shutdown = 0;
handle->id = MONITOR_DEFAULT_ID; handle->id = MONITOR_DEFAULT_ID;
handle->disableMasterFailback = 0;
handle->availableWhenDonor = 0;
handle->disableMasterRoleSetting = false;
handle->master = NULL; handle->master = NULL;
handle->script = NULL; handle->script = NULL;
handle->root_node_as_master = true;
handle->use_priority = false;
memset(handle->events, false, sizeof(handle->events)); memset(handle->events, false, sizeof(handle->events));
spinlock_init(&handle->lock); spinlock_init(&handle->lock);
} }
handle->disableMasterFailback = config_get_bool(params, "disable_master_failback");
handle->availableWhenDonor = config_get_bool(params, "available_when_donor");
handle->disableMasterRoleSetting = config_get_bool(params, "disable_master_role_setting");
handle->root_node_as_master = config_get_bool(params, "root_node_as_master");
handle->use_priority = config_get_bool(params, "use_priority");
while (params) while (params)
{ {
if (!strcmp(params->name, "disable_master_failback")) if (!strcmp(params->name, "script"))
{
handle->disableMasterFailback = config_truth_value(params->value);
}
else if (!strcmp(params->name, "available_when_donor"))
{
handle->availableWhenDonor = config_truth_value(params->value);
}
else if (!strcmp(params->name, "disable_master_role_setting"))
{
handle->disableMasterRoleSetting = config_truth_value(params->value);
}
else if (!strcmp(params->name, "root_node_as_master"))
{
handle->root_node_as_master = config_truth_value(params->value);
}
else if (!strcmp(params->name, "use_priority"))
{
handle->use_priority = config_truth_value(params->value);
}
else if (!strcmp(params->name, "script"))
{ {
if (externcmd_can_execute(params->value)) if (externcmd_can_execute(params->value))
{ {
@ -450,8 +438,8 @@ monitorMain(void *arg)
* round. * round.
*/ */
if (nrounds != 0 && if (nrounds != 0 &&
(((nrounds * MON_BASE_INTERVAL_MS) % mon->interval) >= (((nrounds * MON_BASE_INTERVAL_MS) % mon->interval) >=
MON_BASE_INTERVAL_MS) && (!mon->server_pending_changes)) MON_BASE_INTERVAL_MS) && (!mon->server_pending_changes))
{ {
nrounds += 1; nrounds += 1;
continue; continue;

View File

@ -78,7 +78,11 @@ MXS_MODULE* MXS_CREATE_MODULE()
MONITOR_VERSION, MONITOR_VERSION,
"A Multi-Master Multi Master monitor", "A Multi-Master Multi Master monitor",
"V1.1.1", "V1.1.1",
&MyObject &MyObject,
{
{"detect_stale_master", MXS_MODULE_PARAM_BOOL, "false"},
{MXS_END_MODULE_PARAMS}
}
}; };
return &info; return &info;
@ -113,18 +117,15 @@ startMonitor(MONITOR *mon, const CONFIG_PARAMETER *params)
handle->id = MONITOR_DEFAULT_ID; handle->id = MONITOR_DEFAULT_ID;
handle->master = NULL; handle->master = NULL;
handle->script = NULL; handle->script = NULL;
handle->detectStaleMaster = false;
memset(handle->events, false, sizeof(handle->events)); memset(handle->events, false, sizeof(handle->events));
spinlock_init(&handle->lock); spinlock_init(&handle->lock);
} }
handle->detectStaleMaster = config_get_bool(params, "detect_stale_master");
while (params) while (params)
{ {
if (!strcmp(params->name, "detect_stale_master")) if (!strcmp(params->name, "script"))
{
handle->detectStaleMaster = config_truth_value(params->value);
}
else if (!strcmp(params->name, "script"))
{ {
if (externcmd_can_execute(params->value)) if (externcmd_can_execute(params->value))
{ {
@ -536,7 +537,7 @@ monitorMain(void *arg)
*/ */
if (nrounds != 0 && if (nrounds != 0 &&
(((nrounds * MON_BASE_INTERVAL_MS) % mon->interval) >= (((nrounds * MON_BASE_INTERVAL_MS) % mon->interval) >=
MON_BASE_INTERVAL_MS) && (!mon->server_pending_changes)) MON_BASE_INTERVAL_MS) && (!mon->server_pending_changes))
{ {
nrounds += 1; nrounds += 1;
continue; continue;

View File

@ -53,8 +53,6 @@
MXS_BEGIN_DECLS MXS_BEGIN_DECLS
#define MYSQLMON_DEFAULT_FAILCOUNT 5
/** /**
* The handle for an instance of a MySQL Monitor module * The handle for an instance of a MySQL Monitor module
*/ */

View File

@ -112,7 +112,17 @@ MXS_MODULE* MXS_CREATE_MODULE()
MONITOR_VERSION, MONITOR_VERSION,
"A MySQL Master/Slave replication monitor", "A MySQL Master/Slave replication monitor",
"V1.5.0", "V1.5.0",
&MyObject &MyObject,
{
{"detect_replication_lag", MXS_MODULE_PARAM_BOOL, "false"},
{"detect_stale_master", MXS_MODULE_PARAM_BOOL, "true"},
{"detect_stale_slave", MXS_MODULE_PARAM_BOOL, "true"},
{"mysql51_replication", MXS_MODULE_PARAM_BOOL, "false"},
{"multimaster", MXS_MODULE_PARAM_BOOL, "false"},
{"failover", MXS_MODULE_PARAM_BOOL, "false"},
{"failcount", MXS_MODULE_PARAM_COUNT, "5"},
{MXS_END_MODULE_PARAMS}
}
}; };
return &info; return &info;
@ -238,14 +248,7 @@ startMonitor(MONITOR *monitor, const CONFIG_PARAMETER* params)
handle->server_info = server_info; handle->server_info = server_info;
handle->shutdown = 0; handle->shutdown = 0;
handle->id = config_get_gateway_id(); handle->id = config_get_gateway_id();
handle->replicationHeartbeat = 0;
handle->detectStaleMaster = true;
handle->detectStaleSlave = true;
handle->script = NULL; handle->script = NULL;
handle->multimaster = false;
handle->mysql51_replication = false;
handle->failover = false;
handle->failcount = MYSQLMON_DEFAULT_FAILCOUNT;
handle->warn_failover = true; handle->warn_failover = true;
memset(handle->events, false, sizeof(handle->events)); memset(handle->events, false, sizeof(handle->events));
spinlock_init(&handle->lock); spinlock_init(&handle->lock);
@ -254,38 +257,17 @@ startMonitor(MONITOR *monitor, const CONFIG_PARAMETER* params)
/** This should always be reset to NULL */ /** This should always be reset to NULL */
handle->master = NULL; handle->master = NULL;
handle->detectStaleMaster = config_get_bool(params, "detect_stale_master");
handle->detectStaleSlave = config_get_bool(params, "detect_stale_slave");
handle->replicationHeartbeat = config_get_bool(params, "detect_replication_lag");
handle->multimaster = config_get_bool(params, "multimaster");
handle->failover = config_get_bool(params, "failover");
handle->failcount = config_get_integer(params, "failcount");
handle->mysql51_replication = config_get_bool(params, "mysql51_replication");
while (params) while (params)
{ {
if (!strcmp(params->name, "detect_stale_master")) if (!strcmp(params->name, "script"))
{
handle->detectStaleMaster = config_truth_value(params->value);
}
else if (!strcmp(params->name, "detect_stale_slave"))
{
handle->detectStaleSlave = config_truth_value(params->value);
}
else if (!strcmp(params->name, "detect_replication_lag"))
{
handle->replicationHeartbeat = config_truth_value(params->value);
}
else if (!strcmp(params->name, "multimaster"))
{
handle->multimaster = config_truth_value(params->value);
}
else if (!strcmp(params->name, "failover"))
{
handle->failover = config_truth_value(params->value);
}
else if (!strcmp(params->name, "failcount"))
{
handle->failcount = atoi(params->value);
if (handle->failcount <= 0)
{
MXS_ERROR("[%s] Invalid value for 'failcount': %s", monitor->name, params->value);
error = true;
}
}
else if (!strcmp(params->name, "script"))
{ {
if (externcmd_can_execute(params->value)) if (externcmd_can_execute(params->value))
{ {
@ -308,10 +290,6 @@ startMonitor(MONITOR *monitor, const CONFIG_PARAMETER* params)
have_events = true; have_events = true;
} }
} }
else if (!strcmp(params->name, "mysql51_replication"))
{
handle->mysql51_replication = config_truth_value(params->value);
}
params = params->next; params = params->next;
} }
@ -1123,7 +1101,7 @@ monitorMain(void *arg)
*/ */
if (nrounds != 0 && if (nrounds != 0 &&
(((nrounds * MON_BASE_INTERVAL_MS) % mon->interval) >= (((nrounds * MON_BASE_INTERVAL_MS) % mon->interval) >=
MON_BASE_INTERVAL_MS) && (!mon->server_pending_changes)) MON_BASE_INTERVAL_MS) && (!mon->server_pending_changes))
{ {
nrounds += 1; nrounds += 1;
continue; continue;

View File

@ -71,7 +71,10 @@ MXS_MODULE* MXS_CREATE_MODULE()
MONITOR_VERSION, MONITOR_VERSION,
"A MySQL cluster SQL node monitor", "A MySQL cluster SQL node monitor",
"V2.1.0", "V2.1.0",
&MyObject &MyObject,
{
{MXS_END_MODULE_PARAMS} // No parameters
}
}; };
return &info; return &info;