From d61d989249591a9837ffca53c7b1efe56bb8278b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Tue, 28 Mar 2023 14:37:03 +0200 Subject: [PATCH] Deprecate 'admin-checksum_*' variables Checksums are now always computed for each module. Enabling/Disabling modules synchronization for Cluster is now only dependent of 'cluster_*_diffs_before_sync' variables. --- lib/MySQL_HostGroups_Manager.cpp | 4 +- lib/ProxySQL_Admin.cpp | 90 +++++++---- lib/ProxySQL_Cluster.cpp | 246 ++++++++++++++++--------------- 3 files changed, 191 insertions(+), 149 deletions(-) diff --git a/lib/MySQL_HostGroups_Manager.cpp b/lib/MySQL_HostGroups_Manager.cpp index 09e86503d..fdaaf21af 100644 --- a/lib/MySQL_HostGroups_Manager.cpp +++ b/lib/MySQL_HostGroups_Manager.cpp @@ -1857,8 +1857,8 @@ bool MySQL_HostGroups_Manager::commit( generate_mysql_hostgroup_attributes_table(); } - - if ( GloAdmin && GloAdmin->checksum_variables.checksum_mysql_servers ) { + // Checksums are always generated - 'admin-checksum_*' deprecated + { uint64_t hash1=0, hash2=0; SpookyHash myhash; char buf[80]; diff --git a/lib/ProxySQL_Admin.cpp b/lib/ProxySQL_Admin.cpp index eb5e65d02..fac8edc82 100644 --- a/lib/ProxySQL_Admin.cpp +++ b/lib/ProxySQL_Admin.cpp @@ -6558,7 +6558,9 @@ void ProxySQL_Admin::flush_admin_variables___database_to_runtime( } } //commit(); NOT IMPLEMENTED - if (checksum_variables.checksum_admin_variables) { + + // Checksums are always generated - 'admin-checksum_*' deprecated + { pthread_mutex_lock(&GloVars.checksum_mutex); // generate checksum for cluster flush_admin_variables___runtime_to_database(admindb, false, false, false, true); @@ -6905,7 +6907,9 @@ void ProxySQL_Admin::flush_mysql_variables___database_to_runtime(SQLite3DB *db, free(previous_default_collation_connection); GloMTH->commit(); GloMTH->wrunlock(); - if (checksum_variables.checksum_mysql_variables) { + + // Checksums are always generated - 'admin-checksum_*' deprecated + { // NOTE: 'GloMTH->wrunlock()' should have been called before this point to avoid possible // deadlocks. See issue #3847. pthread_mutex_lock(&GloVars.checksum_mutex); @@ -7574,8 +7578,8 @@ void ProxySQL_Admin::flush_ldap_variables___database_to_runtime(SQLite3DB *db, b } GloMyLdapAuth->wrunlock(); - // update variables checksum - if (checksum_variables.checksum_ldap_variables) { + // Checksums are always generated - 'admin-checksum_*' deprecated + { pthread_mutex_lock(&GloVars.checksum_mutex); // generate checksum for cluster flush_ldap_variables___runtime_to_database(admindb, false, false, false, true); @@ -8130,6 +8134,10 @@ bool ProxySQL_Admin::set_variable(char *name, char *value, bool lock) { // this if (!strcasecmp(name,"cluster_mysql_query_rules_diffs_before_sync")) { int intv=atoi(value); if (intv >= 0 && intv <= 1000) { + if (variables.cluster_mysql_query_rules_diffs_before_sync == 0 && intv != 0) { + proxy_info("Re-enabled previously disabled 'admin-cluster_admin_variables_diffs_before_sync'. Resetting global checksums to force Cluster re-sync.\n"); + GloProxyCluster->Reset_Global_Checksums(lock); + } variables.cluster_mysql_query_rules_diffs_before_sync=intv; __sync_lock_test_and_set(&GloProxyCluster->cluster_mysql_query_rules_diffs_before_sync, intv); return true; @@ -8140,6 +8148,10 @@ bool ProxySQL_Admin::set_variable(char *name, char *value, bool lock) { // this if (!strcasecmp(name,"cluster_mysql_servers_diffs_before_sync")) { int intv=atoi(value); if (intv >= 0 && intv <= 1000) { + if (variables.cluster_mysql_servers_diffs_before_sync == 0 && intv != 0) { + proxy_info("Re-enabled previously disabled 'admin-cluster_mysql_servers_diffs_before_sync'. Resetting global checksums to force Cluster re-sync.\n"); + GloProxyCluster->Reset_Global_Checksums(lock); + } variables.cluster_mysql_servers_diffs_before_sync=intv; __sync_lock_test_and_set(&GloProxyCluster->cluster_mysql_servers_diffs_before_sync, intv); return true; @@ -8150,6 +8162,10 @@ bool ProxySQL_Admin::set_variable(char *name, char *value, bool lock) { // this if (!strcasecmp(name,"cluster_mysql_users_diffs_before_sync")) { int intv=atoi(value); if (intv >= 0 && intv <= 1000) { + if (variables.cluster_mysql_users_diffs_before_sync == 0 && intv != 0) { + proxy_info("Re-enabled previously disabled 'admin-cluster_mysql_users_diffs_before_sync'. Resetting global checksums to force Cluster re-sync.\n"); + GloProxyCluster->Reset_Global_Checksums(lock); + } variables.cluster_mysql_users_diffs_before_sync=intv; __sync_lock_test_and_set(&GloProxyCluster->cluster_mysql_users_diffs_before_sync, intv); return true; @@ -8160,6 +8176,10 @@ bool ProxySQL_Admin::set_variable(char *name, char *value, bool lock) { // this if (!strcasecmp(name,"cluster_proxysql_servers_diffs_before_sync")) { int intv=atoi(value); if (intv >= 0 && intv <= 1000) { + if (variables.cluster_proxysql_servers_diffs_before_sync == 0 && intv != 0) { + proxy_info("Re-enabled previously disabled 'admin-cluster_proxysql_servers_diffs_before_sync'. Resetting global checksums to force Cluster re-sync.\n"); + GloProxyCluster->Reset_Global_Checksums(lock); + } variables.cluster_proxysql_servers_diffs_before_sync=intv; __sync_lock_test_and_set(&GloProxyCluster->cluster_proxysql_servers_diffs_before_sync, intv); return true; @@ -8170,6 +8190,10 @@ bool ProxySQL_Admin::set_variable(char *name, char *value, bool lock) { // this if (!strcasecmp(name,"cluster_mysql_variables_diffs_before_sync")) { int intv=atoi(value); if (intv >= 0 && intv <= 1000) { + if (variables.cluster_mysql_variables_diffs_before_sync == 0 && intv != 0) { + proxy_info("Re-enabled previously disabled 'admin-cluster_mysql_variables_diffs_before_sync'. Resetting global checksums to force Cluster re-sync.\n"); + GloProxyCluster->Reset_Global_Checksums(lock); + } variables.cluster_mysql_variables_diffs_before_sync=intv; __sync_lock_test_and_set(&GloProxyCluster->cluster_mysql_variables_diffs_before_sync, intv); return true; @@ -8180,6 +8204,10 @@ bool ProxySQL_Admin::set_variable(char *name, char *value, bool lock) { // this if (!strcasecmp(name,"cluster_admin_variables_diffs_before_sync")) { int intv=atoi(value); if (intv >= 0 && intv <= 1000) { + if (variables.cluster_admin_variables_diffs_before_sync == 0 && intv != 0) { + proxy_info("Re-enabled previously disabled 'admin-cluster_admin_variables_diffs_before_sync'. Resetting global checksums to force Cluster re-sync.\n"); + GloProxyCluster->Reset_Global_Checksums(lock); + } variables.cluster_admin_variables_diffs_before_sync=intv; __sync_lock_test_and_set(&GloProxyCluster->cluster_admin_variables_diffs_before_sync, intv); return true; @@ -8190,6 +8218,10 @@ bool ProxySQL_Admin::set_variable(char *name, char *value, bool lock) { // this if (!strcasecmp(name,"cluster_ldap_variables_diffs_before_sync")) { int intv=atoi(value); if (intv >= 0 && intv <= 1000) { + if (variables.cluster_ldap_variables_save_to_disk == 0 && intv != 0) { + proxy_info("Re-enabled previously disabled 'admin-cluster_ldap_variables_diffs_before_sync'. Resetting global checksums to force Cluster re-sync.\n"); + GloProxyCluster->Reset_Global_Checksums(lock); + } variables.cluster_ldap_variables_diffs_before_sync=intv; __sync_lock_test_and_set(&GloProxyCluster->cluster_ldap_variables_diffs_before_sync, intv); return true; @@ -8384,28 +8416,25 @@ bool ProxySQL_Admin::set_variable(char *name, char *value, bool lock) { // this } if (strcasecmp(value,"false")==0 || strcasecmp(value,"0")==0) { checksum_variables.checksum_mysql_query_rules=false; + variables.cluster_mysql_query_rules_diffs_before_sync = 0; + proxy_warning("Disabling deprecated 'admin-checksum_mysql_query_rules', setting 'admin-cluster_mysql_query_rules_diffs_before_sync=0'\n"); return true; } return false; } if (!strcasecmp(name,"checksum_mysql_servers")) { - bool new_value = true; - if (strcasecmp(value,"true")==0 || strcasecmp(value,"1")==0) { - new_value = true; - } else if (strcasecmp(value,"false")==0 || strcasecmp(value,"0")==0) { - new_value = false; - } else { - return false; + checksum_variables.checksum_mysql_servers=true; + return true; } - - if (checksum_variables.checksum_mysql_servers == false && new_value == true) { - proxy_info("Updated 'admin-checksum_mysql_servers' to 'true'. Resetting global checksums to force Cluster re-sync.\n"); - GloProxyCluster->Reset_Global_Checksums(lock); + if (strcasecmp(value,"false")==0 || strcasecmp(value,"0")==0) { + checksum_variables.checksum_mysql_servers=false; + variables.cluster_mysql_servers_diffs_before_sync = 0; + proxy_warning("Disabling deprecated 'admin-checksum_mysql_servers', setting 'admin-cluster_mysql_servers_diffs_before_sync=0'\n"); + return true; } - checksum_variables.checksum_mysql_servers = new_value; - return true; + return false; } if (!strcasecmp(name,"checksum_mysql_users")) { if (strcasecmp(value,"true")==0 || strcasecmp(value,"1")==0) { @@ -8414,6 +8443,8 @@ bool ProxySQL_Admin::set_variable(char *name, char *value, bool lock) { // this } if (strcasecmp(value,"false")==0 || strcasecmp(value,"0")==0) { checksum_variables.checksum_mysql_users=false; + variables.cluster_mysql_users_diffs_before_sync = 0; + proxy_warning("Disabling deprecated 'admin-checksum_mysql_users', setting 'admin-cluster_mysql_users_diffs_before_sync=0'\n"); return true; } return false; @@ -8425,6 +8456,8 @@ bool ProxySQL_Admin::set_variable(char *name, char *value, bool lock) { // this } if (strcasecmp(value,"false")==0 || strcasecmp(value,"0")==0) { checksum_variables.checksum_mysql_variables=false; + variables.cluster_mysql_variables_diffs_before_sync = 0; + proxy_warning("Disabling deprecated 'admin-checksum_mysql_variables', setting 'admin-cluster_mysql_variables_diffs_before_sync=0'\n"); return true; } return false; @@ -8436,6 +8469,8 @@ bool ProxySQL_Admin::set_variable(char *name, char *value, bool lock) { // this } if (strcasecmp(value,"false")==0 || strcasecmp(value,"0")==0) { checksum_variables.checksum_admin_variables=false; + variables.cluster_admin_variables_diffs_before_sync = 0; + proxy_warning("Disabling deprecated 'admin-checksum_admin_variables', setting 'admin-cluster_admin_variables_diffs_before_sync=0'\n"); return true; } return false; @@ -8447,6 +8482,8 @@ bool ProxySQL_Admin::set_variable(char *name, char *value, bool lock) { // this } if (strcasecmp(value,"false")==0 || strcasecmp(value,"0")==0) { checksum_variables.checksum_ldap_variables=false; + variables.cluster_ldap_variables_diffs_before_sync = 0; + proxy_warning("Disabling deprecated 'admin-checksum_ldap_variables', setting 'admin-cluster_ldap_variables_diffs_before_sync=0'\n"); return true; } return false; @@ -10578,14 +10615,9 @@ void ProxySQL_Admin::add_admin_users() { void ProxySQL_Admin::__refresh_users( unique_ptr&& mysql_users_resultset, const string& checksum, const time_t epoch ) { - bool calculate_checksum = false; bool no_resultset_supplied = mysql_users_resultset == nullptr; - - if (checksum_variables.checksum_mysql_users) { - calculate_checksum = true; - } - if (calculate_checksum) - pthread_mutex_lock(&GloVars.checksum_mutex); + // Checksums are always generated - 'admin-checksum_*' deprecated + pthread_mutex_lock(&GloVars.checksum_mutex); __delete_inactive_users(USERNAME_BACKEND); __delete_inactive_users(USERNAME_FRONTEND); @@ -10605,7 +10637,8 @@ void ProxySQL_Admin::__refresh_users( GloMyAuth->remove_inactives(USERNAME_FRONTEND); set_variable((char *)"admin_credentials",(char *)""); - if (calculate_checksum) { + // Checksums are always generated - 'admin-checksum_*' deprecated + { char* buff = nullptr; char buf[20] = { 0 }; @@ -10642,8 +10675,9 @@ void ProxySQL_Admin::__refresh_users( // store the new 'added_users' resultset after generating the new checksum GloMyAuth->save_mysql_users(std::move(mysql_users_resultset)); - pthread_mutex_unlock(&GloVars.checksum_mutex); } + pthread_mutex_unlock(&GloVars.checksum_mutex); + proxy_info( "Computed checksum for 'LOAD MYSQL USERS TO RUNTIME' was '%s', with epoch '%llu'\n", GloVars.checksums_values.mysql_users.checksum, GloVars.checksums_values.mysql_users.epoch @@ -12184,7 +12218,9 @@ char* ProxySQL_Admin::load_mysql_query_rules_to_runtime(SQLite3_result* SQLite3_ #ifdef BENCHMARK_FASTROUTING_LOAD for (int i=0; i<10; i++) { #endif // BENCHMARK_FASTROUTING_LOAD - if (checksum_variables.checksum_mysql_query_rules) { + + // Checksums are always generated - 'admin-checksum_*' deprecated + { pthread_mutex_lock(&GloVars.checksum_mutex); char* buff = nullptr; char buf[20]; diff --git a/lib/ProxySQL_Cluster.cpp b/lib/ProxySQL_Cluster.cpp index 6a2e5d16c..599a59d7d 100644 --- a/lib/ProxySQL_Cluster.cpp +++ b/lib/ProxySQL_Cluster.cpp @@ -416,18 +416,22 @@ ProxySQL_Node_Metrics * ProxySQL_Node_Entry::get_metrics_prev() { void ProxySQL_Node_Entry::set_checksums(MYSQL_RES *_r) { MYSQL_ROW row; time_t now = time(NULL); - pthread_mutex_lock(&GloVars.checksum_mutex); - // Fetch the checksum variables to ensure consistency at local scope - bool admin_checksum_admin_variables = GloAdmin->checksum_variables.checksum_admin_variables; - bool admin_checksum_mysql_query_rules = GloAdmin->checksum_variables.checksum_mysql_query_rules; - bool admin_checksum_mysql_servers = GloAdmin->checksum_variables.checksum_mysql_servers; - bool admin_checksum_mysql_users = GloAdmin->checksum_variables.checksum_mysql_users; - bool admin_checksum_mysql_variables = GloAdmin->checksum_variables.checksum_mysql_variables; - bool admin_checksum_ldap_variables = GloAdmin->checksum_variables.checksum_ldap_variables; + // Fetch the cluster_*_diffs_before_sync variables to ensure consistency at local scope + unsigned int diff_mqr = (unsigned int)__sync_fetch_and_add(&GloProxyCluster->cluster_mysql_query_rules_diffs_before_sync,0); + unsigned int diff_ms = (unsigned int)__sync_fetch_and_add(&GloProxyCluster->cluster_mysql_servers_diffs_before_sync,0); + unsigned int diff_mu = (unsigned int)__sync_fetch_and_add(&GloProxyCluster->cluster_mysql_users_diffs_before_sync,0); + unsigned int diff_ps = (unsigned int)__sync_fetch_and_add(&GloProxyCluster->cluster_proxysql_servers_diffs_before_sync,0); + unsigned int diff_mv = (unsigned int)__sync_fetch_and_add(&GloProxyCluster->cluster_mysql_variables_diffs_before_sync,0); + unsigned int diff_lv = (unsigned int)__sync_fetch_and_add(&GloProxyCluster->cluster_ldap_variables_diffs_before_sync,0); + unsigned int diff_av = (unsigned int)__sync_fetch_and_add(&GloProxyCluster->cluster_admin_variables_diffs_before_sync,0); + + pthread_mutex_lock(&GloVars.checksum_mutex); while ( _r && (row = mysql_fetch_row(_r))) { if (strcmp(row[0],"admin_variables")==0) { + ProxySQL_Checksum_Value_2& checksum = checksums_values.admin_variables; + ProxySQL_Checksum_Value& global_checksum = GloVars.checksums_values.admin_variables; checksums_values.admin_variables.version = atoll(row[1]); checksums_values.admin_variables.epoch = atoll(row[2]); checksums_values.admin_variables.last_updated = now; @@ -435,48 +439,36 @@ void ProxySQL_Node_Entry::set_checksums(MYSQL_RES *_r) { strcpy(checksums_values.admin_variables.checksum, row[3]); checksums_values.admin_variables.last_changed = now; checksums_values.admin_variables.diff_check = 1; + const char* no_sync_message = NULL; - // DISABLED MODULE CHECKSUMS: - // -------------------------- - // Disabling the checksum computation of any module, implies that we are not going to perform a - // configuration pull for that particular module. Yet, we still follow the normal flow of fetch the new - // detected checksums from the peers. We inform during the fetching about the non-sync condition, and - // later we use the config to avoid the pulling. This approach has several advantages, first, it leaves - // us with a fully functional 'stats_proxysql_servers_checksums'. This allows us to spot the non-syncing - // condition cross-referencing with 'runtime_checksums_values': - // - Version number will be higher than '1' for the peer checksum. - // - Epoch of the checksum will be newer than our own epoch. - // - Diff check will keep increasing beyond the configured threshold. - // Secondly, allows us to easily prevent extra logging if 'global_checksums' are not used to prevent - // individual checksums fetching, see 'LOGGING-NOTE' below. - if (admin_checksum_admin_variables) { - proxy_info( - "Cluster: detected a new checksum for admin_variables from peer %s:%d, version %llu, epoch %llu, checksum %s . Not syncing yet ...\n", - hostname, port, checksums_values.admin_variables.version, checksums_values.admin_variables.epoch, checksums_values.admin_variables.checksum - ); + if (diff_av) { + no_sync_message = "Not syncing yet ...\n"; } else { + no_sync_message = "Not syncing due to 'admin-cluster_admin_variables_diffs_before_sync=0'.\n"; + } + + proxy_info( + "Cluster: detected a new checksum for %s from peer %s:%d, version %llu, epoch %llu, checksum %s . %s", + row[0], hostname, port, checksum.version, checksum.epoch, checksum.checksum, no_sync_message + ); + + if (strcmp(checksum.checksum, global_checksum.checksum) == 0) { proxy_info( - "Cluster: detected a new checksum for admin_variables from peer %s:%d, version %llu, epoch %llu, checksum %s. Not syncing due to 'admin-checksum_admin_variables=false'.\n", - hostname, port, checksums_values.admin_variables.version, checksums_values.admin_variables.epoch, checksums_values.admin_variables.checksum + "Cluster: checksum for %s from peer %s:%d matches with local checksum %s , we won't sync.\n", + row[0], hostname, port, global_checksum.checksum ); } } else { checksums_values.admin_variables.diff_check++; } if (strcmp(checksums_values.admin_variables.checksum, GloVars.checksums_values.admin_variables.checksum) == 0) { - // LOGGING-NOTE: Log only if the remote checksum has just been updated. Avoids constant logging when - // 'global_checksum' are not used to prevent individual modules fetching. - if (checksums_values.admin_variables.last_changed == now) { - proxy_info( - "Cluster: checksum for admin_variables from peer %s:%d matches with local checksum %s, we won't sync.\n", - hostname, port, GloVars.checksums_values.admin_variables.checksum - ); - } checksums_values.admin_variables.diff_check = 0; } continue; } if (strcmp(row[0],"mysql_query_rules")==0) { + ProxySQL_Checksum_Value_2& checksum = checksums_values.mysql_query_rules; + ProxySQL_Checksum_Value& global_checksum = GloVars.checksums_values.mysql_query_rules; checksums_values.mysql_query_rules.version = atoll(row[1]); checksums_values.mysql_query_rules.epoch = atoll(row[2]); checksums_values.mysql_query_rules.last_updated = now; @@ -484,35 +476,36 @@ void ProxySQL_Node_Entry::set_checksums(MYSQL_RES *_r) { strcpy(checksums_values.mysql_query_rules.checksum, row[3]); checksums_values.mysql_query_rules.last_changed = now; checksums_values.mysql_query_rules.diff_check = 1; + const char* no_sync_message = NULL; - // See 'DISABLED MODULE CHECKSUMS' at 'admin_variables' above - if (admin_checksum_mysql_query_rules) { - proxy_info( - "Cluster: detected a new checksum for mysql_query_rules from peer %s:%d, version %llu, epoch %llu, checksum %s . Not syncing yet ...\n", - hostname, port, checksums_values.mysql_query_rules.version, checksums_values.mysql_query_rules.epoch, checksums_values.mysql_query_rules.checksum - ); + if (diff_mqr) { + no_sync_message = "Not syncing yet ...\n"; } else { + no_sync_message = "Not syncing due to 'admin-cluster_mysql_query_rules_diffs_before_sync=0'.\n"; + } + + proxy_info( + "Cluster: detected a new checksum for %s from peer %s:%d, version %llu, epoch %llu, checksum %s . %s", + row[0], hostname, port, checksum.version, checksum.epoch, checksum.checksum, no_sync_message + ); + + if (strcmp(checksum.checksum, global_checksum.checksum) == 0) { proxy_info( - "Cluster: detected a new checksum for mysql_query_rules from peer %s:%d, version %llu, epoch %llu, checksum %s. Not syncing due to 'admin-checksum_mysql_query_rules=false'.\n", - hostname, port, checksums_values.mysql_query_rules.version, checksums_values.mysql_query_rules.epoch, checksums_values.mysql_query_rules.checksum + "Cluster: checksum for %s from peer %s:%d matches with local checksum %s , we won't sync.\n", + row[0], hostname, port, global_checksum.checksum ); } } else { checksums_values.mysql_query_rules.diff_check++; } if (strcmp(checksums_values.mysql_query_rules.checksum, GloVars.checksums_values.mysql_query_rules.checksum) == 0) { - // See LOGGING-NOTE at 'admin_variables' above. - if (checksums_values.mysql_query_rules.last_changed == now) { - proxy_info( - "Cluster: checksum for mysql_query_rules from peer %s:%d matches with local checksum %s , we won't sync.\n", - hostname, port, GloVars.checksums_values.mysql_query_rules.checksum - ); - } checksums_values.mysql_query_rules.diff_check = 0; } continue; } if (strcmp(row[0],"mysql_servers")==0) { + ProxySQL_Checksum_Value_2& checksum = checksums_values.mysql_servers; + ProxySQL_Checksum_Value& global_checksum = GloVars.checksums_values.mysql_servers; checksums_values.mysql_servers.version = atoll(row[1]); checksums_values.mysql_servers.epoch = atoll(row[2]); checksums_values.mysql_servers.last_updated = now; @@ -520,17 +513,23 @@ void ProxySQL_Node_Entry::set_checksums(MYSQL_RES *_r) { strcpy(checksums_values.mysql_servers.checksum, row[3]); checksums_values.mysql_servers.last_changed = now; checksums_values.mysql_servers.diff_check = 1; + const char* no_sync_message = NULL; - // See 'DISABLED MODULE CHECKSUMS' at 'admin_variables' above - if (admin_checksum_mysql_servers) { - proxy_info( - "Cluster: detected a new checksum for mysql_servers from peer %s:%d, version %llu, epoch %llu, checksum %s . Not syncing yet ...\n", - hostname, port, checksums_values.mysql_servers.version, checksums_values.mysql_servers.epoch, checksums_values.mysql_servers.checksum - ); + if (diff_ms) { + no_sync_message = "Not syncing yet ...\n"; } else { + no_sync_message = "Not syncing due to 'admin-cluster_mysql_servers_diffs_before_sync=0'.\n"; + } + + proxy_info( + "Cluster: detected a new checksum for %s from peer %s:%d, version %llu, epoch %llu, checksum %s . %s", + row[0], hostname, port, checksum.version, checksum.epoch, checksum.checksum, no_sync_message + ); + + if (strcmp(checksum.checksum, global_checksum.checksum) == 0) { proxy_info( - "Cluster: detected a new checksum for mysql_servers from peer %s:%d, version %llu, epoch %llu, checksum %s. Not syncing due to 'admin-checksum_mysql_servers=false'.\n", - hostname, port, checksums_values.mysql_servers.version, checksums_values.mysql_servers.epoch, checksums_values.mysql_servers.checksum + "Cluster: checksum for %s from peer %s:%d matches with local checksum %s , we won't sync.\n", + row[0], hostname, port, global_checksum.checksum ); } } else { @@ -546,6 +545,8 @@ void ProxySQL_Node_Entry::set_checksums(MYSQL_RES *_r) { continue; } if (strcmp(row[0],"mysql_users")==0) { + ProxySQL_Checksum_Value_2& checksum = checksums_values.mysql_users; + ProxySQL_Checksum_Value& global_checksum = GloVars.checksums_values.mysql_users; checksums_values.mysql_users.version = atoll(row[1]); checksums_values.mysql_users.epoch = atoll(row[2]); checksums_values.mysql_users.last_updated = now; @@ -553,35 +554,36 @@ void ProxySQL_Node_Entry::set_checksums(MYSQL_RES *_r) { strcpy(checksums_values.mysql_users.checksum, row[3]); checksums_values.mysql_users.last_changed = now; checksums_values.mysql_users.diff_check = 1; + const char* no_sync_message = NULL; - // See 'DISABLED MODULE CHECKSUMS' at 'admin_variables' above - if (admin_checksum_mysql_users) { - proxy_info( - "Cluster: detected a new checksum for mysql_users from peer %s:%d, version %llu, epoch %llu, checksum %s . Not syncing yet ...\n", - hostname, port, checksums_values.mysql_users.version, checksums_values.mysql_users.epoch, checksums_values.mysql_users.checksum - ); + if (diff_mu) { + no_sync_message = "Not syncing yet ...\n"; } else { + no_sync_message = "Not syncing due to 'admin-cluster_mysql_users_diffs_before_sync=0'.\n"; + } + + proxy_info( + "Cluster: detected a new checksum for %s from peer %s:%d, version %llu, epoch %llu, checksum %s . %s", + row[0], hostname, port, checksum.version, checksum.epoch, checksum.checksum, no_sync_message + ); + + if (strcmp(checksum.checksum, global_checksum.checksum) == 0) { proxy_info( - "Cluster: detected a new checksum for mysql_users from peer %s:%d, version %llu, epoch %llu, checksum %s. Not syncing due to 'admin-checksum_mysql_users=false'.\n", - hostname, port, checksums_values.mysql_users.version, checksums_values.mysql_users.epoch, checksums_values.mysql_users.checksum + "Cluster: checksum for %s from peer %s:%d matches with local checksum %s , we won't sync.\n", + row[0], hostname, port, global_checksum.checksum ); } } else { checksums_values.mysql_users.diff_check++; } if (strcmp(checksums_values.mysql_users.checksum, GloVars.checksums_values.mysql_users.checksum) == 0) { - // See LOGGING-NOTE at 'admin_variables' above. - if (checksums_values.mysql_users.last_changed == now) { - proxy_info( - "Cluster: checksum for mysql_users from peer %s:%d matches with local checksum %s , we won't sync.\n", - hostname, port, GloVars.checksums_values.mysql_users.checksum - ); - } checksums_values.mysql_users.diff_check = 0; } continue; } if (strcmp(row[0],"mysql_variables")==0) { + ProxySQL_Checksum_Value_2& checksum = checksums_values.mysql_variables; + ProxySQL_Checksum_Value& global_checksum = GloVars.checksums_values.mysql_variables; checksums_values.mysql_variables.version = atoll(row[1]); checksums_values.mysql_variables.epoch = atoll(row[2]); checksums_values.mysql_variables.last_updated = now; @@ -589,35 +591,36 @@ void ProxySQL_Node_Entry::set_checksums(MYSQL_RES *_r) { strcpy(checksums_values.mysql_variables.checksum, row[3]); checksums_values.mysql_variables.last_changed = now; checksums_values.mysql_variables.diff_check = 1; + const char* no_sync_message = NULL; - // See 'DISABLED MODULE CHECKSUMS' at 'mysql_variables' above - if (admin_checksum_mysql_variables) { - proxy_info( - "Cluster: detected a new checksum for mysql_variables from peer %s:%d, version %llu, epoch %llu, checksum %s . Not syncing yet ...\n", - hostname, port, checksums_values.mysql_variables.version, checksums_values.mysql_variables.epoch, checksums_values.mysql_variables.checksum - ); + if (diff_mv) { + no_sync_message = "Not syncing yet ...\n"; } else { + no_sync_message = "Not syncing due to 'admin-cluster_mysql_variables_diffs_before_sync=0'.\n"; + } + + proxy_info( + "Cluster: detected a new checksum for %s from peer %s:%d, version %llu, epoch %llu, checksum %s . %s", + row[0], hostname, port, checksum.version, checksum.epoch, checksum.checksum, no_sync_message + ); + + if (strcmp(checksum.checksum, global_checksum.checksum) == 0) { proxy_info( - "Cluster: detected a new checksum for mysql_variables from peer %s:%d, version %llu, epoch %llu, checksum %s. Not syncing due to 'admin-checksum_mysql_variables=false'.\n", - hostname, port, checksums_values.mysql_variables.version, checksums_values.mysql_variables.epoch, checksums_values.mysql_variables.checksum + "Cluster: checksum for %s from peer %s:%d matches with local checksum %s , we won't sync.\n", + row[0], hostname, port, global_checksum.checksum ); } } else { checksums_values.mysql_variables.diff_check++; } if (strcmp(checksums_values.mysql_variables.checksum, GloVars.checksums_values.mysql_variables.checksum) == 0) { - // See LOGGING-NOTE at 'admin_variables' above. - if (checksums_values.mysql_variables.last_changed == now) { - proxy_info( - "Cluster: checksum for mysql_variables from peer %s:%d matches with local checksum %s , we won't sync.\n", - hostname, port, GloVars.checksums_values.mysql_variables.checksum - ); - } checksums_values.mysql_variables.diff_check = 0; } continue; } if (strcmp(row[0],"proxysql_servers")==0) { + ProxySQL_Checksum_Value_2& checksum = checksums_values.proxysql_servers; + ProxySQL_Checksum_Value& global_checksum = GloVars.checksums_values.proxysql_servers; checksums_values.proxysql_servers.version = atoll(row[1]); checksums_values.proxysql_servers.epoch = atoll(row[2]); checksums_values.proxysql_servers.last_updated = now; @@ -625,9 +628,24 @@ void ProxySQL_Node_Entry::set_checksums(MYSQL_RES *_r) { strcpy(checksums_values.proxysql_servers.checksum, row[3]); checksums_values.proxysql_servers.last_changed = now; checksums_values.proxysql_servers.diff_check = 1; - proxy_info("Cluster: detected a new checksum for proxysql_servers from peer %s:%d, version %llu, epoch %llu, checksum %s . Not syncing yet ...\n", hostname, port, checksums_values.proxysql_servers.version, checksums_values.proxysql_servers.epoch, checksums_values.proxysql_servers.checksum); - if (strcmp(checksums_values.proxysql_servers.checksum, GloVars.checksums_values.proxysql_servers.checksum) == 0) { - proxy_info("Cluster: checksum for proxysql_servers from peer %s:%d matches with local checksum %s , we won't sync.\n", hostname, port, GloVars.checksums_values.proxysql_servers.checksum); + const char* no_sync_message = NULL; + + if (diff_ps) { + no_sync_message = "Not syncing yet ...\n"; + } else { + no_sync_message = "Not syncing due to 'admin-cluster_proxysql_servers_diffs_before_sync=0'.\n"; + } + + proxy_info( + "Cluster: detected a new checksum for %s from peer %s:%d, version %llu, epoch %llu, checksum %s . %s", + row[0], hostname, port, checksum.version, checksum.epoch, checksum.checksum, no_sync_message + ); + + if (strcmp(checksum.checksum, global_checksum.checksum) == 0) { + proxy_info( + "Cluster: checksum for %s from peer %s:%d matches with local checksum %s , we won't sync.\n", + row[0], hostname, port, global_checksum.checksum + ); } } else { checksums_values.proxysql_servers.diff_check++; @@ -638,6 +656,8 @@ void ProxySQL_Node_Entry::set_checksums(MYSQL_RES *_r) { continue; } if (GloMyLdapAuth && strcmp(row[0],"ldap_variables")==0) { + ProxySQL_Checksum_Value_2& checksum = checksums_values.ldap_variables; + ProxySQL_Checksum_Value& global_checksum = GloVars.checksums_values.ldap_variables; checksums_values.ldap_variables.version = atoll(row[1]); checksums_values.ldap_variables.epoch = atoll(row[2]); checksums_values.ldap_variables.last_updated = now; @@ -645,30 +665,29 @@ void ProxySQL_Node_Entry::set_checksums(MYSQL_RES *_r) { strcpy(checksums_values.ldap_variables.checksum, row[3]); checksums_values.ldap_variables.last_changed = now; checksums_values.ldap_variables.diff_check = 1; + const char* no_sync_message = NULL; - // See 'DISABLED MODULE CHECKSUMS' at 'admin_variables' above - if (admin_checksum_ldap_variables) { - proxy_info( - "Cluster: detected a new checksum for ldap_variables from peer %s:%d, version %llu, epoch %llu, checksum %s . Not syncing yet ...\n", - hostname, port, checksums_values.ldap_variables.version, checksums_values.ldap_variables.epoch, checksums_values.ldap_variables.checksum - ); + if (diff_lv) { + no_sync_message = "Not syncing yet ...\n"; } else { + no_sync_message = "Not syncing due to 'admin-cluster_ldap_variables_diffs_before_sync=0'.\n"; + } + + proxy_info( + "Cluster: detected a new checksum for %s from peer %s:%d, version %llu, epoch %llu, checksum %s . %s", + row[0], hostname, port, checksum.version, checksum.epoch, checksum.checksum, no_sync_message + ); + + if (strcmp(checksum.checksum, global_checksum.checksum) == 0) { proxy_info( - "Cluster: detected a new checksum for ldap_variables from peer %s:%d, version %llu, epoch %llu, checksum %s. Not syncing due to 'admin-checksum_ldap_variables=false'.\n", - hostname, port, checksums_values.ldap_variables.version, checksums_values.ldap_variables.epoch, checksums_values.ldap_variables.checksum + "Cluster: checksum for %s from peer %s:%d matches with local checksum %s , we won't sync.\n", + row[0], hostname, port, global_checksum.checksum ); } } else { checksums_values.ldap_variables.diff_check++; } if (strcmp(checksums_values.ldap_variables.checksum, GloVars.checksums_values.ldap_variables.checksum) == 0) { - // See LOGGING-NOTE at 'admin_variables' above. - if (checksums_values.ldap_variables.last_changed == now) { - proxy_info( - "Cluster: checksum for ldap_variables from peer %s:%d matches with local checksum %s , we won't sync.\n", - hostname, port, GloVars.checksums_values.ldap_variables.checksum - ); - } checksums_values.ldap_variables.diff_check = 0; } continue; @@ -730,19 +749,6 @@ void ProxySQL_Node_Entry::set_checksums(MYSQL_RES *_r) { // we now do a series of checks, and we take action // note that this is done outside the critical section // as mutex on GloVars.checksum_mutex is already released - unsigned int diff_mqr = admin_checksum_mysql_query_rules ? - (unsigned int)__sync_fetch_and_add(&GloProxyCluster->cluster_mysql_query_rules_diffs_before_sync,0) : 0; - unsigned int diff_ms = admin_checksum_mysql_servers ? - (unsigned int)__sync_fetch_and_add(&GloProxyCluster->cluster_mysql_servers_diffs_before_sync,0) : 0; - unsigned int diff_mu = admin_checksum_mysql_users ? - (unsigned int)__sync_fetch_and_add(&GloProxyCluster->cluster_mysql_users_diffs_before_sync,0) : 0; - unsigned int diff_ps = (unsigned int)__sync_fetch_and_add(&GloProxyCluster->cluster_proxysql_servers_diffs_before_sync,0); - unsigned int diff_mv = admin_checksum_mysql_variables ? - (unsigned int)__sync_fetch_and_add(&GloProxyCluster->cluster_mysql_variables_diffs_before_sync,0) : 0; - unsigned int diff_lv = admin_checksum_ldap_variables ? - (unsigned int)__sync_fetch_and_add(&GloProxyCluster->cluster_ldap_variables_diffs_before_sync,0) : 0; - unsigned int diff_av = admin_checksum_admin_variables ? - (unsigned int)__sync_fetch_and_add(&GloProxyCluster->cluster_admin_variables_diffs_before_sync,0) : 0; ProxySQL_Checksum_Value_2 *v = NULL; if (diff_mqr) { unsigned long long own_version = __sync_fetch_and_add(&GloVars.checksums_values.mysql_query_rules.version,0);