Format monitor modules

Formatted monitor modules with Astyle.
This commit is contained in:
Markus Mäkelä
2017-01-17 13:46:20 +02:00
parent c25b7629f4
commit 735674bb1b
4 changed files with 76 additions and 209 deletions

View File

@ -55,8 +55,6 @@ static MONITOR_SERVERS *set_cluster_master(MONITOR_SERVERS *, MONITOR_SERVERS *,
static void disableMasterFailback(void *, int);
bool isGaleraEvent(monitor_event_t event);
static void update_sst_donor_nodes(MONITOR*, int);
static int compare_node_index(const void*, const void*);
static int compare_node_priority(const void*, const void*);
/**
* The module entry point routine. It is this routine that
@ -616,9 +614,7 @@ static MONITOR_SERVERS *get_candidate_master(MONITOR* mon)
* This means that we can't connect to the root node of the cluster.
*
* If the node is down, the cluster would recalculate the index values
* and we would find it. In this case, we just can't connect to it.
*/
* and we would find it. In this case, we just can't connect to it. */
candidate_master = NULL;
}
@ -639,8 +635,7 @@ 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,
static MONITOR_SERVERS *set_cluster_master(MONITOR_SERVERS *current_master, MONITOR_SERVERS *candidate_master,
int master_stickiness)
{
/*
@ -692,17 +687,12 @@ static void update_sst_donor_nodes(MONITOR *mon, int is_cluster)
MONITOR_SERVERS *ptr;
MYSQL_ROW row;
MYSQL_RES *result;
GALERA_MONITOR *handle = mon->handle;
bool ignore_priority = true;
if (is_cluster == 1)
{
MXS_DEBUG("Only one server in the cluster: update_sst_donor_nodes is not performed");
return;
}
unsigned int found_slaves = 0;
MONITOR_SERVERS *node_list[is_cluster-1];
/* Donor list size = DONOR_LIST_SET_VAR + n_hosts * max_host_len + n_hosts + 1 */
char *donor_list = MXS_CALLOC(1, strlen(DONOR_LIST_SET_VAR) +
@ -719,46 +709,10 @@ static void update_sst_donor_nodes(MONITOR *mon, int is_cluster)
ptr = mon->databases;
/* Create an array of slave nodes */
while (ptr)
{
if (SERVER_IS_JOINED(ptr->server) && SERVER_IS_SLAVE(ptr->server))
{
node_list[found_slaves] = (MONITOR_SERVERS *)ptr;
found_slaves++;
/* Check the server parameter "priority"
* If no server has "priority" set, then
* the server list will be order by default method.
*/
if (handle->use_priority &&
server_get_parameter(ptr->server, "priority"))
{
ignore_priority = false;
}
}
ptr = ptr->next;
}
if (ignore_priority)
{
MXS_DEBUG("Use priority is set but no server has priority parameter. "
"Donor server list will be ordered by 'wsrep_local_index'");
}
/* Set order type */
bool sort_order = (!ignore_priority) && (int)handle->use_priority;
/* Sort the array */
qsort(node_list,
found_slaves,
sizeof(MONITOR_SERVERS *),
sort_order ? compare_node_priority : compare_node_index);
/* Select nodename from each server and append it to node_list */
for (int k = 0; k < found_slaves; k++)
{
MONITOR_SERVERS *ptr = node_list[k];
/* Get the Galera node name */
if (mysql_query(ptr->con, "SHOW VARIABLES LIKE 'wsrep_node_name'") == 0
@ -792,6 +746,9 @@ static void update_sst_donor_nodes(MONITOR *mon, int is_cluster)
}
}
ptr = ptr->next;
}
int donor_list_size = strlen(donor_list);
if (donor_list[donor_list_size - 1] == ',')
{
@ -804,9 +761,12 @@ static void update_sst_donor_nodes(MONITOR *mon, int is_cluster)
donor_list);
/* Set now rep_sst_donor in each slave node */
for (int k=0; k < found_slaves; k++)
ptr = mon->databases;
while (ptr)
{
MONITOR_SERVERS *ptr = node_list[k];
if (SERVER_IS_JOINED(ptr->server) && SERVER_IS_SLAVE(ptr->server))
{
/* Set the Galera SST donor node list */
if (mysql_query(ptr->con, donor_list) == 0)
{
@ -821,101 +781,8 @@ static void update_sst_donor_nodes(MONITOR *mon, int is_cluster)
}
}
ptr = ptr->next;
}
MXS_FREE(donor_list);
}
/**
* Compare routine for slave nodes sorted by 'wsrep_local_index'
*
* The default order is DESC.
*
* Nodes with lowest 'wsrep_local_index' value
* are at the end of the list.
*
* @param a Pointer to array value
* @param b Pointer to array value
* @return A number less than, threater than or equal to 0
*/
static int compare_node_index (const void *a, const void *b)
{
const MONITOR_SERVERS *s_a = *(MONITOR_SERVERS * const *)a;
const MONITOR_SERVERS *s_b = *(MONITOR_SERVERS * const *)b;
// Order is DESC: b - a
return s_b->server->node_id - s_a->server->node_id;
}
/**
* Compare routine for slave nodes sorted by node priority
*
* The default order is DESC.
*
* Some special cases, i.e: no give priority, or 0 value
* are handled.
*
* Note: the master selection algorithm is:
* node with lowest priority value and > 0
*
* This sorting function will add master candidates
* at the end of the list.
*
* @param a Pointer to array value
* @param b Pointer to array value
* @return A number less than, threater than or equal to 0
*/
static int compare_node_priority (const void *a, const void *b)
{
const MONITOR_SERVERS *s_a = *(MONITOR_SERVERS * const *)a;
const MONITOR_SERVERS *s_b = *(MONITOR_SERVERS * const *)b;
const char *pri_a = server_get_parameter(s_a->server, "priority");
const char *pri_b = server_get_parameter(s_b->server, "priority");
/**
* Check priority parameter:
*
* Return a - b in case of issues
*/
if (!pri_a && pri_b)
{
MXS_DEBUG("Server %s has no given priority. It will be at the beginning of the list",
s_a->server->unique_name);
return -(INT_MAX - 1);
}
else if (pri_a && !pri_b)
{
MXS_DEBUG("Server %s has no given priority. It will be at the beginning of the list",
s_b->server->unique_name);
return INT_MAX - 1;
}
else if (!pri_a && !pri_b)
{
MXS_DEBUG("Servers %s and %s have no given priority. They be at the beginning of the list",
s_a->server->unique_name,
s_b->server->unique_name);
return 0;
}
/* The given priority is valid */
int pri_val_a = atoi(pri_a);
int pri_val_b = atoi(pri_b);
/* Return a - b in case of issues */
if ((pri_val_a < INT_MAX && pri_val_a > 0) && !(pri_val_b < INT_MAX && pri_val_b > 0))
{
return pri_val_a;
}
else if (!(pri_val_a < INT_MAX && pri_val_a > 0) && (pri_val_b < INT_MAX && pri_val_b > 0))
{
return -pri_val_b;
}
else if (!(pri_val_a < INT_MAX && pri_val_a > 0) && !(pri_val_b < INT_MAX && pri_val_b > 0))
{
return 0;
}
// The order is DESC: b -a
return pri_val_b - pri_val_a;
}