MXS-1262: Use monitor journals in all monitors

All monitors now persist the state of the server in a monitor journal
file.

Moved the removal of stale journals into the core and removed them from
the monitor journal interface.
This commit is contained in:
Markus Mäkelä
2017-08-10 08:59:53 +03:00
parent b448b129d0
commit 53bf21f785
8 changed files with 32 additions and 36 deletions

View File

@ -340,20 +340,4 @@ void store_server_journal(MXS_MONITOR *monitor, MXS_MONITOR_SERVERS *master);
*/ */
void load_server_journal(MXS_MONITOR *monitor, MXS_MONITOR_SERVERS **master); void load_server_journal(MXS_MONITOR *monitor, MXS_MONITOR_SERVERS **master);
/**
* @brief Remove stored journal file
*
* @param monitor Monitor whose journal is removed
*/
void remove_server_journal(MXS_MONITOR *monitor);
/**
* @brief Check whether the journal is too old
*
* @param monitor Monitor to check
* @return True if journal is stale or an error occurred while reading the file.
* False if the file is still valid.
*/
bool journal_is_stale(MXS_MONITOR *monitor, time_t max_age);
MXS_END_DECLS MXS_END_DECLS

View File

@ -75,6 +75,8 @@ static MXS_MONITOR *allMonitors = NULL;
static SPINLOCK monLock = SPINLOCK_INIT; static SPINLOCK monLock = SPINLOCK_INIT;
static void monitor_server_free_all(MXS_MONITOR_SERVERS *servers); static void monitor_server_free_all(MXS_MONITOR_SERVERS *servers);
static void remove_server_journal(MXS_MONITOR *monitor);
static bool journal_is_stale(MXS_MONITOR *monitor, time_t max_age);
/** Server type specific bits */ /** Server type specific bits */
static unsigned int server_type_bits = SERVER_MASTER | SERVER_SLAVE | static unsigned int server_type_bits = SERVER_MASTER | SERVER_SLAVE |
@ -190,6 +192,12 @@ monitorStart(MXS_MONITOR *monitor, const MXS_CONFIG_PARAMETER* params)
{ {
spinlock_acquire(&monitor->lock); spinlock_acquire(&monitor->lock);
if (journal_is_stale(monitor, monitor->journal_max_age))
{
MXS_WARNING("Removing stale journal file for monitor '%s'.", monitor->name);
remove_server_journal(monitor);
}
if ((monitor->handle = (*monitor->module->startMonitor)(monitor, params))) if ((monitor->handle = (*monitor->module->startMonitor)(monitor, params)))
{ {
monitor->state = MONITOR_STATE_RUNNING; monitor->state = MONITOR_STATE_RUNNING;
@ -1901,6 +1909,8 @@ static const char* process_server(MXS_MONITOR *monitor, const char *data, const
sptr++; sptr++;
uint32_t state = sptr[0] | (sptr[1] << 8) | (sptr[2] << 16) | (sptr[3] << 24); uint32_t state = sptr[0] | (sptr[1] << 8) | (sptr[2] << 16) | (sptr[3] << 24);
db->mon_prev_status = state;
db->server->status_pending = state;
server_set_status_nolock(db->server, state); server_set_status_nolock(db->server, state);
monitor_set_pending_status(db, state); monitor_set_pending_status(db, state);
break; break;
@ -1918,6 +1928,8 @@ static const char* process_server(MXS_MONITOR *monitor, const char *data, const
static const char* process_master(MXS_MONITOR *monitor, MXS_MONITOR_SERVERS **master, const char *data, static const char* process_master(MXS_MONITOR *monitor, MXS_MONITOR_SERVERS **master, const char *data,
const char *end) const char *end)
{ {
if (master)
{
for (MXS_MONITOR_SERVERS* db = monitor->databases; db; db = db->next) for (MXS_MONITOR_SERVERS* db = monitor->databases; db; db = db->next)
{ {
if (strcmp(db->server->unique_name, data) == 0) if (strcmp(db->server->unique_name, data) == 0)
@ -1926,6 +1938,7 @@ static const char* process_master(MXS_MONITOR *monitor, MXS_MONITOR_SERVERS **ma
break; break;
} }
} }
}
data += strlen(data) + 1; data += strlen(data) + 1;
@ -2114,7 +2127,7 @@ void load_server_journal(MXS_MONITOR *monitor, MXS_MONITOR_SERVERS **master)
} }
} }
void remove_server_journal(MXS_MONITOR *monitor) static void remove_server_journal(MXS_MONITOR *monitor)
{ {
char path[PATH_MAX]; char path[PATH_MAX];
@ -2128,7 +2141,7 @@ void remove_server_journal(MXS_MONITOR *monitor)
} }
} }
bool journal_is_stale(MXS_MONITOR *monitor, time_t max_age) static bool journal_is_stale(MXS_MONITOR *monitor, time_t max_age)
{ {
bool is_stale = true; bool is_stale = true;
char path[PATH_MAX]; char path[PATH_MAX];

View File

@ -118,6 +118,8 @@ monitorMain(void *arg)
return; return;
} }
load_server_journal(monitor, NULL);
while (!handle->shutdown) while (!handle->shutdown)
{ {
lock_monitor_servers(monitor); lock_monitor_servers(monitor);
@ -141,6 +143,7 @@ monitorMain(void *arg)
mon_process_state_changes(monitor, handle->script, handle->events); mon_process_state_changes(monitor, handle->script, handle->events);
servers_status_current_to_pending(monitor); servers_status_current_to_pending(monitor);
store_server_journal(monitor, NULL);
release_monitor_servers(monitor); release_monitor_servers(monitor);
/** Sleep until the next monitoring interval */ /** Sleep until the next monitoring interval */

View File

@ -497,6 +497,7 @@ monitorMain(void *arg)
return; return;
} }
handle->status = MXS_MONITOR_RUNNING; handle->status = MXS_MONITOR_RUNNING;
load_server_journal(mon, NULL);
while (1) while (1)
{ {
@ -651,6 +652,7 @@ monitorMain(void *arg)
update_sst_donor_nodes(mon, is_cluster); update_sst_donor_nodes(mon, is_cluster);
} }
store_server_journal(mon, NULL);
release_monitor_servers(mon); release_monitor_servers(mon);
} }
} }

