From 735674bb1b17c69cfe2283247e5e62724b5d00b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Tue, 17 Jan 2017 13:46:20 +0200 Subject: [PATCH] Format monitor modules Formatted monitor modules with Astyle. --- server/modules/monitor/auroramon/auroramon.c | 14 +- server/modules/monitor/galeramon/galeramon.c | 243 ++++-------------- server/modules/monitor/mysqlmon/mysql_mon.c | 14 +- .../monitor/ndbclustermon/ndbclustermon.c | 14 +- 4 files changed, 76 insertions(+), 209 deletions(-) diff --git a/server/modules/monitor/auroramon/auroramon.c b/server/modules/monitor/auroramon/auroramon.c index cd1d5956e..4384622ca 100644 --- a/server/modules/monitor/auroramon/auroramon.c +++ b/server/modules/monitor/auroramon/auroramon.c @@ -281,16 +281,16 @@ MXS_MODULE* MXS_CREATE_MODULE() { { "script", - MXS_MODULE_PARAM_PATH, - NULL, - MXS_MODULE_OPT_PATH_X_OK + MXS_MODULE_PARAM_PATH, + NULL, + MXS_MODULE_OPT_PATH_X_OK }, { "events", - MXS_MODULE_PARAM_ENUM, - MONITOR_EVENT_DEFAULT_VALUE, - MXS_MODULE_OPT_NONE, - monitor_event_enum_values + MXS_MODULE_PARAM_ENUM, + MONITOR_EVENT_DEFAULT_VALUE, + MXS_MODULE_OPT_NONE, + monitor_event_enum_values }, {MXS_END_MODULE_PARAMS} } diff --git a/server/modules/monitor/galeramon/galeramon.c b/server/modules/monitor/galeramon/galeramon.c index 051611a8c..72b1c42be 100644 --- a/server/modules/monitor/galeramon/galeramon.c +++ b/server/modules/monitor/galeramon/galeramon.c @@ -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 @@ -97,16 +95,16 @@ MXS_MODULE* MXS_CREATE_MODULE() {"use_priority", MXS_MODULE_PARAM_BOOL, "false"}, { "script", - MXS_MODULE_PARAM_PATH, - NULL, - MXS_MODULE_OPT_PATH_X_OK + MXS_MODULE_PARAM_PATH, + NULL, + MXS_MODULE_OPT_PATH_X_OK }, { "events", - MXS_MODULE_PARAM_ENUM, - MONITOR_EVENT_DEFAULT_VALUE, - MXS_MODULE_OPT_NONE, - monitor_event_enum_values + MXS_MODULE_PARAM_ENUM, + MONITOR_EVENT_DEFAULT_VALUE, + MXS_MODULE_OPT_NONE, + monitor_event_enum_values }, {"set_donor_nodes", MXS_MODULE_PARAM_BOOL, "false"}, {MXS_END_MODULE_PARAMS} @@ -548,7 +546,7 @@ monitorMain(void *arg) */ if (handle->set_donor_nodes) { - update_sst_donor_nodes(mon, is_cluster); + update_sst_donor_nodes(mon, is_cluster); } 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. * * 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,77 +709,44 @@ 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 + /* Get the Galera node name */ + if (mysql_query(ptr->con, "SHOW VARIABLES LIKE 'wsrep_node_name'") == 0 && (result = mysql_store_result(ptr->con)) != NULL) - { - if (mysql_field_count(ptr->con) < 2) { - mysql_free_result(result); - MXS_ERROR("Unexpected result for \"SHOW VARIABLES LIKE 'wsrep_node_name'\". " + if (mysql_field_count(ptr->con) < 2) + { + mysql_free_result(result); + MXS_ERROR("Unexpected result for \"SHOW VARIABLES LIKE 'wsrep_node_name'\". " "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]", - ptr->server->unique_name, - row[1]); - - strncat(donor_list, row[1], DONOR_NODE_NAME_MAX_LEN); - strcat(donor_list, ","); + MXS_ERROR("Error while selecting 'wsrep_node_name' from node %s: %s", + ptr->server->unique_name, + mysql_error(ptr->con)); } + } - mysql_free_result(result); - } - else - { - MXS_ERROR("Error while selecting 'wsrep_node_name' from node %s: %s", - ptr->server->unique_name, - mysql_error(ptr->con)); - } + ptr = ptr->next; } 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, "\""); MXS_DEBUG("Sending %s to all slave nodes", - donor_list); + 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]; - /* Set the Galera SST donor node list */ - if (mysql_query(ptr->con, donor_list) == 0) + if (SERVER_IS_JOINED(ptr->server) && SERVER_IS_SLAVE(ptr->server)) { - MXS_DEBUG("SET GLOBAL rep_sst_donor OK in node %s", - ptr->server->unique_name); - } - else - { - MXS_ERROR("SET GLOBAL rep_sst_donor error in node %s: %s", - ptr->server->unique_name, - mysql_error(ptr->con)); + + /* 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); + } + 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); } - -/** - * 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; -} diff --git a/server/modules/monitor/mysqlmon/mysql_mon.c b/server/modules/monitor/mysqlmon/mysql_mon.c index 9f38044dd..fdb5ebcdc 100644 --- a/server/modules/monitor/mysqlmon/mysql_mon.c +++ b/server/modules/monitor/mysqlmon/mysql_mon.c @@ -129,16 +129,16 @@ MXS_MODULE* MXS_CREATE_MODULE() {"failcount", MXS_MODULE_PARAM_COUNT, "5"}, { "script", - MXS_MODULE_PARAM_PATH, - NULL, - MXS_MODULE_OPT_PATH_X_OK + MXS_MODULE_PARAM_PATH, + NULL, + MXS_MODULE_OPT_PATH_X_OK }, { "events", - MXS_MODULE_PARAM_ENUM, - MONITOR_EVENT_DEFAULT_VALUE, - MXS_MODULE_OPT_NONE, - monitor_event_enum_values + MXS_MODULE_PARAM_ENUM, + MONITOR_EVENT_DEFAULT_VALUE, + MXS_MODULE_OPT_NONE, + monitor_event_enum_values }, {MXS_END_MODULE_PARAMS} } diff --git a/server/modules/monitor/ndbclustermon/ndbclustermon.c b/server/modules/monitor/ndbclustermon/ndbclustermon.c index fa4b743a5..4eba5332f 100644 --- a/server/modules/monitor/ndbclustermon/ndbclustermon.c +++ b/server/modules/monitor/ndbclustermon/ndbclustermon.c @@ -80,16 +80,16 @@ MXS_MODULE* MXS_CREATE_MODULE() { { "script", - MXS_MODULE_PARAM_PATH, - NULL, - MXS_MODULE_OPT_PATH_X_OK + MXS_MODULE_PARAM_PATH, + NULL, + MXS_MODULE_OPT_PATH_X_OK }, { "events", - MXS_MODULE_PARAM_ENUM, - MONITOR_EVENT_DEFAULT_VALUE, - MXS_MODULE_OPT_NONE, - monitor_event_enum_values + MXS_MODULE_PARAM_ENUM, + MONITOR_EVENT_DEFAULT_VALUE, + MXS_MODULE_OPT_NONE, + monitor_event_enum_values }, {MXS_END_MODULE_PARAMS} // No parameters }