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:
parent
b448b129d0
commit
53bf21f785
@ -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);
|
||||
|
||||
/**
|
||||
* @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
|
||||
|
@ -75,6 +75,8 @@ static MXS_MONITOR *allMonitors = NULL;
|
||||
static SPINLOCK monLock = SPINLOCK_INIT;
|
||||
|
||||
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 */
|
||||
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);
|
||||
|
||||
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)))
|
||||
{
|
||||
monitor->state = MONITOR_STATE_RUNNING;
|
||||
@ -1901,6 +1909,8 @@ static const char* process_server(MXS_MONITOR *monitor, const char *data, const
|
||||
sptr++;
|
||||
|
||||
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);
|
||||
monitor_set_pending_status(db, state);
|
||||
break;
|
||||
@ -1918,12 +1928,15 @@ 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,
|
||||
const char *end)
|
||||
{
|
||||
for (MXS_MONITOR_SERVERS* db = monitor->databases; db; db = db->next)
|
||||
if (master)
|
||||
{
|
||||
if (strcmp(db->server->unique_name, data) == 0)
|
||||
for (MXS_MONITOR_SERVERS* db = monitor->databases; db; db = db->next)
|
||||
{
|
||||
*master = db;
|
||||
break;
|
||||
if (strcmp(db->server->unique_name, data) == 0)
|
||||
{
|
||||
*master = db;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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];
|
||||
|
||||
@ -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;
|
||||
char path[PATH_MAX];
|
||||
|
@ -118,6 +118,8 @@ monitorMain(void *arg)
|
||||
return;
|
||||
}
|
||||
|
||||
load_server_journal(monitor, NULL);
|
||||
|
||||
while (!handle->shutdown)
|
||||
{
|
||||
lock_monitor_servers(monitor);
|
||||
@ -141,6 +143,7 @@ monitorMain(void *arg)
|
||||
mon_process_state_changes(monitor, handle->script, handle->events);
|
||||
|
||||
servers_status_current_to_pending(monitor);
|
||||
store_server_journal(monitor, NULL);
|
||||
release_monitor_servers(monitor);
|
||||
|
||||
/** Sleep until the next monitoring interval */
|
||||
|
@ -497,6 +497,7 @@ monitorMain(void *arg)
|
||||
return;
|
||||
}
|
||||
handle->status = MXS_MONITOR_RUNNING;
|
||||
load_server_journal(mon, NULL);
|
||||
|
||||
while (1)
|
||||
{
|
||||
@ -651,6 +652,7 @@ monitorMain(void *arg)
|
||||
update_sst_donor_nodes(mon, is_cluster);
|
||||
}
|
||||
|
||||
store_server_journal(mon, NULL);
|
||||
release_monitor_servers(mon);
|
||||
}
|
||||
}
|
||||
|
@ -514,6 +514,8 @@ monitorMain(void *arg)
|
||||
}
|
||||
|
||||
handle->status = MXS_MONITOR_RUNNING;
|
||||
load_server_journal(mon, &handle->master);
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (handle->shutdown)
|
||||
@ -616,6 +618,7 @@ monitorMain(void *arg)
|
||||
|
||||
mon_hangup_failed_servers(mon);
|
||||
servers_status_current_to_pending(mon);
|
||||
store_server_journal(mon, handle->master);
|
||||
release_monitor_servers(mon);
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +78,6 @@ typedef struct
|
||||
down before failover is initiated */
|
||||
bool allow_cluster_recovery; /**< Allow failed servers to rejoin the cluster */
|
||||
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 */
|
||||
MXS_MONITOR* monitor;
|
||||
} MYSQL_MONITOR;
|
||||
|
@ -244,7 +244,6 @@ startMonitor(MXS_MONITOR *monitor, const MXS_CONFIG_PARAMETER* params)
|
||||
handle->shutdown = 0;
|
||||
handle->id = config_get_global_options()->id;
|
||||
handle->warn_failover = true;
|
||||
handle->load_journal = true;
|
||||
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->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;
|
||||
|
||||
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.");
|
||||
return;
|
||||
}
|
||||
|
||||
handle->status = MXS_MONITOR_RUNNING;
|
||||
load_server_journal(mon, &handle->master);
|
||||
|
||||
while (1)
|
||||
{
|
||||
@ -1169,12 +1164,6 @@ monitorMain(void *arg)
|
||||
lock_monitor_servers(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 */
|
||||
ptr = mon->databases;
|
||||
|
||||
|
@ -316,7 +316,9 @@ monitorMain(void *arg)
|
||||
MXS_ERROR("Fatal : mysql_thread_init failed in monitor module. Exiting.");
|
||||
return;
|
||||
}
|
||||
|
||||
handle->status = MXS_MONITOR_RUNNING;
|
||||
load_server_journal(mon, NULL);
|
||||
|
||||
while (1)
|
||||
{
|
||||
@ -374,6 +376,7 @@ monitorMain(void *arg)
|
||||
|
||||
mon_hangup_failed_servers(mon);
|
||||
servers_status_current_to_pending(mon);
|
||||
store_server_journal(mon, NULL);
|
||||
release_monitor_servers(mon);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user