View File

@ -514,6 +514,8 @@ monitorMain(void *arg)
} }
handle->status = MXS_MONITOR_RUNNING; handle->status = MXS_MONITOR_RUNNING;
load_server_journal(mon, &handle->master);
while (1) while (1)
{ {
if (handle->shutdown) if (handle->shutdown)
@ -616,6 +618,7 @@ monitorMain(void *arg)
mon_hangup_failed_servers(mon); mon_hangup_failed_servers(mon);
servers_status_current_to_pending(mon); servers_status_current_to_pending(mon);
store_server_journal(mon, handle->master);
release_monitor_servers(mon); release_monitor_servers(mon);
} }
} }

View File

@ -78,7 +78,6 @@ typedef struct
down before failover is initiated */ down before failover is initiated */
bool allow_cluster_recovery; /**< Allow failed servers to rejoin the cluster */ bool allow_cluster_recovery; /**< Allow failed servers to rejoin the cluster */
bool warn_failover; /**< Log a warning when failover happens */ bool warn_failover; /**< Log a warning when failover happens */
bool load_journal; /**< Whether journal file should be loaded */
bool allow_external_slaves; /**< Whether to allow usage of external slave servers */ bool allow_external_slaves; /**< Whether to allow usage of external slave servers */
MXS_MONITOR* monitor; MXS_MONITOR* monitor;
} MYSQL_MONITOR; } MYSQL_MONITOR;

View File

@ -244,7 +244,6 @@ startMonitor(MXS_MONITOR *monitor, const MXS_CONFIG_PARAMETER* params)
handle->shutdown = 0; handle->shutdown = 0;
handle->id = config_get_global_options()->id; handle->id = config_get_global_options()->id;
handle->warn_failover = true; handle->warn_failover = true;
handle->load_journal = true;
handle->monitor = monitor; handle->monitor = monitor;
} }
@ -263,12 +262,6 @@ startMonitor(MXS_MONITOR *monitor, const MXS_CONFIG_PARAMETER* params)
handle->events = config_get_enum(params, "events", mxs_monitor_event_enum_values); handle->events = config_get_enum(params, "events", mxs_monitor_event_enum_values);
handle->allow_external_slaves = config_get_bool(params, "allow_external_slaves"); handle->allow_external_slaves = config_get_bool(params, "allow_external_slaves");
if (journal_is_stale(monitor, monitor->journal_max_age))
{
MXS_WARNING("Removing stale journal file.");
remove_server_journal(monitor);
}
bool error = false; bool error = false;
if (!check_monitor_permissions(monitor, "SHOW SLAVE STATUS")) if (!check_monitor_permissions(monitor, "SHOW SLAVE STATUS"))
@ -1129,7 +1122,9 @@ monitorMain(void *arg)
MXS_ERROR("mysql_thread_init failed in monitor module. Exiting."); MXS_ERROR("mysql_thread_init failed in monitor module. Exiting.");
return; return;
} }
handle->status = MXS_MONITOR_RUNNING; handle->status = MXS_MONITOR_RUNNING;
load_server_journal(mon, &handle->master);
while (1) while (1)
{ {
@ -1169,12 +1164,6 @@ monitorMain(void *arg)
lock_monitor_servers(mon); lock_monitor_servers(mon);
servers_status_pending_to_current(mon); servers_status_pending_to_current(mon);
if (handle->load_journal)
{
handle->load_journal = false;
load_server_journal(mon, &handle->master);
}
/* start from the first server in the list */ /* start from the first server in the list */
ptr = mon->databases; ptr = mon->databases;

View File

@ -316,7 +316,9 @@ monitorMain(void *arg)
MXS_ERROR("Fatal : mysql_thread_init failed in monitor module. Exiting."); MXS_ERROR("Fatal : mysql_thread_init failed in monitor module. Exiting.");
return; return;
} }
handle->status = MXS_MONITOR_RUNNING; handle->status = MXS_MONITOR_RUNNING;
load_server_journal(mon, NULL);
while (1) while (1)
{ {
@ -374,6 +376,7 @@ monitorMain(void *arg)
mon_hangup_failed_servers(mon); mon_hangup_failed_servers(mon);
servers_status_current_to_pending(mon); servers_status_current_to_pending(mon);
store_server_journal(mon, NULL);
release_monitor_servers(mon); release_monitor_servers(mon);
} }
} }