Galeramon formatting changes
Fixed indentation, bracket alignment and other minor things.
This commit is contained in:
@ -87,8 +87,7 @@ version()
|
||||
void
|
||||
ModuleInit()
|
||||
{
|
||||
LOGIF(LM, (skygw_log_write(
|
||||
LOGFILE_MESSAGE,
|
||||
LOGIF(LM, (skygw_log_write(LOGFILE_MESSAGE,
|
||||
"Initialise the MySQL Galera Monitor module %s.\n",
|
||||
version_str)));
|
||||
}
|
||||
@ -128,7 +127,9 @@ startMonitor(void *arg,void* opt)
|
||||
else
|
||||
{
|
||||
if ((handle = (GALERA_MONITOR *) malloc(sizeof(GALERA_MONITOR))) == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
handle->shutdown = 0;
|
||||
handle->id = MONITOR_DEFAULT_ID;
|
||||
handle->disableMasterFailback = 0;
|
||||
@ -145,13 +146,21 @@ startMonitor(void *arg,void* opt)
|
||||
while (params)
|
||||
{
|
||||
if (!strcmp(params->name, "disable_master_failback"))
|
||||
{
|
||||
handle->disableMasterFailback = config_truth_value(params->value);
|
||||
}
|
||||
else if (!strcmp(params->name, "available_when_donor"))
|
||||
{
|
||||
handle->availableWhenDonor = config_truth_value(params->value);
|
||||
}
|
||||
else if (!strcmp(params->name, "disable_master_role_setting"))
|
||||
{
|
||||
handle->disableMasterRoleSetting = config_truth_value(params->value);
|
||||
}
|
||||
else if (!strcmp(params->name, "use_priority"))
|
||||
{
|
||||
handle->use_priority = config_truth_value(params->value);
|
||||
}
|
||||
else if (!strcmp(params->name, "script"))
|
||||
{
|
||||
if (externcmd_can_execute(params->value))
|
||||
@ -166,11 +175,16 @@ startMonitor(void *arg,void* opt)
|
||||
}
|
||||
else if (!strcmp(params->name, "events"))
|
||||
{
|
||||
if(mon_parse_event_string((bool*)&handle->events,sizeof(handle->events),params->value) != 0)
|
||||
if (mon_parse_event_string((bool*) & handle->events,
|
||||
sizeof(handle->events), params->value) != 0)
|
||||
{
|
||||
script_error = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
have_events = true;
|
||||
}
|
||||
}
|
||||
params = params->next;
|
||||
}
|
||||
if (script_error)
|
||||
@ -333,7 +347,8 @@ char *server_string;
|
||||
isjoined = 1;
|
||||
|
||||
/* Check if the node is a donor and is using xtrabackup, in this case it can stay alive */
|
||||
else if (strcmp(row[1], "2") == 0 && handle->availableWhenDonor == 1) {
|
||||
else if (strcmp(row[1], "2") == 0 && handle->availableWhenDonor == 1)
|
||||
{
|
||||
if (mysql_query(database->con, "SHOW VARIABLES LIKE 'wsrep_sst_method'") == 0
|
||||
&& (result2 = mysql_store_result(database->con)) != NULL)
|
||||
{
|
||||
@ -385,10 +400,14 @@ char *server_string;
|
||||
}
|
||||
|
||||
if (isjoined)
|
||||
{
|
||||
server_set_status(database->server, SERVER_JOINED);
|
||||
}
|
||||
else
|
||||
{
|
||||
server_clear_status(database->server, SERVER_JOINED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The entry point for the monitoring module thread
|
||||
@ -414,8 +433,7 @@ monitor_event_t evtype;
|
||||
master_stickiness = handle->disableMasterFailback;
|
||||
if (mysql_thread_init())
|
||||
{
|
||||
LOGIF(LE, (skygw_log_write_flush(
|
||||
LOGFILE_ERROR,
|
||||
LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,
|
||||
"Fatal : mysql_thread_init failed in monitor "
|
||||
"module. Exiting.\n")));
|
||||
return;
|
||||
@ -460,7 +478,8 @@ monitor_event_t evtype;
|
||||
monitorDatabase(mon, ptr);
|
||||
|
||||
/* clear bits for non member nodes */
|
||||
if ( ! SERVER_IN_MAINT(ptr->server) && (! SERVER_IS_JOINED(ptr->server))) {
|
||||
if (!SERVER_IN_MAINT(ptr->server) && (!SERVER_IS_JOINED(ptr->server)))
|
||||
{
|
||||
ptr->server->depth = -1;
|
||||
|
||||
/* clear M/S status */
|
||||
@ -474,8 +493,7 @@ monitor_event_t evtype;
|
||||
/* Log server status change */
|
||||
if (mon_status_changed(ptr))
|
||||
{
|
||||
LOGIF(LD, (skygw_log_write_flush(
|
||||
LOGFILE_DEBUG,
|
||||
LOGIF(LD, (skygw_log_write_flush(LOGFILE_DEBUG,
|
||||
"Backend server %s:%d state : %s",
|
||||
ptr->server->name,
|
||||
ptr->server->port,
|
||||
@ -515,38 +533,49 @@ monitor_event_t evtype;
|
||||
candidate_master = get_candidate_master(mon);
|
||||
|
||||
/* Select the master, based on master_stickiness */
|
||||
if (1 == handle->disableMasterRoleSetting) {
|
||||
if (1 == handle->disableMasterRoleSetting)
|
||||
{
|
||||
handle->master = NULL;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
handle->master = set_cluster_master(handle->master, candidate_master, master_stickiness);
|
||||
}
|
||||
|
||||
ptr = mon->databases;
|
||||
|
||||
while (ptr) {
|
||||
if (!SERVER_IS_JOINED(ptr->server) || SERVER_IN_MAINT(ptr->server)) {
|
||||
while (ptr)
|
||||
{
|
||||
if (!SERVER_IS_JOINED(ptr->server) || SERVER_IN_MAINT(ptr->server))
|
||||
{
|
||||
ptr = ptr->next;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (handle->master) {
|
||||
if (ptr != handle->master) {
|
||||
if (handle->master)
|
||||
{
|
||||
if (ptr != handle->master)
|
||||
{
|
||||
/* set the Slave role */
|
||||
server_set_status(ptr->server, SERVER_SLAVE);
|
||||
server_clear_status(ptr->server, SERVER_MASTER);
|
||||
|
||||
/* clear master stickiness */
|
||||
server_clear_status(ptr->server, SERVER_MASTER_STICKINESS);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* set the Master role */
|
||||
server_set_status(handle->master->server, SERVER_MASTER);
|
||||
server_clear_status(handle->master->server, SERVER_SLAVE);
|
||||
|
||||
if (candidate_master && handle->master->server->node_id != candidate_master->server->node_id) {
|
||||
if (candidate_master && handle->master->server->node_id != candidate_master->server->node_id)
|
||||
{
|
||||
/* set master stickiness */
|
||||
server_set_status(handle->master->server, SERVER_MASTER_STICKINESS);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* clear master stickiness */
|
||||
server_clear_status(ptr->server, SERVER_MASTER_STICKINESS);
|
||||
}
|
||||
@ -558,15 +587,17 @@ monitor_event_t evtype;
|
||||
ptr = ptr->next;
|
||||
}
|
||||
|
||||
if (is_cluster == 0 && log_no_members) {
|
||||
LOGIF(LE, (skygw_log_write_flush(
|
||||
LOGFILE_ERROR,
|
||||
if (is_cluster == 0 && log_no_members)
|
||||
{
|
||||
LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,
|
||||
"Error: there are no cluster members")));
|
||||
log_no_members = 0;
|
||||
} else {
|
||||
if (is_cluster > 0 && log_no_members == 0) {
|
||||
LOGIF(LE, (skygw_log_write_flush(
|
||||
LOGFILE_ERROR,
|
||||
}
|
||||
else
|
||||
{
|
||||
if (is_cluster > 0 && log_no_members == 0)
|
||||
{
|
||||
LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,
|
||||
"Info: found cluster members")));
|
||||
log_no_members = 1;
|
||||
}
|
||||
@ -608,7 +639,8 @@ monitor_event_t evtype;
|
||||
* @param servers The monitored servers list
|
||||
* @return The candidate master on success, NULL on failure
|
||||
*/
|
||||
static MONITOR_SERVERS *get_candidate_master(MONITOR* mon) {
|
||||
static MONITOR_SERVERS *get_candidate_master(MONITOR* mon)
|
||||
{
|
||||
MONITOR_SERVERS *moitor_servers = mon->databases;
|
||||
MONITOR_SERVERS *candidate_master = NULL;
|
||||
GALERA_MONITOR* handle = mon->handle;
|
||||
@ -617,8 +649,10 @@ static MONITOR_SERVERS *get_candidate_master(MONITOR* mon) {
|
||||
int currval;
|
||||
char* value;
|
||||
/* set min_id to the lowest value of moitor_servers->server->node_id */
|
||||
while(moitor_servers) {
|
||||
if (!SERVER_IN_MAINT(moitor_servers->server) && SERVER_IS_JOINED(moitor_servers->server)) {
|
||||
while (moitor_servers)
|
||||
{
|
||||
if (!SERVER_IN_MAINT(moitor_servers->server) && SERVER_IS_JOINED(moitor_servers->server))
|
||||
{
|
||||
|
||||
moitor_servers->server->depth = 0;
|
||||
|
||||
@ -636,7 +670,8 @@ static MONITOR_SERVERS *get_candidate_master(MONITOR* mon) {
|
||||
candidate_master == NULL || /** No candidate chosen */
|
||||
serverGetParameter(candidate_master->server, "priority") == NULL)) /** Candidate has no priority */
|
||||
{
|
||||
if (min_id < 0 || moitor_servers->server->node_id < min_id) {
|
||||
if (min_id < 0 || moitor_servers->server->node_id < min_id)
|
||||
{
|
||||
min_id = moitor_servers->server->node_id;
|
||||
candidate_master = moitor_servers;
|
||||
}
|
||||
@ -647,6 +682,7 @@ static MONITOR_SERVERS *get_candidate_master(MONITOR* mon) {
|
||||
|
||||
return candidate_master;
|
||||
}
|
||||
|
||||
/**
|
||||
* set the master server in the cluster
|
||||
*
|
||||
@ -661,24 +697,32 @@ static MONITOR_SERVERS *get_candidate_master(MONITOR* mon) {
|
||||
* @param candidate_master The candidate master server accordingly to the selection rule
|
||||
* @return The master node pointer (could be NULL)
|
||||
*/
|
||||
static MONITOR_SERVERS *set_cluster_master(MONITOR_SERVERS *current_master, MONITOR_SERVERS *candidate_master, int master_stickiness) {
|
||||
static MONITOR_SERVERS *set_cluster_master(MONITOR_SERVERS *current_master, MONITOR_SERVERS *candidate_master, int master_stickiness)
|
||||
{
|
||||
/*
|
||||
* if current master is not set or master_stickiness is not enable
|
||||
* just return candidate_master.
|
||||
*/
|
||||
if (current_master == NULL || master_stickiness == 0) {
|
||||
if (current_master == NULL || master_stickiness == 0)
|
||||
{
|
||||
return candidate_master;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* if current_master is still a cluster member use it
|
||||
*
|
||||
*/
|
||||
if (SERVER_IS_JOINED(current_master->server) && (! SERVER_IN_MAINT(current_master->server))) {
|
||||
if (SERVER_IS_JOINED(current_master->server) && (!SERVER_IN_MAINT(current_master->server)))
|
||||
{
|
||||
return current_master;
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
return candidate_master;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable/Enable the Master failback in a Galera Cluster.
|
||||
@ -735,6 +779,7 @@ static monitor_event_t galera_events[] = {
|
||||
NEW_DONOR_EVENT,
|
||||
MAX_MONITOR_EVENT
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if the Galera monitor is monitoring this event type.
|
||||
* @param event Event to check
|
||||
@ -746,7 +791,9 @@ bool isGaleraEvent(monitor_event_t event)
|
||||
for (i = 0; galera_events[i] != MAX_MONITOR_EVENT; i++)
|
||||
{
|
||||
if (event == galera_events[i])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user