From 32f9f727d0e503b8cce17f984f4f798fdbe1a8a2 Mon Sep 17 00:00:00 2001 From: Rahim Kanji Date: Thu, 6 Apr 2023 12:37:25 +0500 Subject: [PATCH] Fixed code styling --- lib/MySQL_HostGroups_Manager.cpp | 39 +++++++++++--------------------- lib/ProxySQL_Cluster.cpp | 35 ++++++++++------------------ 2 files changed, 25 insertions(+), 49 deletions(-) diff --git a/lib/MySQL_HostGroups_Manager.cpp b/lib/MySQL_HostGroups_Manager.cpp index 8f7a28e53..50f39ff46 100644 --- a/lib/MySQL_HostGroups_Manager.cpp +++ b/lib/MySQL_HostGroups_Manager.cpp @@ -1519,8 +1519,7 @@ void MySQL_HostGroups_Manager::update_runtime_mysql_servers_table(SQLite3_result mydb->execute_statement(query, &error, &cols, &affected_rows, &resultset); if (error) { proxy_error("Error on %s : %s\n", query, error); - } - else { + } else { if (GloMTH->variables.hostgroup_manager_verbose) { proxy_info("Dumping mysql_servers LEFT JOIN mysql_servers_incoming\n"); resultset->dump_to_stderr(); @@ -1550,8 +1549,7 @@ void MySQL_HostGroups_Manager::update_runtime_mysql_servers_table(SQLite3_result mydb->execute_statement(query, &error, &cols, &affected_rows, &resultset); if (error) { proxy_error("Error on %s : %s\n", query, error); - } - else { + } else { if (GloMTH->variables.hostgroup_manager_verbose) { proxy_info("Dumping mysql_servers JOIN mysql_servers_incoming\n"); @@ -1596,8 +1594,7 @@ void MySQL_HostGroups_Manager::update_runtime_mysql_servers_table(SQLite3_result proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL, 6, "Server %u:%s:%d has gtid_port enabled, setting use_gitd=true if not already set\n", mysrvc->myhgc->hid, mysrvc->address, mysrvc->port); use_gtid = true; } - } - else { + } else { bool run_update = false; MySrvC* mysrvc = (MySrvC*)ptr; // carefully increase the 2nd index by 1 for every new column added @@ -1688,8 +1685,7 @@ void MySQL_HostGroups_Manager::update_runtime_mysql_servers_table(SQLite3_result } if (use_gtid) { has_gtid_port = true; - } - else { + } else { has_gtid_port = false; } if (resultset) { delete resultset; resultset = NULL; } @@ -1717,8 +1713,7 @@ void MySQL_HostGroups_Manager::update_runtime_mysql_servers_table(SQLite3_result if (peer_runtime_mysql_server.epoch != 0 && peer_runtime_mysql_server.checksum.empty() == false && GloVars.checksums_values.mysql_servers.checksum == peer_runtime_mysql_server.checksum) { GloVars.checksums_values.mysql_servers.epoch = peer_runtime_mysql_server.epoch; - } - else { + } else { GloVars.checksums_values.mysql_servers.epoch = t; } @@ -1888,8 +1883,7 @@ void MySQL_HostGroups_Manager::update_hostgroup_manager_mappings() { std::unique_ptr server_mapping(new HostGroup_Server_Mapping(this)); fetched_server_mapping = server_mapping.get(); hostgroup_server_mapping.insert({ server_id, std::move(server_mapping) }); - } - else { + } else { fetched_server_mapping = itr->second.get(); } @@ -2190,8 +2184,7 @@ bool MySQL_HostGroups_Manager::commit( if (peer_runtime_mysql_server.epoch != 0 && peer_runtime_mysql_server.checksum.empty() == false && GloVars.checksums_values.mysql_servers.checksum == peer_runtime_mysql_server.checksum) { GloVars.checksums_values.mysql_servers.epoch = peer_runtime_mysql_server.epoch; - } - else { + } else { GloVars.checksums_values.mysql_servers.epoch = t; } @@ -2203,8 +2196,7 @@ bool MySQL_HostGroups_Manager::commit( if (peer_mysql_server_incoming.epoch != 0 && peer_mysql_server_incoming.checksum.empty() == false && GloVars.checksums_values.mysql_servers_incoming.checksum == peer_mysql_server_incoming.checksum) { GloVars.checksums_values.mysql_servers_incoming.epoch = peer_mysql_server_incoming.epoch; - } - else { + } else { GloVars.checksums_values.mysql_servers_incoming.epoch = t; } @@ -2275,8 +2267,7 @@ uint64_t MySQL_HostGroups_Manager::get_mysql_servers_checksum(SQLite3_result* ru if (strcasecmp(row->fields[4], "OFFLINE_HARD") == 0) { rm_rows_count += 1; return true; - } - else { + } else { return false; } }; @@ -2287,8 +2278,7 @@ uint64_t MySQL_HostGroups_Manager::get_mysql_servers_checksum(SQLite3_result* ru resultset->rows_count = init_row_count - rm_rows_count; save_runtime_mysql_servers(resultset); - } - else { + } else { save_runtime_mysql_servers(runtime_mysql_servers); } @@ -2330,8 +2320,7 @@ uint64_t MySQL_HostGroups_Manager::get_mysql_servers_incoming_checksum(SQLite3_r if (strcasecmp(row->fields[4], "OFFLINE_HARD") == 0) { rm_rows_count += 1; return true; - } - else { + } else { return false; } }; @@ -2343,8 +2332,7 @@ uint64_t MySQL_HostGroups_Manager::get_mysql_servers_incoming_checksum(SQLite3_r save_mysql_servers_incoming(resultset); } - } - else { + } else { proxy_info("Checksum for table %s is 0x%lX\n", "mysql_servers_incoming", (long unsigned int)0); } } else { @@ -2387,8 +2375,7 @@ uint64_t MySQL_HostGroups_Manager::get_mysql_servers_incoming_checksum(SQLite3_r if (strcasecmp(status, "ONLINE") == 0 || strcasecmp(status, "SHUNNED") == 0) { status_conv = "0"; - } - else if (strcasecmp(status, "OFFLINE_SOFT") == 0) { + } else if (strcasecmp(status, "OFFLINE_SOFT") == 0) { status_conv = "2"; } } diff --git a/lib/ProxySQL_Cluster.cpp b/lib/ProxySQL_Cluster.cpp index c73f38821..292e8f6fa 100644 --- a/lib/ProxySQL_Cluster.cpp +++ b/lib/ProxySQL_Cluster.cpp @@ -350,8 +350,7 @@ ProxySQL_Node_Entry::ProxySQL_Node_Entry(char* _hostname, uint16_t _port, uint64 weight = _weight; if (_comment == NULL) { comment = strdup((char*)""); - } - else { + } else { comment = strdup(_comment); } @@ -522,8 +521,7 @@ void ProxySQL_Node_Entry::set_checksums(MYSQL_RES *_r) { proxy_debug(PROXY_DEBUG_CLUSTER, 5, "Checksum for mysql_servers_incoming from peer %s:%d matches with local checksum %s, we won't sync.\n", hostname, port, GloVars.checksums_values.mysql_servers_incoming.checksum); proxy_info("Cluster: checksum for mysql_servers_incoming from peer %s:%d matches with local checksum %s, we won't sync.\n", hostname, port, GloVars.checksums_values.mysql_servers_incoming.checksum); } - } - else { + } else { checksums_values.mysql_servers_incoming.diff_check++; proxy_debug(PROXY_DEBUG_CLUSTER, 5, "Checksum for mysql_servers_incoming from peer %s:%d, version %llu, epoch %llu, checksum %s is different from local checksum %s. Incremented diff_check %d ...\n", hostname, port, checksums_values.mysql_servers_incoming.version, checksums_values.mysql_servers_incoming.epoch, checksums_values.mysql_servers_incoming.checksum, GloVars.checksums_values.mysql_servers_incoming.checksum, checksums_values.mysql_servers_incoming.diff_check); @@ -783,8 +781,7 @@ void ProxySQL_Node_Entry::set_checksums(MYSQL_RES *_r) { proxy_error("Cluster: detected a peer %s:%d with mysql_servers_incoming version %llu, epoch %llu, diff_check %u, checksum %s. Own version: %llu, epoch: %llu, checksum %s. Sync conflict, epoch times are EQUAL, can't determine which server holds the latest config, we won't sync. This message will be repeated every %u checks until LOAD MYSQL SERVERS TO RUNTIME is executed on candidate master.\n", hostname, port, v->version, v->epoch, v->diff_check, v->checksum, own_version, own_epoch, own_checksum, (diff_ms * 10)); GloProxyCluster->metrics.p_counter_array[p_cluster_counter::sync_conflict_mysql_servers_share_epoch]->Increment(); } - } - else { + } else { if (v->diff_check && (v->diff_check % (diff_ms * 10)) == 0) { proxy_debug(PROXY_DEBUG_CLUSTER, 5, "Detected peer %s:%d with mysql_servers version %llu, epoch %llu, diff_check %u. Own version: %llu, epoch: %llu. diff_check is increasing, but version 1 doesn't allow sync. This message will be repeated every %u checks until LOAD MYSQL SERVERS TO RUNTIME is executed on candidate master.\n", hostname, port, v->version, v->epoch, v->diff_check, own_version, own_epoch, (diff_ms * 10)); proxy_warning("Cluster: detected a peer %s:%d with mysql_servers version %llu, epoch %llu, diff_check %u. Own version: %llu, epoch: %llu. diff_check is increasing, but version 1 doesn't allow sync. This message will be repeated every %u checks until LOAD MYSQL SERVERS TO RUNTIME is executed on candidate master.\n", hostname, port, v->version, v->epoch, v->diff_check, own_version, own_epoch, (diff_ms * 10)); @@ -818,8 +815,7 @@ void ProxySQL_Node_Entry::set_checksums(MYSQL_RES *_r) { proxy_error("Cluster: detected a peer %s:%d with mysql_servers version %llu, epoch %llu, diff_check %u, checksum %s. Own version: %llu, epoch: %llu, checksum %s. Sync conflict, epoch times are EQUAL, can't determine which server holds the latest config, we won't sync. This message will be repeated every %u checks until LOAD MYSQL SERVERS TO RUNTIME is executed on candidate master.\n", hostname, port, v->version, v->epoch, v->diff_check, v->checksum, own_version, own_epoch, own_checksum, (diff_ms * 10)); GloProxyCluster->metrics.p_counter_array[p_cluster_counter::sync_conflict_mysql_servers_share_epoch]->Increment(); } - } - else { + } else { if (v->diff_check && (v->diff_check % (diff_ms * 10)) == 0) { proxy_debug(PROXY_DEBUG_CLUSTER, 5, "Detected peer %s:%d with mysql_servers version %llu, epoch %llu, diff_check %u. Own version: %llu, epoch: %llu. diff_check is increasing, but version 1 doesn't allow sync. This message will be repeated every %u checks until LOAD MYSQL SERVERS TO RUNTIME is executed on candidate master.\n", hostname, port, v->version, v->epoch, v->diff_check, own_version, own_epoch, (diff_ms * 10)); proxy_warning("Cluster: detected a peer %s:%d with mysql_servers version %llu, epoch %llu, diff_check %u. Own version: %llu, epoch: %llu. diff_check is increasing, but version 1 doesn't allow sync. This message will be repeated every %u checks until LOAD MYSQL SERVERS TO RUNTIME is executed on candidate master.\n", hostname, port, v->version, v->epoch, v->diff_check, own_version, own_epoch, (diff_ms * 10)); @@ -1905,8 +1901,7 @@ void ProxySQL_Cluster::pull_mysql_servers_incoming_from_peer(const mysql_servers if (it_err == 0) { results[i] = fetch_res; - } - else { + } else { fetching_error = true; break; } @@ -1931,7 +1926,7 @@ void ProxySQL_Cluster::pull_mysql_servers_incoming_from_peer(const mysql_servers MYSQL_RES* fetch_res = nullptr; if (fetch_and_store(conn, query, &fetch_res) == 0) { results[6] = fetch_res; - }else { + } else { fetching_error = true; } } @@ -2033,8 +2028,7 @@ void ProxySQL_Cluster::pull_mysql_servers_incoming_from_peer(const mysql_servers if (o != row[8]) { free(o); } - } - else { + } else { // In case of comment being null, placeholder must not have '' fqs += "VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)"; o = const_cast("NULL"); @@ -2077,8 +2071,7 @@ void ProxySQL_Cluster::pull_mysql_servers_incoming_from_peer(const mysql_servers if (o != row[8]) { free(o); } - } - else { + } else { // In case of comment being null, placeholder must not have '' fqs += "VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)"; o = const_cast("NULL"); @@ -2121,8 +2114,7 @@ void ProxySQL_Cluster::pull_mysql_servers_incoming_from_peer(const mysql_servers if (o != row[13]) { free(o); } - } - else { + } else { // In case of comment being null, placeholder must not have '' fqs += "VALUES (%s, %s, %s, %s, '%s', %s, %s, %s, %s, %s, %s, %s, %s, %s)"; o = const_cast("NULL"); @@ -2185,14 +2177,12 @@ void ProxySQL_Cluster::pull_mysql_servers_incoming_from_peer(const mysql_servers proxy_debug(PROXY_DEBUG_CLUSTER, 5, "Saving to disk MySQL Servers Incoming from peer %s:%d\n", hostname, port); proxy_info("Cluster: Saving to disk MySQL Servers Incoming from peer %s:%d\n", hostname, port); GloAdmin->flush_GENERIC__from_to("mysql_servers", "memory_to_disk"); - } - else { + } else { proxy_debug(PROXY_DEBUG_CLUSTER, 5, "Not saving to disk MySQL Servers from peer %s:%d failed.\n", hostname, port); proxy_info("Cluster: Not saving to disk MySQL Servers from peer %s:%d failed.\n", hostname, port); } GloAdmin->mysql_servers_wrunlock(); - } - else { + } else { proxy_debug(PROXY_DEBUG_CLUSTER, 5, "Fetching MySQL Servers from peer %s:%d failed: Checksum changed from %s to %s\n", hostname, port, peer_mysql_servers_incoming_checksum, computed_checksum.c_str()); proxy_info( @@ -2209,8 +2199,7 @@ void ProxySQL_Cluster::pull_mysql_servers_incoming_from_peer(const mysql_servers metrics.p_counter_array[p_cluster_counter::pulled_mysql_servers_success]->Increment(); } - } - else { + } else { proxy_debug(PROXY_DEBUG_CLUSTER, 5, "Fetching MySQL Servers from peer %s:%d failed: %s\n", hostname, port, mysql_error(conn)); proxy_info("Cluster: Fetching MySQL Servers from peer %s:%d failed: %s\n", hostname, port, mysql_error(conn)); metrics.p_counter_array[p_cluster_counter::pulled_mysql_servers_failure]->Increment();