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:
@ -27,7 +27,7 @@ typedef struct aurora_monitor
|
||||
bool shutdown; /**< True if the monitor is stopped */
|
||||
THREAD thread; /**< Monitor thread */
|
||||
char* script; /**< Launchable script */
|
||||
bool events[MAX_MONITOR_EVENT]; /**< Enabled monitor events */
|
||||
uint64_t events; /**< Enabled monitor events */
|
||||
} AURORA_MONITOR;
|
||||
|
||||
/**
|
||||
@ -101,39 +101,6 @@ void update_server_status(MONITOR *monitor, MONITOR_SERVERS *database)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if this is an event that the Aurora monitor handles
|
||||
* @param event Event to check
|
||||
* @return True if the event is monitored, false if it is not
|
||||
* */
|
||||
bool is_aurora_event(monitor_event_t event)
|
||||
{
|
||||
static monitor_event_t aurora_events[] =
|
||||
{
|
||||
MASTER_DOWN_EVENT,
|
||||
MASTER_UP_EVENT,
|
||||
SLAVE_DOWN_EVENT,
|
||||
SLAVE_UP_EVENT,
|
||||
SERVER_DOWN_EVENT,
|
||||
SERVER_UP_EVENT,
|
||||
LOST_MASTER_EVENT,
|
||||
LOST_SLAVE_EVENT,
|
||||
NEW_MASTER_EVENT,
|
||||
NEW_SLAVE_EVENT,
|
||||
MAX_MONITOR_EVENT
|
||||
};
|
||||
|
||||
for (int i = 0; aurora_events[i] != MAX_MONITOR_EVENT; i++)
|
||||
{
|
||||
if (event == aurora_events[i])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Main monitoring loop
|
||||
*
|
||||
@ -170,25 +137,9 @@ monitorMain(void *arg)
|
||||
/**
|
||||
* After updating the status of all servers, check if monitor events
|
||||
* need to be launched.
|
||||
*
|
||||
* TODO: Move this functionality into monitor.c, it is duplicated in
|
||||
* every monitor.
|
||||
*/
|
||||
for (MONITOR_SERVERS *ptr = monitor->databases; ptr; ptr = ptr->next)
|
||||
{
|
||||
if (mon_status_changed(ptr))
|
||||
{
|
||||
monitor_event_t evtype = mon_get_event_type(ptr);
|
||||
if (is_aurora_event(evtype))
|
||||
{
|
||||
mon_log_state_change(ptr);
|
||||
if (handle->script && handle->events[evtype])
|
||||
{
|
||||
monitor_launch_script(monitor, ptr, handle->script);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
mon_process_state_changes(monitor, handle->script, handle->events);
|
||||
|
||||
servers_status_current_to_pending(monitor);
|
||||
release_monitor_servers(monitor);
|
||||
|
||||
@ -233,12 +184,12 @@ static void auroramon_free(AURORA_MONITOR *handle)
|
||||
static void *
|
||||
startMonitor(MONITOR *mon, const CONFIG_PARAMETER *params)
|
||||
{
|
||||
bool have_events = false, script_error = false;
|
||||
AURORA_MONITOR *handle = mon->handle;
|
||||
|
||||
if (handle)
|
||||
{
|
||||
handle->shutdown = false;
|
||||
MXS_FREE(handle->script);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -248,35 +199,6 @@ startMonitor(MONITOR *mon, const CONFIG_PARAMETER *params)
|
||||
}
|
||||
|
||||
handle->shutdown = false;
|
||||
handle->script = NULL;
|
||||
memset(handle->events, false, sizeof(handle->events));
|
||||
|
||||
while (params)
|
||||
{
|
||||
if (strcmp(params->name, "script") == 0)
|
||||
{
|
||||
if (externcmd_can_execute(params->value))
|
||||
{
|
||||
handle->script = MXS_STRDUP_A(params->value);
|
||||
}
|
||||
else
|
||||
{
|
||||
script_error = true;
|
||||
}
|
||||
}
|
||||
else if (strcmp(params->name, "events") == 0)
|
||||
{
|
||||
if (mon_parse_event_string(handle->events, sizeof(handle->events), params->value) != 0)
|
||||
{
|
||||
script_error = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
have_events = true;
|
||||
}
|
||||
}
|
||||
params = params->next;
|
||||
}
|
||||
|
||||
if (!check_monitor_permissions(mon, "SELECT @@aurora_server_id, server_id FROM "
|
||||
"information_schema.replica_host_status "
|
||||
@ -286,22 +208,11 @@ startMonitor(MONITOR *mon, const CONFIG_PARAMETER *params)
|
||||
auroramon_free(handle);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (script_error)
|
||||
{
|
||||
MXS_ERROR("Errors were found in the script configuration parameters "
|
||||
"for the monitor '%s'.", mon->name);
|
||||
auroramon_free(handle);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/** If no specific events are given, enable them all */
|
||||
if (!have_events)
|
||||
{
|
||||
memset(handle->events, true, sizeof(handle->events));
|
||||
}
|
||||
}
|
||||
|
||||
handle->script = config_copy_string(params, "script");
|
||||
handle->events = config_get_enum(params, "events", monitor_event_enum_values);
|
||||
|
||||
if (thread_start(&handle->thread, monitorMain, mon) == NULL)
|
||||
{
|
||||
MXS_ERROR("Failed to start monitor thread for monitor '%s'.", mon->name);
|
||||
@ -366,6 +277,19 @@ MXS_MODULE* MXS_CREATE_MODULE()
|
||||
NULL, /* Thread init. */
|
||||
NULL, /* Thread finish. */
|
||||
{
|
||||
{
|
||||
"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}
|
||||
}
|
||||
};
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -85,6 +85,19 @@ MXS_MODULE* MXS_CREATE_MODULE()
|
||||
NULL, /* Thread finish. */
|
||||
{
|
||||
{"detect_stale_master", 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}
|
||||
}
|
||||
};
|
||||
@ -105,11 +118,11 @@ static void *
|
||||
startMonitor(MONITOR *mon, const CONFIG_PARAMETER *params)
|
||||
{
|
||||
MM_MONITOR *handle = mon->handle;
|
||||
bool have_events = false, script_error = false;
|
||||
|
||||
if (handle)
|
||||
{
|
||||
handle->shutdown = 0;
|
||||
MXS_FREE(handle->script);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -120,41 +133,12 @@ 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);
|
||||
}
|
||||
|
||||
handle->detectStaleMaster = config_get_bool(params, "detect_stale_master");
|
||||
|
||||
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);
|
||||
|
||||
if (!check_monitor_permissions(mon, "SHOW SLAVE STATUS"))
|
||||
{
|
||||
@ -164,19 +148,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);
|
||||
@ -615,24 +586,11 @@ monitorMain(void *arg)
|
||||
ptr = ptr->next;
|
||||
}
|
||||
|
||||
ptr = mon->databases;
|
||||
monitor_event_t evtype;
|
||||
while (ptr)
|
||||
{
|
||||
if (mon_status_changed(ptr))
|
||||
{
|
||||
evtype = mon_get_event_type(ptr);
|
||||
if (isMySQLEvent(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);
|
||||
@ -717,37 +675,3 @@ static MONITOR_SERVERS *get_current_master(MONITOR *mon)
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static monitor_event_t mysql_events[] =
|
||||
{
|
||||
MASTER_DOWN_EVENT,
|
||||
MASTER_UP_EVENT,
|
||||
SLAVE_DOWN_EVENT,
|
||||
SLAVE_UP_EVENT,
|
||||
SERVER_DOWN_EVENT,
|
||||
SERVER_UP_EVENT,
|
||||
LOST_MASTER_EVENT,
|
||||
LOST_SLAVE_EVENT,
|
||||
NEW_MASTER_EVENT,
|
||||
NEW_SLAVE_EVENT,
|
||||
MAX_MONITOR_EVENT
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if the MM monitor is monitoring this event type.
|
||||
* @param event Event to check
|
||||
* @return True if the event is monitored, false if it is not
|
||||
* */
|
||||
bool isMySQLEvent(monitor_event_t event)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; mysql_events[i] != MAX_MONITOR_EVENT; i++)
|
||||
{
|
||||
if (event == mysql_events[i])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ typedef struct
|
||||
int detectStaleMaster; /**< Monitor flag for Stale Master detection */
|
||||
MONITOR_SERVERS *master; /**< Master server for Master/Slave replication */
|
||||
char* script; /*< Script to call when state changes occur on servers */
|
||||
bool events[MAX_MONITOR_EVENT]; /*< enabled events */
|
||||
uint64_t events; /*< enabled events */
|
||||
} MM_MONITOR;
|
||||
|
||||
MXS_END_DECLS
|
||||
|
@ -73,7 +73,7 @@ typedef struct
|
||||
bool mysql51_replication; /**< Use MySQL 5.1 replication */
|
||||
MONITOR_SERVERS *master; /**< Master server for MySQL Master/Slave replication */
|
||||
char* script; /*< Script to call when state changes occur on servers */
|
||||
bool events[MAX_MONITOR_EVENT]; /*< enabled events */
|
||||
uint64_t events; /*< enabled events */
|
||||
HASHTABLE *server_info; /**< Contains server specific information */
|
||||
bool failover; /**< If simple failover is enabled */
|
||||
int failcount; /**< How many monitoring cycles servers must be
|
||||
|
@ -125,6 +125,19 @@ MXS_MODULE* MXS_CREATE_MODULE()
|
||||
{"multimaster", MXS_MODULE_PARAM_BOOL, "false"},
|
||||
{"failover", MXS_MODULE_PARAM_BOOL, "false"},
|
||||
{"failcount", MXS_MODULE_PARAM_COUNT, "5"},
|
||||
{
|
||||
"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}
|
||||
}
|
||||
};
|
||||
@ -229,11 +242,11 @@ static void *
|
||||
startMonitor(MONITOR *monitor, const CONFIG_PARAMETER* params)
|
||||
{
|
||||
MYSQL_MONITOR *handle = (MYSQL_MONITOR*) monitor->handle;
|
||||
bool have_events = false, script_error = false, error = false;
|
||||
|
||||
if (handle)
|
||||
{
|
||||
handle->shutdown = 0;
|
||||
MXS_FREE(handle->script);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -252,9 +265,7 @@ startMonitor(MONITOR *monitor, const CONFIG_PARAMETER* params)
|
||||
handle->server_info = server_info;
|
||||
handle->shutdown = 0;
|
||||
handle->id = config_get_gateway_id();
|
||||
handle->script = NULL;
|
||||
handle->warn_failover = true;
|
||||
memset(handle->events, false, sizeof(handle->events));
|
||||
spinlock_init(&handle->lock);
|
||||
}
|
||||
|
||||
@ -268,34 +279,10 @@ startMonitor(MONITOR *monitor, const CONFIG_PARAMETER* params)
|
||||
handle->failover = config_get_bool(params, "failover");
|
||||
handle->failcount = config_get_integer(params, "failcount");
|
||||
handle->mysql51_replication = config_get_bool(params, "mysql51_replication");
|
||||
handle->script = config_copy_string(params, "script");
|
||||
handle->events = config_get_enum(params, "events", monitor_event_enum_values);
|
||||
|
||||
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;
|
||||
}
|
||||
bool error = false;
|
||||
|
||||
if (!check_monitor_permissions(monitor, "SHOW SLAVE STATUS"))
|
||||
{
|
||||
@ -303,17 +290,6 @@ startMonitor(MONITOR *monitor, const CONFIG_PARAMETER* params)
|
||||
error = true;
|
||||
}
|
||||
|
||||
if (script_error)
|
||||
{
|
||||
MXS_ERROR("[%s] Errors were found in the script configuration parameters ", monitor->name);
|
||||
error = true;
|
||||
}
|
||||
else if (!have_events)
|
||||
{
|
||||
/** If no specific events are given, enable them all */
|
||||
memset(handle->events, true, sizeof(handle->events));
|
||||
}
|
||||
|
||||
if (!init_server_info(handle, monitor->databases))
|
||||
{
|
||||
error = true;
|
||||
@ -1330,25 +1306,11 @@ monitorMain(void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
ptr = mon->databases;
|
||||
monitor_event_t evtype;
|
||||
while (ptr)
|
||||
{
|
||||
/** Execute monitor script if a server state has changed */
|
||||
if (mon_status_changed(ptr))
|
||||
{
|
||||
evtype = mon_get_event_type(ptr);
|
||||
if (isMySQLEvent(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);
|
||||
|
||||
/* log master detection failure of first master becomes available after failure */
|
||||
if (root_master &&
|
||||
@ -1878,39 +1840,6 @@ static int add_slave_to_master(long *slaves_list, int list_size, long node_id)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static monitor_event_t mysql_events[] =
|
||||
{
|
||||
MASTER_DOWN_EVENT,
|
||||
MASTER_UP_EVENT,
|
||||
SLAVE_DOWN_EVENT,
|
||||
SLAVE_UP_EVENT,
|
||||
SERVER_DOWN_EVENT,
|
||||
SERVER_UP_EVENT,
|
||||
LOST_MASTER_EVENT,
|
||||
LOST_SLAVE_EVENT,
|
||||
NEW_MASTER_EVENT,
|
||||
NEW_SLAVE_EVENT,
|
||||
MAX_MONITOR_EVENT
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if the MySQL monitor is monitoring this event type.
|
||||
* @param event Event to check
|
||||
* @return True if the event is monitored, false if it is not
|
||||
* */
|
||||
bool isMySQLEvent(monitor_event_t event)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; mysql_events[i] != MAX_MONITOR_EVENT; i++)
|
||||
{
|
||||
if (event == mysql_events[i])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if replicate_ignore_table is defined and if maxscale_schema.replication_hearbeat
|
||||
* table is in the list.
|
||||
|
@ -77,6 +77,19 @@ MXS_MODULE* MXS_CREATE_MODULE()
|
||||
NULL, /* Thread init. */
|
||||
NULL, /* Thread finish. */
|
||||
{
|
||||
{
|
||||
"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} // No parameters
|
||||
}
|
||||
};
|
||||
@ -101,6 +114,7 @@ startMonitor(MONITOR *mon, const CONFIG_PARAMETER *params)
|
||||
if (handle != NULL)
|
||||
{
|
||||
handle->shutdown = 0;
|
||||
MXS_FREE(handle->script);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -110,39 +124,12 @@ startMonitor(MONITOR *mon, const CONFIG_PARAMETER *params)
|
||||
}
|
||||
handle->shutdown = 0;
|
||||
handle->id = MONITOR_DEFAULT_ID;
|
||||
handle->script = NULL;
|
||||
handle->master = NULL;
|
||||
memset(handle->events, false, sizeof(handle->events));
|
||||
spinlock_init(&handle->lock);
|
||||
}
|
||||
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 'Ndb_number_of_ready_data_nodes'"))
|
||||
@ -153,19 +140,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);
|
||||
@ -382,67 +356,14 @@ monitorMain(void *arg)
|
||||
ptr = ptr->next;
|
||||
}
|
||||
|
||||
ptr = mon->databases;
|
||||
monitor_event_t evtype;
|
||||
|
||||
while (ptr)
|
||||
{
|
||||
/** Execute monitor script if a server state has changed */
|
||||
if (mon_status_changed(ptr))
|
||||
{
|
||||
evtype = mon_get_event_type(ptr);
|
||||
if (isNdbEvent(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);
|
||||
release_monitor_servers(mon);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static monitor_event_t ndb_events[] =
|
||||
{
|
||||
MASTER_DOWN_EVENT,
|
||||
MASTER_UP_EVENT,
|
||||
SLAVE_DOWN_EVENT,
|
||||
SLAVE_UP_EVENT,
|
||||
SERVER_DOWN_EVENT,
|
||||
SERVER_UP_EVENT,
|
||||
NDB_UP_EVENT,
|
||||
NDB_DOWN_EVENT,
|
||||
LOST_MASTER_EVENT,
|
||||
LOST_SLAVE_EVENT,
|
||||
LOST_NDB_EVENT,
|
||||
NEW_MASTER_EVENT,
|
||||
NEW_SLAVE_EVENT,
|
||||
NEW_NDB_EVENT,
|
||||
MAX_MONITOR_EVENT
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if the event type is one the ndbcustermonitor is interested in.
|
||||
* @param event Event to check
|
||||
* @return True if the event is monitored, false if it is not
|
||||
*/
|
||||
bool isNdbEvent(monitor_event_t event)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; ndb_events[i] != MAX_MONITOR_EVENT; i++)
|
||||
{
|
||||
if (event == ndb_events[i])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user