MXS-406: node comparison function is now split in two different ones

Two new routines, compare_node_index and compare_node_priority
routines, can be used by qsort depending on sort_order var
This commit is contained in:
MassimilianoPinto
2017-01-17 12:04:31 +01:00
parent 23e40dc0f8
commit f45ac341d8

View File

@ -55,7 +55,8 @@ static MONITOR_SERVERS *set_cluster_master(MONITOR_SERVERS *, MONITOR_SERVERS *,
static void disableMasterFailback(void *, int); static void disableMasterFailback(void *, int);
bool isGaleraEvent(monitor_event_t event); bool isGaleraEvent(monitor_event_t event);
static void update_sst_donor_nodes(MONITOR*, int); static void update_sst_donor_nodes(MONITOR*, int);
static int compare_cluster_node_index (const void*, const void*, void *); 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 * The module entry point routine. It is this routine that
@ -746,10 +747,13 @@ static void update_sst_donor_nodes(MONITOR *mon, int is_cluster)
} }
/* Set order type */ /* Set order type */
int sort_order = (!ignore_priority) && (int)handle->use_priority; bool sort_order = (!ignore_priority) && (int)handle->use_priority;
/* Sort the array */ /* Sort the array */
qsort_r(node_list, found_slaves, sizeof(MONITOR_SERVERS *), compare_cluster_node_index, (void *)&sort_order); 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 */ /* Select nodename from each server and append it to node_list */
for (int k = 0; k < found_slaves; k++) for (int k = 0; k < found_slaves; k++)
@ -821,7 +825,29 @@ static void update_sst_donor_nodes(MONITOR *mon, int is_cluster)
} }
/** /**
* Compare routine for slave nodes sorting * 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. * The default order is DESC.
* *
@ -829,28 +855,21 @@ static void update_sst_donor_nodes(MONITOR *mon, int is_cluster)
* are handled. * are handled.
* *
* Note: the master selection algorithm is: * Note: the master selection algorithm is:
* 1) node with lowest wsrep_local_index OR * node with lowest priority value and > 0
* 2) lowest priority value and > 0
* *
* the sorting order DESC, will add master candidates * This sorting function will add master candidates
* at the end of the list. * at the end of the list.
* *
* @param a Pointer to array value * @param a Pointer to array value
* @param b Pointer to array value * @param b Pointer to array value
* @param order Ordering by wsrep_local_index or node priority
* @return A number less than, threater than or equal to 0 * @return A number less than, threater than or equal to 0
*/ */
static int compare_cluster_node_index (const void *a, const void *b, void *order) static int compare_node_priority (const void *a, const void *b)
{ {
const MONITOR_SERVERS *s_a = *(MONITOR_SERVERS * const *)a; const MONITOR_SERVERS *s_a = *(MONITOR_SERVERS * const *)a;
const MONITOR_SERVERS *s_b = *(MONITOR_SERVERS * const *)b; const MONITOR_SERVERS *s_b = *(MONITOR_SERVERS * const *)b;
int list_order = *(int *)order;
if (list_order)
{
const char *pri_a = server_get_parameter(s_a->server, "priority"); const char *pri_a = server_get_parameter(s_a->server, "priority");
const char *pri_b = server_get_parameter(s_b->server, "priority"); const char *pri_b = server_get_parameter(s_b->server, "priority");
@ -900,9 +919,3 @@ static int compare_cluster_node_index (const void *a, const void *b, void *order
// The order is DESC: b -a // The order is DESC: b -a
return pri_val_b - pri_val_a; return pri_val_b - pri_val_a;
} }
else
{
// Order is DESC: b - a
return s_b->server->node_id - s_a->server->node_id;
}
}