diff --git a/include/maxscale/monitor.h b/include/maxscale/monitor.h index a50b73b10..29e22b8bf 100644 --- a/include/maxscale/monitor.h +++ b/include/maxscale/monitor.h @@ -163,13 +163,14 @@ typedef enum */ typedef struct monitor_servers { - SERVER *server; /**< The server being monitored */ - MYSQL *con; /**< The MySQL connection */ + SERVER *server; /**< The server being monitored */ + MYSQL *con; /**< The MySQL connection */ bool log_version_err; int mon_err_count; unsigned int mon_prev_status; - unsigned int pending_status; /**< Pending Status flag bitmap */ - struct monitor_servers *next; /**< The next server in the list */ + unsigned int pending_status; /**< Pending Status flag bitmap */ + mxs_monitor_event_t last_event; /**< The last event that occurred on this server*/ + struct monitor_servers *next; /**< The next server in the list */ } MXS_MONITOR_SERVERS; /** diff --git a/server/core/monitor.cc b/server/core/monitor.cc index fb8966d56..fe7ebc4f8 100644 --- a/server/core/monitor.cc +++ b/server/core/monitor.cc @@ -321,6 +321,7 @@ bool monitorAddServer(MXS_MONITOR *mon, SERVER *server) db->next = NULL; db->mon_err_count = 0; db->log_version_err = true; + db->last_event = UNDEFINED_EVENT; /** Server status is uninitialized */ db->mon_prev_status = -1; /* pending status is updated by get_replication_tree */ @@ -1709,6 +1710,16 @@ void mon_process_state_changes(MXS_MONITOR *monitor, const char *script, uint64_ { mon_log_state_change(ptr); + /** + * The last executed event will be needed if a passive MaxScale is + * promoted to an active one and the last event that occurred on + * a server was a master_down event. + * + * In this case, a failover script should be called if no master_up + * or new_master events are triggered within a pre-defined time limit. + */ + ptr->last_event = mon_get_event_type(ptr); + if (script && (events & mon_get_event_type(ptr))) { monitor_launch_script(monitor, ptr, script);