Format monitor modules
Formatted monitor modules with Astyle.
This commit is contained in:
@ -281,16 +281,16 @@ MXS_MODULE* MXS_CREATE_MODULE()
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
"script",
|
"script",
|
||||||
MXS_MODULE_PARAM_PATH,
|
MXS_MODULE_PARAM_PATH,
|
||||||
NULL,
|
NULL,
|
||||||
MXS_MODULE_OPT_PATH_X_OK
|
MXS_MODULE_OPT_PATH_X_OK
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"events",
|
"events",
|
||||||
MXS_MODULE_PARAM_ENUM,
|
MXS_MODULE_PARAM_ENUM,
|
||||||
MONITOR_EVENT_DEFAULT_VALUE,
|
MONITOR_EVENT_DEFAULT_VALUE,
|
||||||
MXS_MODULE_OPT_NONE,
|
MXS_MODULE_OPT_NONE,
|
||||||
monitor_event_enum_values
|
monitor_event_enum_values
|
||||||
},
|
},
|
||||||
{MXS_END_MODULE_PARAMS}
|
{MXS_END_MODULE_PARAMS}
|
||||||
}
|
}
|
||||||
|
@ -55,8 +55,6 @@ 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_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
|
||||||
@ -97,16 +95,16 @@ MXS_MODULE* MXS_CREATE_MODULE()
|
|||||||
{"use_priority", MXS_MODULE_PARAM_BOOL, "false"},
|
{"use_priority", MXS_MODULE_PARAM_BOOL, "false"},
|
||||||
{
|
{
|
||||||
"script",
|
"script",
|
||||||
MXS_MODULE_PARAM_PATH,
|
MXS_MODULE_PARAM_PATH,
|
||||||
NULL,
|
NULL,
|
||||||
MXS_MODULE_OPT_PATH_X_OK
|
MXS_MODULE_OPT_PATH_X_OK
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"events",
|
"events",
|
||||||
MXS_MODULE_PARAM_ENUM,
|
MXS_MODULE_PARAM_ENUM,
|
||||||
MONITOR_EVENT_DEFAULT_VALUE,
|
MONITOR_EVENT_DEFAULT_VALUE,
|
||||||
MXS_MODULE_OPT_NONE,
|
MXS_MODULE_OPT_NONE,
|
||||||
monitor_event_enum_values
|
monitor_event_enum_values
|
||||||
},
|
},
|
||||||
{"set_donor_nodes", MXS_MODULE_PARAM_BOOL, "false"},
|
{"set_donor_nodes", MXS_MODULE_PARAM_BOOL, "false"},
|
||||||
{MXS_END_MODULE_PARAMS}
|
{MXS_END_MODULE_PARAMS}
|
||||||
@ -548,7 +546,7 @@ monitorMain(void *arg)
|
|||||||
*/
|
*/
|
||||||
if (handle->set_donor_nodes)
|
if (handle->set_donor_nodes)
|
||||||
{
|
{
|
||||||
update_sst_donor_nodes(mon, is_cluster);
|
update_sst_donor_nodes(mon, is_cluster);
|
||||||
}
|
}
|
||||||
|
|
||||||
release_monitor_servers(mon);
|
release_monitor_servers(mon);
|
||||||
@ -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.
|
* 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
|
* 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;
|
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
|
* @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,
|
static MONITOR_SERVERS *set_cluster_master(MONITOR_SERVERS *current_master, MONITOR_SERVERS *candidate_master,
|
||||||
MONITOR_SERVERS *candidate_master,
|
|
||||||
int master_stickiness)
|
int master_stickiness)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@ -692,17 +687,12 @@ static void update_sst_donor_nodes(MONITOR *mon, int is_cluster)
|
|||||||
MONITOR_SERVERS *ptr;
|
MONITOR_SERVERS *ptr;
|
||||||
MYSQL_ROW row;
|
MYSQL_ROW row;
|
||||||
MYSQL_RES *result;
|
MYSQL_RES *result;
|
||||||
GALERA_MONITOR *handle = mon->handle;
|
|
||||||
bool ignore_priority = true;
|
|
||||||
|
|
||||||
if (is_cluster == 1)
|
if (is_cluster == 1)
|
||||||
{
|
{
|
||||||
MXS_DEBUG("Only one server in the cluster: update_sst_donor_nodes is not performed");
|
MXS_DEBUG("Only one server in the cluster: update_sst_donor_nodes is not performed");
|
||||||
return;
|
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 */
|
/* 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) +
|
char *donor_list = MXS_CALLOC(1, strlen(DONOR_LIST_SET_VAR) +
|
||||||
@ -719,77 +709,44 @@ static void update_sst_donor_nodes(MONITOR *mon, int is_cluster)
|
|||||||
|
|
||||||
ptr = mon->databases;
|
ptr = mon->databases;
|
||||||
|
|
||||||
/* Create an array of slave nodes */
|
|
||||||
while (ptr)
|
while (ptr)
|
||||||
{
|
{
|
||||||
if (SERVER_IS_JOINED(ptr->server) && SERVER_IS_SLAVE(ptr->server))
|
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"
|
/* Get the Galera node name */
|
||||||
* If no server has "priority" set, then
|
if (mysql_query(ptr->con, "SHOW VARIABLES LIKE 'wsrep_node_name'") == 0
|
||||||
* 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
|
|
||||||
&& (result = mysql_store_result(ptr->con)) != NULL)
|
&& (result = mysql_store_result(ptr->con)) != NULL)
|
||||||
{
|
|
||||||
if (mysql_field_count(ptr->con) < 2)
|
|
||||||
{
|
{
|
||||||
mysql_free_result(result);
|
if (mysql_field_count(ptr->con) < 2)
|
||||||
MXS_ERROR("Unexpected result for \"SHOW VARIABLES LIKE 'wsrep_node_name'\". "
|
{
|
||||||
|
mysql_free_result(result);
|
||||||
|
MXS_ERROR("Unexpected result for \"SHOW VARIABLES LIKE 'wsrep_node_name'\". "
|
||||||
"Expected 2 columns");
|
"Expected 2 columns");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((row = mysql_fetch_row(result)))
|
while ((row = mysql_fetch_row(result)))
|
||||||
|
{
|
||||||
|
MXS_DEBUG("wsrep_node_name name for %s is [%s]",
|
||||||
|
ptr->server->unique_name,
|
||||||
|
row[1]);
|
||||||
|
|
||||||
|
strncat(donor_list, row[1], DONOR_NODE_NAME_MAX_LEN);
|
||||||
|
strcat(donor_list, ",");
|
||||||
|
}
|
||||||
|
|
||||||
|
mysql_free_result(result);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
MXS_DEBUG("wsrep_node_name name for %s is [%s]",
|
MXS_ERROR("Error while selecting 'wsrep_node_name' from node %s: %s",
|
||||||
ptr->server->unique_name,
|
ptr->server->unique_name,
|
||||||
row[1]);
|
mysql_error(ptr->con));
|
||||||
|
|
||||||
strncat(donor_list, row[1], DONOR_NODE_NAME_MAX_LEN);
|
|
||||||
strcat(donor_list, ",");
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mysql_free_result(result);
|
ptr = ptr->next;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MXS_ERROR("Error while selecting 'wsrep_node_name' from node %s: %s",
|
|
||||||
ptr->server->unique_name,
|
|
||||||
mysql_error(ptr->con));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int donor_list_size = strlen(donor_list);
|
int donor_list_size = strlen(donor_list);
|
||||||
@ -801,121 +758,31 @@ static void update_sst_donor_nodes(MONITOR *mon, int is_cluster)
|
|||||||
strcat(donor_list, "\"");
|
strcat(donor_list, "\"");
|
||||||
|
|
||||||
MXS_DEBUG("Sending %s to all slave nodes",
|
MXS_DEBUG("Sending %s to all slave nodes",
|
||||||
donor_list);
|
donor_list);
|
||||||
|
|
||||||
/* Set now rep_sst_donor in each slave node */
|
/* 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)
|
|
||||||
{
|
{
|
||||||
MXS_DEBUG("SET GLOBAL rep_sst_donor OK in node %s",
|
|
||||||
ptr->server->unique_name);
|
/* Set the Galera SST donor node list */
|
||||||
}
|
if (mysql_query(ptr->con, donor_list) == 0)
|
||||||
else
|
{
|
||||||
{
|
MXS_DEBUG("SET GLOBAL rep_sst_donor OK in node %s",
|
||||||
MXS_ERROR("SET GLOBAL rep_sst_donor error in node %s: %s",
|
ptr->server->unique_name);
|
||||||
ptr->server->unique_name,
|
}
|
||||||
mysql_error(ptr->con));
|
else
|
||||||
|
{
|
||||||
|
MXS_ERROR("SET GLOBAL rep_sst_donor error in node %s: %s",
|
||||||
|
ptr->server->unique_name,
|
||||||
|
mysql_error(ptr->con));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ptr = ptr->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
MXS_FREE(donor_list);
|
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;
|
|
||||||
}
|
|
||||||
|
@ -129,16 +129,16 @@ MXS_MODULE* MXS_CREATE_MODULE()
|
|||||||
{"failcount", MXS_MODULE_PARAM_COUNT, "5"},
|
{"failcount", MXS_MODULE_PARAM_COUNT, "5"},
|
||||||
{
|
{
|
||||||
"script",
|
"script",
|
||||||
MXS_MODULE_PARAM_PATH,
|
MXS_MODULE_PARAM_PATH,
|
||||||
NULL,
|
NULL,
|
||||||
MXS_MODULE_OPT_PATH_X_OK
|
MXS_MODULE_OPT_PATH_X_OK
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"events",
|
"events",
|
||||||
MXS_MODULE_PARAM_ENUM,
|
MXS_MODULE_PARAM_ENUM,
|
||||||
MONITOR_EVENT_DEFAULT_VALUE,
|
MONITOR_EVENT_DEFAULT_VALUE,
|
||||||
MXS_MODULE_OPT_NONE,
|
MXS_MODULE_OPT_NONE,
|
||||||
monitor_event_enum_values
|
monitor_event_enum_values
|
||||||
},
|
},
|
||||||
{MXS_END_MODULE_PARAMS}
|
{MXS_END_MODULE_PARAMS}
|
||||||
}
|
}
|
||||||
|
@ -80,16 +80,16 @@ MXS_MODULE* MXS_CREATE_MODULE()
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
"script",
|
"script",
|
||||||
MXS_MODULE_PARAM_PATH,
|
MXS_MODULE_PARAM_PATH,
|
||||||
NULL,
|
NULL,
|
||||||
MXS_MODULE_OPT_PATH_X_OK
|
MXS_MODULE_OPT_PATH_X_OK
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"events",
|
"events",
|
||||||
MXS_MODULE_PARAM_ENUM,
|
MXS_MODULE_PARAM_ENUM,
|
||||||
MONITOR_EVENT_DEFAULT_VALUE,
|
MONITOR_EVENT_DEFAULT_VALUE,
|
||||||
MXS_MODULE_OPT_NONE,
|
MXS_MODULE_OPT_NONE,
|
||||||
monitor_event_enum_values
|
monitor_event_enum_values
|
||||||
},
|
},
|
||||||
{MXS_END_MODULE_PARAMS} // No parameters
|
{MXS_END_MODULE_PARAMS} // No parameters
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user