Move monitor script processing and launching into the core

This removes parts of the nearly identical code from all monitors.

The removal of monitor type specific event checking is done based on the
assumption that only the monitor that is monitoring the server can be the
cause for a state change. This removes the need to actually check that the
state change is relevant for each monitor and allows the event handling to
be moved into the core.
This commit is contained in:
Markus Mäkelä
2017-01-11 11:11:11 +02:00
parent 7ef5e4bfd9
commit a196420c2d
11 changed files with 206 additions and 680 deletions

View File

@ -88,6 +88,19 @@ MXS_MODULE* MXS_CREATE_MODULE()
{"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"},
{
"script",
MXS_MODULE_PARAM_PATH,
NULL,
MXS_MODULE_OPT_PATH_X_OK
},
{
"events",
MXS_MODULE_PARAM_ENUM,
MONITOR_EVENT_DEFAULT_VALUE,
MXS_MODULE_OPT_NONE,
monitor_event_enum_values
},
{MXS_END_MODULE_PARAMS}
}
};
@ -106,10 +119,10 @@ static void *
startMonitor(MONITOR *mon, const CONFIG_PARAMETER *params)
{
GALERA_MONITOR *handle = mon->handle;
bool have_events = false, script_error = false;
if (handle != NULL)
{
handle->shutdown = 0;
MXS_FREE(handle->script);
}
else
{
@ -120,8 +133,6 @@ startMonitor(MONITOR *mon, const CONFIG_PARAMETER *params)
handle->shutdown = 0;
handle->id = MONITOR_DEFAULT_ID;
handle->master = NULL;
handle->script = NULL;
memset(handle->events, false, sizeof(handle->events));
spinlock_init(&handle->lock);
}
@ -130,35 +141,8 @@ startMonitor(MONITOR *mon, const CONFIG_PARAMETER *params)
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)
{
if (!strcmp(params->name, "script"))
{
if (externcmd_can_execute(params->value))
{
MXS_FREE(handle->script);
handle->script = MXS_STRDUP_A(params->value);
}
else
{
script_error = true;
}
}
else if (!strcmp(params->name, "events"))
{
if (mon_parse_event_string((bool *) handle->events,
sizeof(handle->events), params->value) != 0)
{
script_error = true;
}
else
{
have_events = true;
}
}
params = params->next;
}
handle->script = config_copy_string(params, "script");
handle->events = config_get_enum(params, "events", monitor_event_enum_values);
/** SHOW STATUS doesn't require any special permissions */
if (!check_monitor_permissions(mon, "SHOW STATUS LIKE 'wsrep_local_state'"))
@ -169,19 +153,6 @@ startMonitor(MONITOR *mon, const CONFIG_PARAMETER *params)
return NULL;
}
if (script_error)
{
MXS_ERROR("Errors were found in the script configuration parameters "
"for the monitor '%s'. The script will not be used.", mon->name);
MXS_FREE(handle->script);
handle->script = NULL;
}
/** If no specific events are given, enable them all */
if (!have_events)
{
memset(handle->events, true, sizeof(handle->events));
}
if (thread_start(&handle->thread, monitorMain, mon) == NULL)
{
MXS_ERROR("Failed to start monitor thread for monitor '%s'.", mon->name);
@ -551,26 +522,12 @@ monitorMain(void *arg)
}
}
ptr = mon->databases;
while (ptr)
{
/** Execute monitor script if a server state has changed */
if (mon_status_changed(ptr))
{
evtype = mon_get_event_type(ptr);
if (isGaleraEvent(evtype))
{
mon_log_state_change(ptr);
if (handle->script && handle->events[evtype])
{
monitor_launch_script(mon, ptr, handle->script);
}
}
}
ptr = ptr->next;
}
/**
* After updating the status of all servers, check if monitor events
* need to be launched.
*/
mon_process_state_changes(mon, handle->script, handle->events);
mon_hangup_failed_servers(mon);
servers_status_current_to_pending(mon);
@ -687,81 +644,3 @@ static MONITOR_SERVERS *set_cluster_master(MONITOR_SERVERS *current_master, MONI
}
}
}
/**
* Disable/Enable the Master failback in a Galera Cluster.
*
* A restarted / rejoined node may get back the previous 'wsrep_local_index'
* from Cluster: if the value is the lowest in the cluster it will be selected as Master
* This will cause a Master change even if there is no failure.
* The option if set to 1 will avoid this situation, keeping the current Master (if running) available
*
* @param arg The handle allocated by startMonitor
* @param disable To disable it use 1, 0 keeps failback
*
* NOT USED
static void
disableMasterFailback(void *arg, int disable)
{
GALERA_MONITOR *handle = (GALERA_MONITOR *) arg;
memcpy(&handle->disableMasterFailback, &disable, sizeof(int));
}
*/
/**
* Allow a Galera node to be in sync when Donor.
*
* When enabled, the monitor will check if the node is using xtrabackup or xtrabackup-v2
* as SST method. In that case, node will stay as synced.
*
* @param arg The handle allocated by startMonitor
* @param disable To allow sync status use 1, 0 for traditional behavior
* NOT USED
static void
availableWhenDonor(void *arg, int disable)
{
GALERA_MONITOR *handle = (GALERA_MONITOR *) arg;
memcpy(&handle->availableWhenDonor, &disable, sizeof(int));
}
*/
static monitor_event_t galera_events[] =
{
MASTER_DOWN_EVENT,
MASTER_UP_EVENT,
SLAVE_DOWN_EVENT,
SLAVE_UP_EVENT,
SERVER_DOWN_EVENT,
SERVER_UP_EVENT,
SYNCED_DOWN_EVENT,
SYNCED_UP_EVENT,
DONOR_DOWN_EVENT,
DONOR_UP_EVENT,
LOST_MASTER_EVENT,
LOST_SLAVE_EVENT,
LOST_SYNCED_EVENT,
LOST_DONOR_EVENT,
NEW_MASTER_EVENT,
NEW_SLAVE_EVENT,
NEW_SYNCED_EVENT,
NEW_DONOR_EVENT,
MAX_MONITOR_EVENT
};
/**
* Check if the Galera monitor is monitoring this event type.
* @param event Event to check
* @return True if the event is monitored, false if it is not
* */
bool isGaleraEvent(monitor_event_t event)
{
int i;
for (i = 0; galera_events[i] != MAX_MONITOR_EVENT; i++)
{
if (event == galera_events[i])
{
return true;
}
}
return false;
}

View File

@ -61,7 +61,7 @@ typedef struct
bool root_node_as_master; /**< Whether we require that the Master should
* have a wsrep_local_index of 0 */
bool use_priority; /*< Use server priorities */
bool events[MAX_MONITOR_EVENT]; /*< enabled events */
uint64_t events; /*< enabled events */
} GALERA_MONITOR;
MXS_END_DECLS