Remove use of timestamps in failover code

Using timestamps to detect whether MaxScale was active or passive can
cause problems if multiple events happen at the same time. This can be
avoided by separating events into actively observed and passively observed
events. This clarifies the logic by removing the ambiguity of timestamps.

As the monitoring threads are separate from the worker threads, it is
prudent to use atomic operations to modify and read the state of the
MaxScale. This will impose an happens-before relation between MaxScale
being set into passive mode and events being classified as being passively
observed.
This commit is contained in:
Markus Mäkelä
2017-10-27 10:26:10 +03:00
parent 37e64bad90
commit 2d1e5f46fa
6 changed files with 29 additions and 39 deletions

View File

@ -1755,16 +1755,17 @@ void mon_process_state_changes(MXS_MONITOR *monitor, const char *script, uint64_
mxs_monitor_event_t event = mon_get_event_type(ptr);
ptr->server->last_event = event;
ptr->server->triggered_at = hkheartbeat;
ptr->server->active_event = !atomic_load_int32(&config_get_global_options()->passive);
ptr->new_event = true;
mon_log_state_change(ptr);
if (event == MASTER_DOWN_EVENT)
{
monitor->last_master_down = hkheartbeat;
monitor->master_has_failed = true;
}
else if (event == MASTER_UP_EVENT || event == NEW_MASTER_EVENT)
{
monitor->last_master_up = hkheartbeat;
monitor->master_has_failed = false;
}
if (script && (events & event))