Galeramon formatting changes

Fixed indentation, bracket alignment and other minor things.
This commit is contained in:
Markus Makela
2015-11-16 13:29:12 +02:00
parent f3a4bedbf5
commit 6dea82631d

View File

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