Fixed a possible bug with multiple monitors monitoring the same servers.

This commit is contained in:
Markus Makela
2015-05-19 15:42:11 +03:00
parent 1403b3dfeb
commit c4f51c0b8c
4 changed files with 177 additions and 30 deletions

View File

@ -52,6 +52,7 @@ MODULE_INFO info = {
static void *startMonitor(void *,void*);
static void stopMonitor(void *);
static void diagnostics(DCB *, void *);
bool isNdbEvent(monitor_event_t event);
static MONITOR_OBJECT MyObject = {
startMonitor,
@ -402,18 +403,57 @@ size_t nrounds = 0;
while(ptr)
{
/** Execute monitor script if a server state has changed */
if(mon_status_changed(ptr) && (evtype = mon_get_event_type(ptr)) != UNDEFINED_MONITOR_EVENT)
if(mon_status_changed(ptr))
{
skygw_log_write(LOGFILE_TRACE,"Server changed state: %s[%s:%u]: %s",
ptr->server->unique_name,
ptr->server->name,ptr->server->port,
mon_get_event_name(ptr));
if(handle->script && handle->events[evtype])
evtype = mon_get_event_type(ptr);
if(isNdbEvent(evtype))
{
monitor_launch_script(mon,ptr,handle->script);
skygw_log_write(LOGFILE_TRACE,"Server changed state: %s[%s:%u]: %s",
ptr->server->unique_name,
ptr->server->name,ptr->server->port,
mon_get_event_name(ptr));
if(handle->script && handle->events[evtype])
{
monitor_launch_script(mon,ptr,handle->script);
}
}
}
ptr = ptr->next;
}
}
}
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;
}