From ba1762bc3e470155cf61edfbd10319bf61ab45e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Mon, 26 Apr 2021 18:50:22 +0200 Subject: [PATCH 01/17] Implemented sync support for 'ldap-%' global variables --- include/ProxySQL_Cluster.hpp | 9 ++ include/proxysql_admin.h | 4 + include/proxysql_glovars.hpp | 1 + lib/ProxySQL_Admin.cpp | 96 ++++++++++++++++++++ lib/ProxySQL_Cluster.cpp | 166 +++++++++++++++++++++++++++++++++-- lib/ProxySQL_GloVars.cpp | 11 +++ 6 files changed, 282 insertions(+), 5 deletions(-) diff --git a/include/ProxySQL_Cluster.hpp b/include/ProxySQL_Cluster.hpp index 33f514ce9..e228b0f69 100644 --- a/include/ProxySQL_Cluster.hpp +++ b/include/ProxySQL_Cluster.hpp @@ -86,6 +86,7 @@ class ProxySQL_Node_Entry { struct { ProxySQL_Checksum_Value_2 admin_variables; ProxySQL_Checksum_Value_2 mysql_variables; + ProxySQL_Checksum_Value_2 ldap_variables; ProxySQL_Checksum_Value_2 mysql_query_rules; ProxySQL_Checksum_Value_2 mysql_servers; ProxySQL_Checksum_Value_2 mysql_users; @@ -116,6 +117,7 @@ class ProxySQL_Cluster_Nodes { void get_peer_to_sync_mysql_users(char **host, uint16_t *port); void get_peer_to_sync_mysql_variables(char **host, uint16_t *port); void get_peer_to_sync_admin_variables(char **host, uint16_t* port); + void get_peer_to_sync_ldap_variables(char **host, uint16_t *port); void get_peer_to_sync_proxysql_servers(char **host, uint16_t *port); }; @@ -149,12 +151,16 @@ struct p_cluster_counter { pulled_admin_variables_success, pulled_admin_variables_failure, + pulled_ldap_variables_success, + pulled_ldap_variables_failure, + sync_conflict_mysql_query_rules_share_epoch, sync_conflict_mysql_servers_share_epoch, sync_conflict_proxysql_servers_share_epoch, sync_conflict_mysql_users_share_epoch, sync_conflict_mysql_variables_share_epoch, sync_conflict_admin_variables_share_epoch, + sync_conflict_ldap_variables_share_epoch, sync_delayed_mysql_query_rules_version_one, sync_delayed_mysql_servers_version_one, @@ -162,6 +168,7 @@ struct p_cluster_counter { sync_delayed_proxysql_servers_version_one, sync_delayed_mysql_variables_version_one, sync_delayed_admin_variables_version_one, + sync_delayed_ldap_variables_version_one, __size }; @@ -225,12 +232,14 @@ class ProxySQL_Cluster { int cluster_mysql_users_diffs_before_sync; int cluster_proxysql_servers_diffs_before_sync; int cluster_mysql_variables_diffs_before_sync; + int cluster_ldap_variables_diffs_before_sync; int cluster_admin_variables_diffs_before_sync; bool cluster_mysql_query_rules_save_to_disk; bool cluster_mysql_servers_save_to_disk; bool cluster_mysql_users_save_to_disk; bool cluster_proxysql_servers_save_to_disk; bool cluster_mysql_variables_save_to_disk; + bool cluster_ldap_variables_save_to_disk; bool cluster_admin_variables_save_to_disk; ProxySQL_Cluster(); ~ProxySQL_Cluster(); diff --git a/include/proxysql_admin.h b/include/proxysql_admin.h index b85ffae70..78930068e 100644 --- a/include/proxysql_admin.h +++ b/include/proxysql_admin.h @@ -152,12 +152,14 @@ class ProxySQL_Admin { int cluster_proxysql_servers_diffs_before_sync; int cluster_mysql_variables_diffs_before_sync; int cluster_admin_variables_diffs_before_sync; + int cluster_ldap_variables_diffs_before_sync; bool cluster_mysql_query_rules_save_to_disk; bool cluster_mysql_servers_save_to_disk; bool cluster_mysql_users_save_to_disk; bool cluster_proxysql_servers_save_to_disk; bool cluster_mysql_variables_save_to_disk; bool cluster_admin_variables_save_to_disk; + bool cluster_ldap_variables_save_to_disk; int stats_mysql_connection_pool; int stats_mysql_connections; int stats_mysql_query_cache; @@ -262,6 +264,7 @@ class ProxySQL_Admin { bool checksum_mysql_users; bool checksum_mysql_variables; bool checksum_admin_variables; + bool checksum_ldap_variables; } checksum_variables; void public_add_active_users(enum cred_username_type usertype, char *user=NULL) { __add_active_users(usertype, user); @@ -311,6 +314,7 @@ class ProxySQL_Admin { void flush_mysql_variables__from_memory_to_disk(); void flush_admin_variables__from_disk_to_memory(); void flush_admin_variables__from_memory_to_disk(); + void flush_ldap_variables__from_memory_to_disk(); void load_mysql_servers_to_runtime(); void save_mysql_servers_from_runtime(); diff --git a/include/proxysql_glovars.hpp b/include/proxysql_glovars.hpp index 6b8b299f4..67eede52a 100644 --- a/include/proxysql_glovars.hpp +++ b/include/proxysql_glovars.hpp @@ -111,6 +111,7 @@ class ProxySQL_GlobalVariables { ProxySQL_Checksum_Value mysql_servers; ProxySQL_Checksum_Value mysql_users; ProxySQL_Checksum_Value mysql_variables; + ProxySQL_Checksum_Value ldap_variables; ProxySQL_Checksum_Value proxysql_servers; uint64_t global_checksum; unsigned long long updates_cnt; diff --git a/lib/ProxySQL_Admin.cpp b/lib/ProxySQL_Admin.cpp index 10db17b0f..74f3cd10e 100644 --- a/lib/ProxySQL_Admin.cpp +++ b/lib/ProxySQL_Admin.cpp @@ -535,17 +535,20 @@ static char * admin_variables_names[]= { (char *)"cluster_proxysql_servers_diffs_before_sync", (char *)"cluster_mysql_variables_diffs_before_sync", (char *)"cluster_admin_variables_diffs_before_sync", + (char *)"cluster_ldap_variables_diffs_before_sync", (char *)"cluster_mysql_query_rules_save_to_disk", (char *)"cluster_mysql_servers_save_to_disk", (char *)"cluster_mysql_users_save_to_disk", (char *)"cluster_proxysql_servers_save_to_disk", (char *)"cluster_mysql_variables_save_to_disk", (char *)"cluster_admin_variables_save_to_disk", + (char *)"cluster_ldap_variables_save_to_disk", (char *)"checksum_mysql_query_rules", (char *)"checksum_mysql_servers", (char *)"checksum_mysql_users", (char *)"checksum_mysql_variables", (char *)"checksum_admin_variables", + (char *)"checksum_ldap_variables", (char *)"restapi_enabled", (char *)"restapi_port", (char *)"web_enabled", @@ -5265,17 +5268,20 @@ ProxySQL_Admin::ProxySQL_Admin() : variables.cluster_proxysql_servers_diffs_before_sync = 3; variables.cluster_mysql_variables_diffs_before_sync = 3; variables.cluster_admin_variables_diffs_before_sync = 3; + variables.cluster_ldap_variables_diffs_before_sync = 3; checksum_variables.checksum_mysql_query_rules = true; checksum_variables.checksum_mysql_servers = true; checksum_variables.checksum_mysql_users = true; checksum_variables.checksum_mysql_variables = true; checksum_variables.checksum_admin_variables = true; + checksum_variables.checksum_ldap_variables = true; variables.cluster_mysql_query_rules_save_to_disk = true; variables.cluster_mysql_servers_save_to_disk = true; variables.cluster_mysql_users_save_to_disk = true; variables.cluster_proxysql_servers_save_to_disk = true; variables.cluster_mysql_variables_save_to_disk = true; variables.cluster_admin_variables_save_to_disk = true; + variables.cluster_ldap_variables_save_to_disk = true; variables.stats_mysql_connection_pool = 60; variables.stats_mysql_connections = 60; variables.stats_mysql_query_cache = 60; @@ -6935,6 +6941,33 @@ void ProxySQL_Admin::flush_ldap_variables___database_to_runtime(SQLite3DB *db, b } } GloMyLdapAuth->wrunlock(); + + // update variables checksum + if (checksum_variables.checksum_ldap_variables) { + pthread_mutex_lock(&GloVars.checksum_mutex); + // generate checksum for cluster + flush_ldap_variables___runtime_to_database(admindb, false, false, false, true); + char *error=NULL; + int cols=0; + int affected_rows=0; + SQLite3_result *resultset=NULL; + char *q=(char *)"SELECT variable_name, variable_value FROM runtime_global_variables WHERE variable_name LIKE 'ldap-\%' ORDER BY variable_name"; + admindb->execute_statement(q, &error , &cols , &affected_rows , &resultset); + uint64_t hash1 = resultset->raw_checksum(); + uint32_t d32[2]; + char buf[20]; + memcpy(&d32, &hash1, sizeof(hash1)); + sprintf(buf,"0x%0X%0X", d32[0], d32[1]); + GloVars.checksums_values.ldap_variables.set_checksum(buf); + GloVars.checksums_values.ldap_variables.version++; + time_t t = time(NULL); + GloVars.checksums_values.ldap_variables.epoch = t; + GloVars.epoch_version = t; + GloVars.generate_global_checksum(); + GloVars.checksums_values.updates_cnt++; + pthread_mutex_unlock(&GloVars.checksum_mutex); + delete resultset; + } } if (resultset) delete resultset; } @@ -7099,6 +7132,10 @@ char * ProxySQL_Admin::get_variable(char *name) { sprintf(intbuf,"%d",variables.cluster_admin_variables_diffs_before_sync); return strdup(intbuf); } + if (!strcasecmp(name,"cluster_ldap_variables_diffs_before_sync")) { + sprintf(intbuf,"%d",variables.cluster_ldap_variables_diffs_before_sync); + return strdup(intbuf); + } if (!strcasecmp(name,"cluster_mysql_query_rules_save_to_disk")) { return strdup((variables.cluster_mysql_query_rules_save_to_disk ? "true" : "false")); } @@ -7117,6 +7154,9 @@ char * ProxySQL_Admin::get_variable(char *name) { if (!strcasecmp(name,"cluster_admin_variables_save_to_disk")) { return strdup((variables.cluster_admin_variables_save_to_disk ? "true" : "false")); } + if (!strcasecmp(name,"cluster_ldap_variables_save_to_disk")) { + return strdup((variables.cluster_ldap_variables_save_to_disk ? "true" : "false")); + } if (!strcasecmp(name,"refresh_interval")) { sprintf(intbuf,"%d",variables.refresh_interval); return strdup(intbuf); @@ -7145,6 +7185,9 @@ char * ProxySQL_Admin::get_variable(char *name) { if (!strcasecmp(name,"checksum_admin_variables")) { return strdup((checksum_variables.checksum_admin_variables ? "true" : "false")); } + if (!strcasecmp(name,"checksum_ldap_variables")) { + return strdup((checksum_variables.checksum_ldap_variables ? "true" : "false")); + } if (!strcasecmp(name,"restapi_enabled")) { return strdup((variables.restapi_enabled ? "true" : "false")); } @@ -7609,6 +7652,16 @@ bool ProxySQL_Admin::set_variable(char *name, char *value) { // this is the pub return false; } } + if (!strcasecmp(name,"cluster_ldap_variables_diffs_before_sync")) { + int intv=atoi(value); + if (intv >= 0 && intv <= 1000) { + variables.cluster_ldap_variables_diffs_before_sync=intv; + __sync_lock_test_and_set(&GloProxyCluster->cluster_ldap_variables_diffs_before_sync, intv); + return true; + } else { + return false; + } + } if (!strcasecmp(name,"version")) { if (strcasecmp(value,(char *)PROXYSQL_VERSION)==0) { return true; @@ -7775,6 +7828,20 @@ bool ProxySQL_Admin::set_variable(char *name, char *value) { // this is the pub } return rt; } + if (!strcasecmp(name,"cluster_ldap_variables_save_to_disk")) { + bool rt = false; + if (strcasecmp(value,"true")==0 || strcasecmp(value,"1")==0) { + variables.cluster_ldap_variables_save_to_disk=true; + rt = __sync_lock_test_and_set(&GloProxyCluster->cluster_ldap_variables_save_to_disk, true); + return true; + } + if (strcasecmp(value,"false")==0 || strcasecmp(value,"0")==0) { + variables.cluster_ldap_variables_save_to_disk=false; + rt = __sync_lock_test_and_set(&GloProxyCluster->cluster_ldap_variables_save_to_disk, false); + return true; + } + return rt; + } if (!strcasecmp(name,"checksum_mysql_query_rules")) { if (strcasecmp(value,"true")==0 || strcasecmp(value,"1")==0) { checksum_variables.checksum_mysql_query_rules=true; @@ -7830,6 +7897,17 @@ bool ProxySQL_Admin::set_variable(char *name, char *value) { // this is the pub } return false; } + if (!strcasecmp(name,"checksum_ldap_variables")) { + if (strcasecmp(value,"true")==0 || strcasecmp(value,"1")==0) { + checksum_variables.checksum_ldap_variables=true; + return true; + } + if (strcasecmp(value,"false")==0 || strcasecmp(value,"0")==0) { + checksum_variables.checksum_ldap_variables=false; + return true; + } + return false; + } if (!strcasecmp(name,"read_only")) { if (strcasecmp(value,"true")==0 || strcasecmp(value,"1")==0) { variables.admin_read_only=true; @@ -9774,6 +9852,14 @@ void ProxySQL_Admin::flush_admin_variables__from_memory_to_disk() { admindb->wrunlock(); } +void ProxySQL_Admin::flush_ldap_variables__from_memory_to_disk() { + admindb->wrlock(); + admindb->execute("PRAGMA foreign_keys = OFF"); + admindb->execute("INSERT OR REPLACE INTO disk.global_variables SELECT * FROM main.global_variables WHERE variable_name LIKE 'ldap-%'"); + admindb->execute("PRAGMA foreign_keys = ON"); + admindb->wrunlock(); +} + void ProxySQL_Admin::__attach_db(SQLite3DB *db1, SQLite3DB *db2, char *alias) { const char *a="ATTACH DATABASE '%s' AS %s"; int l=strlen(a)+strlen(db2->get_url())+strlen(alias)+5; @@ -10271,6 +10357,16 @@ void ProxySQL_Admin::dump_checksums_values_table() { rc=(*proxy_sqlite3_clear_bindings)(statement1); ASSERT_SQLITE_OK(rc, admindb); rc=(*proxy_sqlite3_reset)(statement1); ASSERT_SQLITE_OK(rc, admindb); + if (GloMyLdapAuth) { + rc=(*proxy_sqlite3_bind_text)(statement1, 1, "ldap_variables", -1, SQLITE_TRANSIENT); ASSERT_SQLITE_OK(rc, admindb); + rc=(*proxy_sqlite3_bind_int64)(statement1, 2, GloVars.checksums_values.ldap_variables.version); ASSERT_SQLITE_OK(rc, admindb); + rc=(*proxy_sqlite3_bind_int64)(statement1, 3, GloVars.checksums_values.ldap_variables.epoch); ASSERT_SQLITE_OK(rc, admindb); + rc=(*proxy_sqlite3_bind_text)(statement1, 4, GloVars.checksums_values.ldap_variables.checksum, -1, SQLITE_TRANSIENT); ASSERT_SQLITE_OK(rc, admindb); + SAFE_SQLITE3_STEP2(statement1); + rc=(*proxy_sqlite3_clear_bindings)(statement1); ASSERT_SQLITE_OK(rc, admindb); + rc=(*proxy_sqlite3_reset)(statement1); ASSERT_SQLITE_OK(rc, admindb); + } + admindb->execute((char *)"COMMIT"); pthread_mutex_unlock(&GloVars.checksum_mutex); (*proxy_sqlite3_finalize)(statement1); diff --git a/lib/ProxySQL_Cluster.cpp b/lib/ProxySQL_Cluster.cpp index 663ecd870..f5193b600 100644 --- a/lib/ProxySQL_Cluster.cpp +++ b/lib/ProxySQL_Cluster.cpp @@ -5,6 +5,7 @@ #include "prometheus_helpers.h" #include "ProxySQL_Cluster.hpp" +#include "MySQL_LDAP_Authentication.hpp" #ifdef DEBUG #define DEB "_DEBUG" @@ -37,8 +38,8 @@ static char *NODE_COMPUTE_DELIMITER=(char *)"-gtyw23a-"; // a random string used for hashing extern ProxySQL_Cluster * GloProxyCluster; - extern ProxySQL_Admin *GloAdmin; +extern MySQL_LDAP_Authentication* GloMyLdapAuth; typedef struct _proxy_node_address_t { pthread_t thrid; @@ -495,6 +496,26 @@ void ProxySQL_Node_Entry::set_checksums(MYSQL_RES *_r) { } continue; } + if (GloMyLdapAuth && strcmp(row[0],"ldap_variables")==0) { + checksums_values.ldap_variables.version = atoll(row[1]); + checksums_values.ldap_variables.epoch = atoll(row[2]); + checksums_values.ldap_variables.last_updated = now; + if (strcmp(checksums_values.ldap_variables.checksum, row[3])) { + strcpy(checksums_values.ldap_variables.checksum, row[3]); + checksums_values.ldap_variables.last_changed = now; + checksums_values.ldap_variables.diff_check = 1; + 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 (strcmp(checksums_values.ldap_variables.checksum, GloVars.checksums_values.ldap_variables.checksum) == 0) { + 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); + } + } else { + checksums_values.ldap_variables.diff_check++; + } + if (strcmp(checksums_values.ldap_variables.checksum, GloVars.checksums_values.ldap_variables.checksum) == 0) { + checksums_values.ldap_variables.diff_check = 0; + } + continue; + } } if (_r == NULL) { ProxySQL_Checksum_Value_2 *v = NULL; @@ -540,6 +561,13 @@ void ProxySQL_Node_Entry::set_checksums(MYSQL_RES *_r) { } if (v->diff_check) v->diff_check++; + v = &checksums_values.ldap_variables; + v->last_updated = now; + if (strcmp(v->checksum, GloVars.checksums_values.ldap_variables.checksum) == 0) { + v->diff_check = 0; + } + if (v->diff_check) + v->diff_check++; } pthread_mutex_unlock(&GloVars.checksum_mutex); // we now do a series of checks, and we take action @@ -550,6 +578,7 @@ void ProxySQL_Node_Entry::set_checksums(MYSQL_RES *_r) { 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); ProxySQL_Checksum_Value_2 *v = NULL; if (diff_mqr) { @@ -716,6 +745,34 @@ void ProxySQL_Node_Entry::set_checksums(MYSQL_RES *_r) { } } } + if (GloMyLdapAuth && diff_lv) { + v = &checksums_values.ldap_variables; + unsigned long long own_version = __sync_fetch_and_add(&GloVars.checksums_values.ldap_variables.version, 0); + unsigned long long own_epoch = __sync_fetch_and_add(&GloVars.checksums_values.ldap_variables.epoch, 0); + char* own_checksum = __sync_fetch_and_add(&GloVars.checksums_values.ldap_variables.checksum, 0); + + if (v->version > 1) { + if ( + (own_version == 1) // we just booted + || + (v->epoch > own_epoch) // epoch is newer + ) { + if (v->diff_check >= diff_lv) { + proxy_info("Cluster: detected a peer %s:%d with ldap_variables version %llu, epoch %llu, diff_check %u. Own version: %llu, epoch: %llu. Proceeding with remote sync\n", hostname, port, v->version, v->epoch, v->diff_check, own_version, own_epoch); + GloProxyCluster->pull_global_variables_from_peer("ldap"); + } + } + if ((v->epoch == own_epoch) && v->diff_check && ((v->diff_check % (diff_lv*10)) == 0)) { + proxy_error("Cluster: detected a peer %s:%d with ldap_variables 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 %llu checks until LOAD MYSQL VARIABLES 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_lv*10)); + GloProxyCluster->metrics.p_counter_array[p_cluster_counter::sync_conflict_ldap_variables_share_epoch]->Increment(); + } + } else { + if (v->diff_check && (v->diff_check % (diff_lv*10)) == 0) { + proxy_warning("Cluster: detected a peer %s:%d with ldap_variables 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 %llu checks until LOAD MYSQL VARIABLES TO RUNTIME is executed on candidate master.\n", hostname, port, v->version, v->epoch, v->diff_check, own_version, own_epoch, (diff_lv*10)); + GloProxyCluster->metrics.p_counter_array[p_cluster_counter::sync_delayed_ldap_variables_version_one]->Increment(); + } + } + } } void ProxySQL_Cluster::pull_mysql_query_rules_from_peer() { @@ -1377,16 +1434,25 @@ void ProxySQL_Cluster::pull_global_variables_from_peer(const std::string& var_ty vars_type_str = const_cast("Admin"); success_metric = p_cluster_counter::pulled_admin_variables_success; failure_metric = p_cluster_counter::pulled_admin_variables_failure; + } else if (var_type == "ldap") { + vars_type_str = const_cast("LDAP"); + success_metric = p_cluster_counter::pulled_ldap_variables_success; + failure_metric = p_cluster_counter::pulled_ldap_variables_failure; } else { - proxy_error("Invalid parameter supplied to 'pull_global_variables_from_peer': var_type=%s", var_type.c_str()); + proxy_error("Invalid parameter supplied to 'pull_global_variables_from_peer': var_type=%s\n", var_type.c_str()); assert(0); } pthread_mutex_lock(&GloProxyCluster->update_mysql_variables_mutex); if (var_type == "mysql") { nodes.get_peer_to_sync_mysql_variables(&hostname, &port); - } else { + } else if (var_type == "admin") { nodes.get_peer_to_sync_admin_variables(&hostname, &port); + } else if (var_type == "ldap"){ + nodes.get_peer_to_sync_ldap_variables(&hostname, &port); + } else { + proxy_error("Invalid parameter supplied to 'pull_global_variables_from_peer': var_type=%s\n", var_type.c_str()); + assert(0); } if (hostname) { @@ -1450,13 +1516,23 @@ void ProxySQL_Cluster::pull_global_variables_from_peer(const std::string& var_ty proxy_info("Cluster: Saving to disk MySQL Variables from peer %s:%d\n", hostname, port); GloAdmin->flush_mysql_variables__from_memory_to_disk(); } - } else { + } else if (var_type == "admin") { GloAdmin->load_admin_variables_to_runtime(); if (GloProxyCluster->cluster_admin_variables_save_to_disk == true) { proxy_info("Cluster: Saving to disk Admin Variables from peer %s:%d\n", hostname, port); GloAdmin->flush_admin_variables__from_memory_to_disk(); } + } else if (var_type == "ldap") { + GloAdmin->load_ldap_variables_to_runtime(); + + if (GloProxyCluster->cluster_ldap_variables_save_to_disk == true) { + proxy_info("Cluster: Saving to disk LDAP Variables from peer %s:%d\n", hostname, port); + GloAdmin->flush_ldap_variables__from_memory_to_disk(); + } + } else { + proxy_error("Invalid parameter supplied to 'pull_global_variables_from_peer': var_type=%s\n", var_type.c_str()); + assert(0); } metrics.p_counter_array[success_metric]->Increment(); } else { @@ -1973,6 +2049,48 @@ void ProxySQL_Cluster_Nodes::get_peer_to_sync_admin_variables(char **host, uint1 } } +void ProxySQL_Cluster_Nodes::get_peer_to_sync_ldap_variables(char **host, uint16_t *port) { + unsigned long long version = 0; + unsigned long long epoch = 0; + unsigned long long max_epoch = 0; + char *hostname = NULL; + uint16_t p = 0; + unsigned int diff_mu = (unsigned int)__sync_fetch_and_add(&GloProxyCluster->cluster_ldap_variables_diffs_before_sync,0); + for (std::unordered_map::iterator it = umap_proxy_nodes.begin(); it != umap_proxy_nodes.end();) { + ProxySQL_Node_Entry * node = it->second; + ProxySQL_Checksum_Value_2 * v = &node->checksums_values.ldap_variables; + if (v->version > 1) { + if ( v->epoch > epoch ) { + max_epoch = v->epoch; + if (v->diff_check > diff_mu) { + epoch = v->epoch; + version = v->version; + if (hostname) { + free(hostname); + } + hostname=strdup(node->get_hostname()); + p = node->get_port(); + } + } + } + it++; + } + if (epoch) { + if (max_epoch > epoch) { + proxy_warning("Cluster: detected a peer with ldap_variables epoch %llu, but not enough diff_check. We won't sync from epoch %llu: temporarily skipping sync\n", max_epoch, epoch); + if (hostname) { + free(hostname); + hostname = NULL; + } + } + } + if (hostname) { + *host = hostname; + *port = p; + proxy_info("Cluster: detected peer %s:%d with ldap_variables version %llu, epoch %llu\n", hostname, p, version, epoch); + } +} + void ProxySQL_Cluster_Nodes::get_peer_to_sync_proxysql_servers(char **host, uint16_t *port) { unsigned long long version = 0; unsigned long long epoch = 0; @@ -2454,6 +2572,26 @@ cluster_metrics_map = std::make_tuple( } ), + // ldap_variables_* + std::make_tuple ( + p_cluster_counter::pulled_ldap_variables_success, + "proxysql_cluster_pulled_total", + "Number of times a 'module' have been pulled from a peer.", + metric_tags { + { "module_name", "ldap_variables" }, + { "status", "success" } + } + ), + std::make_tuple ( + p_cluster_counter::pulled_ldap_variables_failure, + "proxysql_cluster_pulled_total", + "Number of times a 'module' have been pulled from a peer.", + metric_tags { + { "module_name", "ldap_variables" }, + { "status", "failure" } + } + ), + // sync_conflict same epoch // ==================================================================== std::make_tuple ( @@ -2510,6 +2648,15 @@ cluster_metrics_map = std::make_tuple( { "reason", "servers_share_epoch" } } ), + std::make_tuple ( + p_cluster_counter::sync_conflict_ldap_variables_share_epoch, + "proxysql_cluster_syn_conflict_total", + "Number of times a 'module' has not been able to be synced.", + metric_tags { + { "module_name", "ldap_variables" }, + { "reason", "servers_share_epoch" } + } + ), // ==================================================================== // sync_delayed due to version one @@ -2567,7 +2714,16 @@ cluster_metrics_map = std::make_tuple( { "module_name", "admin_variables" }, { "reason", "version_one" } } - ) + ), + std::make_tuple ( + p_cluster_counter::sync_delayed_ldap_variables_version_one, + "proxysql_cluster_syn_conflict_total", + "Number of times a 'module' has not been able to be synced.", + metric_tags { + { "module_name", "ldap_variables" }, + { "reason", "version_one" } + } + ), // ==================================================================== }, cluster_gauge_vector {} diff --git a/lib/ProxySQL_GloVars.cpp b/lib/ProxySQL_GloVars.cpp index 323e7949b..fd86d4377 100644 --- a/lib/ProxySQL_GloVars.cpp +++ b/lib/ProxySQL_GloVars.cpp @@ -7,6 +7,10 @@ #include "SpookyV2.h" #include +#include "MySQL_LDAP_Authentication.hpp" + +extern MySQL_LDAP_Authentication* GloMyLdapAuth; + static void term_handler(int sig) { proxy_warning("Received TERM signal: shutdown in progress...\n"); #ifdef DEBUG @@ -367,6 +371,13 @@ uint64_t ProxySQL_GlobalVariables::generate_global_checksum() { myhash.Update(v->checksum,strlen(v->checksum)); myhash.Update(&v->version,sizeof(v->version)); } + if (GloMyLdapAuth) { + v = &checksums_values.ldap_variables; + if (v->version) { + myhash.Update(v->checksum,strlen(v->checksum)); + myhash.Update(&v->version,sizeof(v->version)); + } + } uint64_t h1, h2; myhash.Final(&h1, &h2); h1 = h1/2; // ugly way to make it signed within LLONG_MAX From 04d39472126afe4c69cab3ed761282b00783b3e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Mon, 26 Apr 2021 18:51:40 +0200 Subject: [PATCH 02/17] Implemented sync support for 'mysql_ldap_mapping' table --- include/ProxySQL_Cluster.hpp | 3 ++ lib/ProxySQL_Cluster.cpp | 70 +++++++++++++++++++++++++++++++++++- 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/include/ProxySQL_Cluster.hpp b/include/ProxySQL_Cluster.hpp index e228b0f69..fb08900f6 100644 --- a/include/ProxySQL_Cluster.hpp +++ b/include/ProxySQL_Cluster.hpp @@ -154,6 +154,9 @@ struct p_cluster_counter { pulled_ldap_variables_success, pulled_ldap_variables_failure, + pulled_mysql_ldap_mapping_success, + pulled_mysql_ldap_mapping_failure, + sync_conflict_mysql_query_rules_share_epoch, sync_conflict_mysql_servers_share_epoch, sync_conflict_proxysql_servers_share_epoch, diff --git a/lib/ProxySQL_Cluster.cpp b/lib/ProxySQL_Cluster.cpp index f5193b600..e47f4011c 100644 --- a/lib/ProxySQL_Cluster.cpp +++ b/lib/ProxySQL_Cluster.cpp @@ -1012,9 +1012,57 @@ void ProxySQL_Cluster::pull_mysql_users_from_peer() { proxy_info("Cluster: Fetching MySQL Users from peer %s:%d failed: %s\n", hostname, port, mysql_error(conn)); metrics.p_counter_array[p_cluster_counter::pulled_mysql_users_failure]->Increment(); } + + if (GloMyLdapAuth) { + rc_query = mysql_query( + conn, + "SELECT priority, frontend_entity, backend_entity, comment FROM mysql_ldap_mapping" + ); + + if (rc_query == 0) { + MYSQL_RES *result = mysql_store_result(conn); + GloAdmin->admindb->execute("DELETE FROM mysql_ldap_mapping"); + MYSQL_ROW row; + char* q = const_cast( + "INSERT INTO mysql_ldap_mapping (priority, frontend_entity, backend_entity, comment)" + " VALUES (?1 , ?2 , ?3 , ?4)" + ); + sqlite3_stmt *statement1 = NULL; + rc = GloAdmin->admindb->prepare_v2(q, &statement1); + ASSERT_SQLITE_OK(rc, GloAdmin->admindb); + + while ((row = mysql_fetch_row(result))) { + rc=(*proxy_sqlite3_bind_int64)(statement1, 1, atoll(row[0])); ASSERT_SQLITE_OK(rc, GloAdmin->admindb); // priority + rc=(*proxy_sqlite3_bind_text)(statement1, 2, row[1], -1, SQLITE_TRANSIENT); ASSERT_SQLITE_OK(rc, GloAdmin->admindb); // frontend_entity + rc=(*proxy_sqlite3_bind_text)(statement1, 3, row[2], -1, SQLITE_TRANSIENT); ASSERT_SQLITE_OK(rc, GloAdmin->admindb); // backend_entity + rc=(*proxy_sqlite3_bind_text)(statement1, 4, row[3], -1, SQLITE_TRANSIENT); ASSERT_SQLITE_OK(rc, GloAdmin->admindb); // comment + + SAFE_SQLITE3_STEP2(statement1); + rc=(*proxy_sqlite3_clear_bindings)(statement1); ASSERT_SQLITE_OK(rc, GloAdmin->admindb); + rc=(*proxy_sqlite3_reset)(statement1); ASSERT_SQLITE_OK(rc, GloAdmin->admindb); + } + + mysql_free_result(result); + proxy_info("Cluster: Fetching LDAP Mappings from peer %s:%d completed\n", hostname, port); + proxy_info("Cluster: Loading to runtime LDAP Mappings from peer %s:%d\n", hostname, port); + GloAdmin->init_users(); + + if (GloProxyCluster->cluster_mysql_users_save_to_disk == true) { + proxy_info("Cluster: Saving to disk LDAP Mappings from peer %s:%d\n", hostname, port); + GloAdmin->flush_mysql_users__from_memory_to_disk(); + } else { + proxy_info("Cluster: Saving to disk LDAP Mappings Rules from peer %s:%d\n", hostname, port); + } + + metrics.p_counter_array[p_cluster_counter::pulled_mysql_ldap_mapping_success]->Increment(); + } else { + proxy_info("Cluster: Fetching LDAP Mappings from peer %s:%d failed: %s\n", hostname, port, mysql_error(conn)); + metrics.p_counter_array[p_cluster_counter::pulled_mysql_ldap_mapping_failure]->Increment(); + } + } } else { proxy_info("Cluster: Fetching MySQL Users from peer %s:%d failed: %s\n", hostname, port, mysql_error(conn)); - metrics.p_counter_array[p_cluster_counter::pulled_mysql_users_failure]->Increment(); + metrics.p_counter_array[p_cluster_counter::pulled_mysql_ldap_mapping_failure]->Increment(); } } __exit_pull_mysql_users_from_peer: @@ -2592,6 +2640,26 @@ cluster_metrics_map = std::make_tuple( } ), + // mysql_ldap_mappings_* + std::make_tuple ( + p_cluster_counter::pulled_mysql_ldap_mapping_success, + "proxysql_cluster_pulled_total", + "Number of times a 'module' have been pulled from a peer.", + metric_tags { + { "module_name", "mysql_ldap_mapping" }, + { "status", "success" } + } + ), + std::make_tuple ( + p_cluster_counter::pulled_mysql_ldap_mapping_failure, + "proxysql_cluster_pulled_total", + "Number of times a 'module' have been pulled from a peer.", + metric_tags { + { "module_name", "mysql_ldap_mapping" }, + { "status", "failure" } + } + ), + // sync_conflict same epoch // ==================================================================== std::make_tuple ( From f1b3687f5d34ab925d73d15a660c2a82d5f7e727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Tue, 27 Apr 2021 09:28:25 +0200 Subject: [PATCH 03/17] Fixed typo using 'cluster_mysql_query_rules_save_to_disk' instead of 'cluster_mysql_users_save_to_disk' in 'pull_mysql_users_from_peer' --- lib/ProxySQL_Cluster.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ProxySQL_Cluster.cpp b/lib/ProxySQL_Cluster.cpp index e47f4011c..ec438f0b5 100644 --- a/lib/ProxySQL_Cluster.cpp +++ b/lib/ProxySQL_Cluster.cpp @@ -1001,7 +1001,7 @@ void ProxySQL_Cluster::pull_mysql_users_from_peer() { proxy_info("Cluster: Fetching MySQL Users from peer %s:%d completed\n", hostname, port); proxy_info("Cluster: Loading to runtime MySQL Users from peer %s:%d\n", hostname, port); GloAdmin->init_users(); - if (GloProxyCluster->cluster_mysql_query_rules_save_to_disk == true) { + if (GloProxyCluster->cluster_mysql_users_save_to_disk == true) { proxy_info("Cluster: Saving to disk MySQL Users from peer %s:%d\n", hostname, port); GloAdmin->flush_mysql_users__from_memory_to_disk(); } else { From 00c6f17f80f4c1746198d8ce6aa9c96bd9584b45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Tue, 27 Apr 2021 10:20:11 +0200 Subject: [PATCH 04/17] Fixed 'sqlite3-t.cpp' compilation after addition of 'GloMyLdapAuth' to 'ProxySQL_GloVars' --- test/tap/tests/sqlite3-t.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/tap/tests/sqlite3-t.cpp b/test/tap/tests/sqlite3-t.cpp index 010bc6686..a15a9e857 100644 --- a/test/tap/tests/sqlite3-t.cpp +++ b/test/tap/tests/sqlite3-t.cpp @@ -6,9 +6,12 @@ #include #include #include + #include "proxysql_structs.h" -#include "proxysql_glovars.hpp" #include "sqlite3db.h" +#include "MySQL_LDAP_Authentication.hpp" + +MySQL_LDAP_Authentication* GloMyLdapAuth = nullptr; int main() { SQLite3DB::LoadPlugin(NULL); From 4027d8cd0e1ebac1a8713d81543e6ddd911e6410 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Mon, 10 May 2021 20:28:35 +0200 Subject: [PATCH 05/17] Temporarily added 'session_track_schema' to the list of ignored variables #3442 --- lib/MySQL_Variables.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/MySQL_Variables.cpp b/lib/MySQL_Variables.cpp index f3f9660a5..875864dd8 100644 --- a/lib/MySQL_Variables.cpp +++ b/lib/MySQL_Variables.cpp @@ -24,6 +24,8 @@ MySQL_Variables::MySQL_Variables() { ignore_vars.push_back("interactive_timeout"); ignore_vars.push_back("wait_timeout"); ignore_vars.push_back("net_read_timeout"); + // NOTE: This variable has been temporarily ignored. Check issues #3442 and #3441. + ignore_vars.push_back("session_track_schema"); variables_regexp = ""; for (auto i = 0; i < SQL_NAME_LAST; i++) { if (i == SQL_CHARACTER_SET || i == SQL_CHARACTER_ACTION || i == SQL_SET_NAMES) { From 2a74ff804ee6aa018a4c698f7688f815e2c81481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Mon, 10 May 2021 20:30:23 +0200 Subject: [PATCH 06/17] Added temporarily ignored 'session_track_schema' variable to 'test_filtered_set_statements-t.cpp' test #3442 --- test/tap/tests/test_filtered_set_statements-t.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/tap/tests/test_filtered_set_statements-t.cpp b/test/tap/tests/test_filtered_set_statements-t.cpp index 99fee1976..bb8bc2b21 100644 --- a/test/tap/tests/test_filtered_set_statements-t.cpp +++ b/test/tap/tests/test_filtered_set_statements-t.cpp @@ -46,6 +46,8 @@ std::vector> filtered_set_queries { { "session_track_gtids", "OWN_GTID" }, { "interactive_timeout", "param" }, { "net_read_timeout", "param" }, + // NOTE: This variable has been temporarily ignored. Check issues #3442 and #3441. + { "session_track_schema", "1" }, }; std::vector get_valid_set_query_set(const std::string& set_query, const std::string param) { From 57fd24c2d664d7aa20fb13a2d370f5f25ff4e3c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Tue, 11 May 2021 00:07:33 +0200 Subject: [PATCH 07/17] Several code cleanup in MySQL_Thread --- include/MySQL_Thread.h | 11 +- lib/MySQL_Thread.cpp | 458 ++++++++++++++++++++++------------------- 2 files changed, 258 insertions(+), 211 deletions(-) diff --git a/include/MySQL_Thread.h b/include/MySQL_Thread.h index d158497e3..5ef87aec6 100644 --- a/include/MySQL_Thread.h +++ b/include/MySQL_Thread.h @@ -216,14 +216,21 @@ class MySQL_Thread ~MySQL_Thread(); MySQL_Session * create_new_session_and_client_data_stream(int _fd); bool init(); - void run(); + void run___get_multiple_idle_connections(int& num_idles); + void run___cleanup_mirror_queue(); + void ProcessAllMyDS_BeforePoll(); + void ProcessAllMyDS_AfterPoll(); + void run(); void poll_listener_add(int sock); void poll_listener_del(int sock); void register_session(MySQL_Session*, bool up_start=true); void unregister_session(int); struct pollfd * get_pollfd(unsigned int i); bool process_data_on_data_stream(MySQL_Data_Stream *myds, unsigned int n); - void process_all_sessions(); + void ProcessAllSessions_SortingSessions(); + void ProcessAllSessions_CompletedMirrorSession(unsigned int& n, MySQL_Session *sess); + void ProcessAllSessions_MaintenanceLoop(MySQL_Session *sess, unsigned long long sess_time, unsigned int& total_active_transactions_); + void process_all_sessions(); void refresh_variables(); void register_session_connection_handler(MySQL_Session *_sess, bool _new=false); void unregister_session_connection_handler(int idx, bool _new=false); diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index 4bb97ef23..c46949980 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -4091,6 +4091,128 @@ void MySQL_Thread::unregister_session(int idx) { } +// this function was inline in MySQL_Thread::run() +void MySQL_Thread::run___get_multiple_idle_connections(int& num_idles) { + int rc; + int i; + num_idles=MyHGM->get_multiple_idle_connections(-1, curtime-mysql_thread___ping_interval_server_msec*1000, my_idle_conns, SESSIONS_FOR_CONNECTIONS_HANDLER); + for (i=0; imybe=sess->find_or_create_backend(mc->parent->myhgc->hid); + + myds=sess->mybe->server_myds; + myds->attach_connection(mc); + myds->assign_fd_from_mysql_conn(); + myds->myds_type=MYDS_BACKEND; + + sess->to_process=1; + myds->wait_until=curtime+mysql_thread___ping_timeout_server*1000; // max_timeout + mc->last_time_used=curtime; + myds->myprot.init(&myds, myds->myconn->userinfo, NULL); + sess->status=PINGING_SERVER; + myds->DSS=STATE_MARIADB_PING; + register_session_connection_handler(sess,true); + int rc=sess->handler(); + if (rc==-1) { + unsigned int sess_idx=mysql_sessions->len-1; + unregister_session(sess_idx); + delete sess; + } + } + processing_idles=true; + last_processing_idles=curtime; +} + +// this function was inline in MySQL_Thread::run() +void MySQL_Thread::ProcessAllMyDS_BeforePoll() { + unsigned int n; + for (n = 0; n < mypolls.len; n++) { + MySQL_Data_Stream *myds=NULL; + myds=mypolls.myds[n]; + mypolls.fds[n].revents=0; + if (myds) { +#ifdef IDLE_THREADS + if (GloVars.global.idle_threads) { + // here we try to move it to the maintenance thread + if (myds->myds_type==MYDS_FRONTEND && myds->sess) { + if (myds->DSS==STATE_SLEEP && myds->sess->status==WAITING_CLIENT_DATA) { + if (move_session_to_idle_mysql_sessions(myds, n)) { + n--; // compensate mypolls.remove_index_fast(n) and n++ of loop + continue; + } + } + } + } +#endif // IDLE_THREADS + if (unlikely(myds->wait_until)) { + tune_timeout_for_myds_needs_pause(myds); + } + if (myds->sess) { + if (unlikely(myds->sess->pause_until > 0)) { + tune_timeout_for_session_needs_pause(myds); + } + } + myds->revents=0; + if (myds->myds_type!=MYDS_LISTENER) { + configure_pollout(myds, n); + } + } + proxy_debug(PROXY_DEBUG_NET,1,"Poll for DataStream=%p will be called with FD=%d and events=%d\n", mypolls.myds[n], mypolls.fds[n].fd, mypolls.fds[n].events); + } +} + + +// this function was inline in MySQL_Thread::run() +void MySQL_Thread::ProcessAllMyDS_AfterPoll() { + int rc; + for (unsigned int n = 0; n < mypolls.len; n++) { + proxy_debug(PROXY_DEBUG_NET,3, "poll for fd %d events %d revents %d\n", mypolls.fds[n].fd , mypolls.fds[n].events, mypolls.fds[n].revents); + + MySQL_Data_Stream *myds=mypolls.myds[n]; + if (myds==NULL) { + read_one_byte_from_pipe(n); + continue; + } + if (mypolls.fds[n].revents==0) { + if (poll_timeout_bool) { + check_timing_out_session(n); + } + } else { + check_for_invalid_fd(n); // this is designed to assert in case of failure + switch(myds->myds_type) { + // Note: this logic that was here was removed completely because we added mariadb client library. + case MYDS_LISTENER: + // we got a new connection! + listener_handle_new_connection(myds,n); + continue; + break; + default: + break; + } + // data on exiting connection + bool rc=process_data_on_data_stream(myds, n); + if (rc==false) { + n--; + } + } + } +} + + +// this function was inline in MySQL_Thread::run() +void MySQL_Thread::run___cleanup_mirror_queue() { + unsigned int l = (unsigned int)mysql_thread___mirror_max_concurrency; + if (mirror_queue_mysql_sessions_cache->len > l) { + while (mirror_queue_mysql_sessions_cache->len > mirror_queue_mysql_sessions->len && mirror_queue_mysql_sessions_cache->len > l) { + MySQL_Session *newsess=(MySQL_Session *)mirror_queue_mysql_sessions_cache->remove_index_fast(0); + __sync_add_and_fetch(&GloMTH->status_variables.mirror_sessions_current,1); + GloMTH->status_variables.p_gauge_array[p_th_gauge::mirror_concurrency]->Increment(); + delete newsess; + } + } +} // main loop void MySQL_Thread::run() { @@ -4130,35 +4252,7 @@ void MySQL_Thread::run() { processing_idles=false; } if (processing_idles==false && (last_processing_idles < curtime-mysql_thread___ping_interval_server_msec*1000) ) { - int i; - num_idles=MyHGM->get_multiple_idle_connections(-1, curtime-mysql_thread___ping_interval_server_msec*1000, my_idle_conns, SESSIONS_FOR_CONNECTIONS_HANDLER); - for (i=0; imybe=sess->find_or_create_backend(mc->parent->myhgc->hid); - - myds=sess->mybe->server_myds; - myds->attach_connection(mc); - myds->assign_fd_from_mysql_conn(); - myds->myds_type=MYDS_BACKEND; - - sess->to_process=1; - myds->wait_until=curtime+mysql_thread___ping_timeout_server*1000; // max_timeout - mc->last_time_used=curtime; - myds->myprot.init(&myds, myds->myconn->userinfo, NULL); - sess->status=PINGING_SERVER; - myds->DSS=STATE_MARIADB_PING; - register_session_connection_handler(sess,true); - int rc=sess->handler(); - if (rc==-1) { - unsigned int sess_idx=mysql_sessions->len-1; - unregister_session(sess_idx); - delete sess; - } - } - processing_idles=true; - last_processing_idles=curtime; + run___get_multiple_idle_connections(num_idles); } #ifdef IDLE_THREADS @@ -4172,39 +4266,7 @@ __run_skip_1: handle_mirror_queue_mysql_sessions(); - for (n = 0; n < mypolls.len; n++) { - MySQL_Data_Stream *myds=NULL; - myds=mypolls.myds[n]; - mypolls.fds[n].revents=0; - if (myds) { -#ifdef IDLE_THREADS - if (GloVars.global.idle_threads) { - // here we try to move it to the maintenance thread - if (myds->myds_type==MYDS_FRONTEND && myds->sess) { - if (myds->DSS==STATE_SLEEP && myds->sess->status==WAITING_CLIENT_DATA) { - if (move_session_to_idle_mysql_sessions(myds, n)) { - n--; // compensate mypolls.remove_index_fast(n) and n++ of loop - continue; - } - } - } - } -#endif // IDLE_THREADS - if (unlikely(myds->wait_until)) { - tune_timeout_for_myds_needs_pause(myds); - } - if (myds->sess) { - if (unlikely(myds->sess->pause_until > 0)) { - tune_timeout_for_session_needs_pause(myds); - } - } - myds->revents=0; - if (myds->myds_type!=MYDS_LISTENER) { - configure_pollout(myds, n); - } - } - proxy_debug(PROXY_DEBUG_NET,1,"Poll for DataStream=%p will be called with FD=%d and events=%d\n", mypolls.myds[n], mypolls.fds[n].fd, mypolls.fds[n].events); - } + ProcessAllMyDS_BeforePoll(); #ifdef IDLE_THREADS if (GloVars.global.idle_threads) { @@ -4310,15 +4372,7 @@ __run_skip_1a: if (maintenance_loop) { // house keeping - unsigned int l = (unsigned int)mysql_thread___mirror_max_concurrency; - if (mirror_queue_mysql_sessions_cache->len > l) { - while (mirror_queue_mysql_sessions_cache->len > mirror_queue_mysql_sessions->len && mirror_queue_mysql_sessions_cache->len > l) { - MySQL_Session *newsess=(MySQL_Session *)mirror_queue_mysql_sessions_cache->remove_index_fast(0); - __sync_add_and_fetch(&GloMTH->status_variables.mirror_sessions_current,1); - GloMTH->status_variables.p_gauge_array[p_th_gauge::mirror_concurrency]->Increment(); - delete newsess; - } - } + run___cleanup_mirror_queue(); GloQPro->update_query_processor_stats(); } @@ -4375,37 +4429,7 @@ __run_skip_1a: } #endif // IDLE_THREADS - for (n = 0; n < mypolls.len; n++) { - proxy_debug(PROXY_DEBUG_NET,3, "poll for fd %d events %d revents %d\n", mypolls.fds[n].fd , mypolls.fds[n].events, mypolls.fds[n].revents); - - MySQL_Data_Stream *myds=mypolls.myds[n]; - if (myds==NULL) { - read_one_byte_from_pipe(n); - continue; - } - if (mypolls.fds[n].revents==0) { - if (poll_timeout_bool) { - check_timing_out_session(n); - } - } else { - check_for_invalid_fd(n); // this is designed to assert in case of failure - switch(myds->myds_type) { - // Note: this logic that was here was removed completely because we added mariadb client library. - case MYDS_LISTENER: - // we got a new connection! - listener_handle_new_connection(myds,n); - continue; - break; - default: - break; - } - // data on exiting connection - bool rc=process_data_on_data_stream(myds, n); - if (rc==false) { - n--; - } - } - } + ProcessAllMyDS_AfterPoll(); #ifdef IDLE_THREADS __run_skip_2: @@ -4709,6 +4733,126 @@ bool MySQL_Thread::process_data_on_data_stream(MySQL_Data_Stream *myds, unsigned } + +// this function was inline in MySQL_Thread::process_all_sessions() +void MySQL_Thread::ProcessAllSessions_SortingSessions() { + unsigned int a=0; + for (unsigned int n=0; nlen; n++) { + MySQL_Session *sess=(MySQL_Session *)mysql_sessions->index(n); + if (sess->mybe && sess->mybe->server_myds) { + if (sess->mybe->server_myds->max_connect_time) { + MySQL_Session *sess2=(MySQL_Session *)mysql_sessions->index(a); + if (sess2->mybe && sess2->mybe->server_myds && sess2->mybe->server_myds->max_connect_time && sess2->mybe->server_myds->max_connect_time <= sess->mybe->server_myds->max_connect_time) { + // do nothing + } else { + void *p=mysql_sessions->pdata[a]; + mysql_sessions->pdata[a]=mysql_sessions->pdata[n]; + mysql_sessions->pdata[n]=p; + a++; + } + } + } + } +} + +// this function was inline in MySQL_Thread::process_all_sessions() +void MySQL_Thread::ProcessAllSessions_CompletedMirrorSession(unsigned int& n, MySQL_Session *sess) { + unregister_session(n); + n--; + unsigned int l = (unsigned int)mysql_thread___mirror_max_concurrency; + if (mirror_queue_mysql_sessions->len*0.3 > l) l=mirror_queue_mysql_sessions->len*0.3; + if (mirror_queue_mysql_sessions_cache->len <= l) { + bool to_cache=true; + if (sess->mybe) { + if (sess->mybe->server_myds) { + to_cache=false; + } + } + if (to_cache) { + __sync_sub_and_fetch(&GloMTH->status_variables.mirror_sessions_current,1); + GloMTH->status_variables.p_gauge_array[p_th_gauge::mirror_concurrency]->Decrement(); + mirror_queue_mysql_sessions_cache->add(sess); + } else { + delete sess; + } + } else { + delete sess; + } +} + + +// this function was inline in MySQL_Thread::process_all_sessions() +void MySQL_Thread::ProcessAllSessions_MaintenanceLoop(MySQL_Session *sess, unsigned long long sess_time, unsigned int& total_active_transactions_) { + unsigned int numTrx=0; + sess->active_transactions=sess->NumActiveTransactions(); + { + unsigned long long sess_active_transactions = sess->active_transactions; + sess->active_transactions=sess->NumActiveTransactions(); + // in case we detected a new transaction just now + if (sess->active_transactions == 0) { + sess->transaction_started_at = 0; + } else { + if (sess_active_transactions == 0) { + sess->transaction_started_at = curtime; + } + } + } + total_active_transactions_ += sess->active_transactions; + sess->to_process=1; + if ( (sess_time/1000 > (unsigned long long)mysql_thread___max_transaction_idle_time) || (sess_time/1000 > (unsigned long long)mysql_thread___wait_timeout) ) { + //numTrx = sess->NumActiveTransactions(); + numTrx = sess->active_transactions; + if (numTrx) { + // the session has idle transactions, kill it + if (sess_time/1000 > (unsigned long long)mysql_thread___max_transaction_idle_time) { + sess->killed=true; + if (sess->client_myds) { + proxy_warning("Killing client connection %s:%d because of (possible) transaction idle for %llums\n",sess->client_myds->addr.addr,sess->client_myds->addr.port, sess_time/1000); + } + } + } else { + // the session is idle, kill it + if (sess_time/1000 > (unsigned long long)mysql_thread___wait_timeout) { + sess->killed=true; + if (sess->client_myds) { + proxy_warning("Killing client connection %s:%d because inactive for %llums\n",sess->client_myds->addr.addr,sess->client_myds->addr.port, sess_time/1000); + } + } + } + } else { + if (sess->active_transactions > 0) { + // here is all the logic related to max_transaction_time + unsigned long long trx_started = sess->transaction_started_at; + if (trx_started > 0 && curtime > trx_started) { + unsigned long long trx_time = curtime - trx_started; + unsigned long long trx_time_ms = trx_time/1000; + if (trx_time_ms > (unsigned long long)mysql_thread___max_transaction_time) { + sess->killed=true; + if (sess->client_myds) { + proxy_warning("Killing client connection %s:%d because of (possible) transaction running for %llums\n",sess->client_myds->addr.addr,sess->client_myds->addr.port, trx_time_ms); + } + } + } + } + } + if (servers_table_version_current != servers_table_version_previous) { // bug fix for #1085 + // Immediatelly kill all client connections using an OFFLINE node when session_fast_forward == true + if (sess->session_fast_forward) { + if (sess->HasOfflineBackends()) { + sess->killed=true; + proxy_warning("Killing client connection %s:%d due to 'session_fast_forward' and offline backends\n", sess->client_myds->addr.addr, sess->client_myds->addr.port); + } + } else { + // Search for connections that should be terminated, and simulate data in them + // the following 2 lines of code replace the previous 2 lines + // instead of killing the sessions, fails the backend connections + if (sess->SetEventInOfflineBackends()) { + sess->to_process=1; + } + } + } +} + void MySQL_Thread::process_all_sessions() { unsigned int n; unsigned int total_active_transactions_=0; @@ -4723,23 +4867,7 @@ void MySQL_Thread::process_all_sessions() { } #endif // IDLE_THREADS if (sess_sort && mysql_sessions->len > 3) { - unsigned int a=0; - for (n=0; nlen; n++) { - MySQL_Session *sess=(MySQL_Session *)mysql_sessions->index(n); - if (sess->mybe && sess->mybe->server_myds) { - if (sess->mybe->server_myds->max_connect_time) { - MySQL_Session *sess2=(MySQL_Session *)mysql_sessions->index(a); - if (sess2->mybe && sess2->mybe->server_myds && sess2->mybe->server_myds->max_connect_time && sess2->mybe->server_myds->max_connect_time <= sess->mybe->server_myds->max_connect_time) { - // do nothing - } else { - void *p=mysql_sessions->pdata[a]; - mysql_sessions->pdata[a]=mysql_sessions->pdata[n]; - mysql_sessions->pdata[n]=p; - a++; - } - } - } - } + ProcessAllSessions_SortingSessions(); } for (n=0; nlen; n++) { MySQL_Session *sess=(MySQL_Session *)mysql_sessions->index(n); @@ -4750,27 +4878,7 @@ void MySQL_Thread::process_all_sessions() { #endif if (sess->mirror==true) { // this is a mirror session if (sess->status==WAITING_CLIENT_DATA) { // the mirror session has completed - unregister_session(n); - n--; - unsigned int l = (unsigned int)mysql_thread___mirror_max_concurrency; - if (mirror_queue_mysql_sessions->len*0.3 > l) l=mirror_queue_mysql_sessions->len*0.3; - if (mirror_queue_mysql_sessions_cache->len <= l) { - bool to_cache=true; - if (sess->mybe) { - if (sess->mybe->server_myds) { - to_cache=false; - } - } - if (to_cache) { - __sync_sub_and_fetch(&GloMTH->status_variables.mirror_sessions_current,1); - GloMTH->status_variables.p_gauge_array[p_th_gauge::mirror_concurrency]->Decrement(); - mirror_queue_mysql_sessions_cache->add(sess); - } else { - delete sess; - } - } else { - delete sess; - } + ProcessAllSessions_CompletedMirrorSession(n, sess); continue; } } @@ -4782,80 +4890,12 @@ void MySQL_Thread::process_all_sessions() { } } if (maintenance_loop) { - unsigned int numTrx=0; unsigned long long sess_time = sess->IdleTime(); #ifdef IDLE_THREADS if (idle_maintenance_thread==false) #endif // IDLE_THREADS { - sess->active_transactions=sess->NumActiveTransactions(); - { - unsigned long long sess_active_transactions = sess->active_transactions; - sess->active_transactions=sess->NumActiveTransactions(); - // in case we detected a new transaction just now - if (sess->active_transactions == 0) { - sess->transaction_started_at = 0; - } else { - if (sess_active_transactions == 0) { - sess->transaction_started_at = curtime; - } - } - } - total_active_transactions_ += sess->active_transactions; - sess->to_process=1; - if ( (sess_time/1000 > (unsigned long long)mysql_thread___max_transaction_idle_time) || (sess_time/1000 > (unsigned long long)mysql_thread___wait_timeout) ) { - //numTrx = sess->NumActiveTransactions(); - numTrx = sess->active_transactions; - if (numTrx) { - // the session has idle transactions, kill it - if (sess_time/1000 > (unsigned long long)mysql_thread___max_transaction_idle_time) { - sess->killed=true; - if (sess->client_myds) { - proxy_warning("Killing client connection %s:%d because of (possible) transaction idle for %llums\n",sess->client_myds->addr.addr,sess->client_myds->addr.port, sess_time/1000); - } - } - } else { - // the session is idle, kill it - if (sess_time/1000 > (unsigned long long)mysql_thread___wait_timeout) { - sess->killed=true; - if (sess->client_myds) { - proxy_warning("Killing client connection %s:%d because inactive for %llums\n",sess->client_myds->addr.addr,sess->client_myds->addr.port, sess_time/1000); - } - } - } - } else { - if (sess->active_transactions > 0) { - // here is all the logic related to max_transaction_time - unsigned long long trx_started = sess->transaction_started_at; - if (trx_started > 0 && curtime > trx_started) { - unsigned long long trx_time = curtime - trx_started; - unsigned long long trx_time_ms = trx_time/1000; - if (trx_time_ms > (unsigned long long)mysql_thread___max_transaction_time) { - sess->killed=true; - if (sess->client_myds) { - proxy_warning("Killing client connection %s:%d because of (possible) transaction running for %llums\n",sess->client_myds->addr.addr,sess->client_myds->addr.port, trx_time_ms); - } - } - } - } - } - if (servers_table_version_current != servers_table_version_previous) { // bug fix for #1085 - // Immediatelly kill all client connections using an OFFLINE node when session_fast_forward == true - if (sess->session_fast_forward) { - if (sess->HasOfflineBackends()) { - sess->killed=true; - proxy_warning("Killing client connection %s:%d due to 'session_fast_forward' and offline backends\n", sess->client_myds->addr.addr, sess->client_myds->addr.port); - } - } - else { - // Search for connections that should be terminated, and simulate data in them - // the following 2 lines of code replace the previous 2 lines - // instead of killing the sessions, fails the backend connections - if (sess->SetEventInOfflineBackends()) { - sess->to_process=1; - } - } - } + ProcessAllSessions_MaintenanceLoop(sess, sess_time, total_active_transactions_); } #ifdef IDLE_THREADS else From eb8dc23dad7a89f5311e50470ccdb474523ca9a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Tue, 11 May 2021 01:55:57 +0200 Subject: [PATCH 08/17] Code cleanup for MySQL variables --- include/MySQL_Thread.h | 8 + lib/MySQL_Thread.cpp | 465 ++++++++--------------------------------- 2 files changed, 97 insertions(+), 376 deletions(-) diff --git a/include/MySQL_Thread.h b/include/MySQL_Thread.h index d158497e3..27e285b71 100644 --- a/include/MySQL_Thread.h +++ b/include/MySQL_Thread.h @@ -361,6 +361,14 @@ class MySQL_Threads_Handler pthread_rwlock_t rwlock; PtrArray *bind_fds; MySQL_Listeners_Manager *MLM; + // VariablesPointers_int stores: + // key: variable name + // tuple: + // variable address + // min value + // max value + // special variable : if true, min and max values are ignored, and further input validation is required + std::unordered_map> VariablesPointers_int; public: struct { int monitor_history; diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index 4bb97ef23..c9d1c5a45 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -1365,45 +1365,38 @@ unsigned int MySQL_Threads_Handler::get_variable_uint(char *name) { } int MySQL_Threads_Handler::get_variable_int(const char *name) { + + if (!strcasecmp(name,"max_transaction_idle_time")) { + PROXY_TRACE(); + } + // convert name to string, and lowercase + std::string nameS = string(name); + std::transform(nameS.begin(), nameS.end(), nameS.begin(), [](unsigned char c){ return std::tolower(c); }); + { + std::unordered_map>::const_iterator it = VariablesPointers_int.find(nameS); + if (it != VariablesPointers_int.end()) { + int * v = std::get<0>(it->second); + return *v; + } + } + + //VALGRIND_DISABLE_ERROR_REPORTING; if (name[0]=='m' && (strncmp(name,"monitor_",8)==0)) { char a = name[8]; - if (a == 'r') { - if (!strcmp(name,"monitor_read_only_interval")) return (int)variables.monitor_read_only_interval; - if (!strcmp(name,"monitor_read_only_timeout")) return (int)variables.monitor_read_only_timeout; - if (!strcmp(name,"monitor_read_only_max_timeout_count")) return (int)variables.monitor_read_only_max_timeout_count; - if (!strcmp(name,"monitor_replication_lag_interval")) return (int)variables.monitor_replication_lag_interval; - if (!strcmp(name,"monitor_replication_lag_timeout")) return (int)variables.monitor_replication_lag_timeout; - if (!strcmp(name,"monitor_replication_lag_count")) return (int)variables.monitor_replication_lag_count; - } if (a == 'g') { char b = name[9]; - if (b == 'r') { - if (!strcmp(name,"monitor_groupreplication_healthcheck_interval")) return (int)variables.monitor_groupreplication_healthcheck_interval; - if (!strcmp(name,"monitor_groupreplication_healthcheck_timeout")) return (int)variables.monitor_groupreplication_healthcheck_timeout; - if (!strcmp(name,"monitor_groupreplication_healthcheck_max_timeout_count")) return (int)variables.monitor_groupreplication_healthcheck_max_timeout_count; - if (!strcmp(name,"monitor_groupreplication_max_transactions_behind_count")) return (int)variables.monitor_groupreplication_max_transactions_behind_count; - } if (b == 'a') { if (!strcmp(name,"monitor_galera_healthcheck_interval")) return (int)variables.monitor_galera_healthcheck_interval; if (!strcmp(name,"monitor_galera_healthcheck_timeout")) return (int)variables.monitor_galera_healthcheck_timeout; if (!strcmp(name,"monitor_galera_healthcheck_max_timeout_count")) return (int)variables.monitor_galera_healthcheck_max_timeout_count; } } - if (a == 'p') { - if (!strcmp(name,"monitor_ping_interval")) return (int)variables.monitor_ping_interval; - if (!strcmp(name,"monitor_ping_max_failures")) return (int)variables.monitor_ping_max_failures; - if (!strcmp(name,"monitor_ping_timeout")) return (int)variables.monitor_ping_timeout; - } if (a == 't') { if (!strcmp(name,"monitor_threads_min")) return (int)variables.monitor_threads_min; if (!strcmp(name,"monitor_threads_max")) return (int)variables.monitor_threads_max; if (!strcmp(name,"monitor_threads_queue_maxsize")) return (int)variables.monitor_threads_queue_maxsize; } - if (a == 'c') { - if (!strcmp(name,"monitor_connect_interval")) return (int)variables.monitor_connect_interval; - if (!strcmp(name,"monitor_connect_timeout")) return (int)variables.monitor_connect_timeout; - } if (a == 'q') { if (!strcmp(name,"monitor_query_interval")) return (int)variables.monitor_query_interval; if (!strcmp(name,"monitor_query_timeout")) return (int)variables.monitor_query_timeout; @@ -1415,9 +1408,6 @@ int MySQL_Threads_Handler::get_variable_int(const char *name) { if (a == 'e') { if (!strcmp(name,"monitor_enabled")) return (int)variables.monitor_enabled; } - if (a == 'h') { - if (!strcmp(name,"monitor_history")) return (int)variables.monitor_history; - } if (a == 's') { if (!strcmp(name,"monitor_slave_lag_when_null")) return (int)variables.monitor_slave_lag_when_null; } @@ -1475,7 +1465,6 @@ int MySQL_Threads_Handler::get_variable_int(const char *name) { case 'h': if (!strcmp(name,"have_compress")) return (int)variables.have_compress; if (!strcmp(name,"have_ssl")) return (int)variables.have_ssl; - if (!strcmp(name,"hostgroup_manager_verbose")) return (int)variables.hostgroup_manager_verbose; break; case 'k': if (!strcmp(name,"kill_backend_connection_when_disconnect")) return (int)variables.kill_backend_connection_when_disconnect; @@ -1487,12 +1476,9 @@ int MySQL_Threads_Handler::get_variable_int(const char *name) { break; case 'm': if (name[3]=='_') { - if (!strcmp(name,"max_allowed_packet")) return (int)variables.max_allowed_packet; if (!strcmp(name,"max_connections")) return (int)variables.max_connections; if (!strcmp(name,"max_stmts_cache")) return (int)variables.max_stmts_cache; if (!strcmp(name,"max_stmts_per_connection")) return (int)variables.max_stmts_per_connection; - if (!strcmp(name,"max_transaction_idle_time")) return (int)variables.max_transaction_idle_time; - if (!strcmp(name,"max_transaction_time")) return (int)variables.max_transaction_time; if (!strcmp(name,"min_num_servers_lantency_awareness")) return (int)variables.min_num_servers_lantency_awareness; } if (!strcmp(name,"mirror_max_concurrency")) return (int)variables.mirror_max_concurrency; @@ -1513,13 +1499,10 @@ int MySQL_Threads_Handler::get_variable_int(const char *name) { if (name[6]=='d') { if (!strcmp(name,"query_digests")) return (int)variables.query_digests; if (!strcmp(name,"query_digests_lowercase")) return (int)variables.query_digests_lowercase; - if (!strcmp(name,"query_digests_max_digest_length")) return (int)variables.query_digests_max_digest_length; - if (!strcmp(name,"query_digests_max_query_length")) return (int)variables.query_digests_max_query_length; if (!strcmp(name,"query_digests_no_digits")) return (int)variables.query_digests_no_digits; if (!strcmp(name,"query_digests_normalize_digest_text")) return (int)variables.query_digests_normalize_digest_text; if (!strcmp(name,"query_digests_replace_null")) return (int)variables.query_digests_replace_null; if (!strcmp(name,"query_digests_track_hostname")) return (int)variables.query_digests_track_hostname; - if (!strcmp(name,"query_digests_grouping_limit")) return (int)variables.query_digests_grouping_limit; } if (name[6]=='p') { if (!strcmp(name,"query_processor_iterations")) return (int)variables.query_processor_iterations; @@ -1556,14 +1539,9 @@ int MySQL_Threads_Handler::get_variable_int(const char *name) { break; case 't': if (name[8] == '_') { - if (!strcmp(name,"throttle_connections_per_sec_to_hostgroup")) return (int)variables.throttle_connections_per_sec_to_hostgroup; if (!strcmp(name,"throttle_max_bytes_per_second_to_client")) return (int)variables.throttle_max_bytes_per_second_to_client; if (!strcmp(name,"throttle_ratio_server_to_client")) return (int)variables.throttle_ratio_server_to_client; } - if (name[9] == '_') { - if (!strcmp(name,"threshold_query_length")) return (int)variables.threshold_query_length; - if (!strcmp(name,"threshold_resultset_size")) return (int)variables.threshold_resultset_size; - } if (!strcmp(name,"tcp_keepalive_time")) return (int)variables.tcp_keepalive_time; break; case 'u': @@ -1587,6 +1565,20 @@ char * MySQL_Threads_Handler::get_variable(char *name) { // this is the public f //VALGRIND_DISABLE_ERROR_REPORTING; #define INTBUFSIZE 4096 char intbuf[INTBUFSIZE]; + + // convert name to string, and lowercase + std::string nameS = string(name); + std::transform(nameS.begin(), nameS.end(), nameS.begin(), [](unsigned char c){ return std::tolower(c); }); + { + std::unordered_map>::const_iterator it = VariablesPointers_int.find(nameS); + if (it != VariablesPointers_int.end()) { + int * v = std::get<0>(it->second); + sprintf(intbuf,"%d", *v); + return strdup(intbuf); + } + } + + if (!strcasecmp(name,"firewall_whitelist_errormsg")) { if (variables.firewall_whitelist_errormsg==NULL || strlen(variables.firewall_whitelist_errormsg)==0) { return NULL; @@ -1692,70 +1684,6 @@ char * MySQL_Threads_Handler::get_variable(char *name) { // this is the public f if (!strcasecmp(name,"monitor_enabled")) { return strdup((variables.monitor_enabled ? "true" : "false")); } - if (!strcasecmp(name,"monitor_history")) { - sprintf(intbuf,"%d",variables.monitor_history); - return strdup(intbuf); - } - if (!strcasecmp(name,"monitor_connect_interval")) { - sprintf(intbuf,"%d",variables.monitor_connect_interval); - return strdup(intbuf); - } - if (!strcasecmp(name,"monitor_connect_timeout")) { - sprintf(intbuf,"%d",variables.monitor_connect_timeout); - return strdup(intbuf); - } - if (!strcasecmp(name,"monitor_ping_interval")) { - sprintf(intbuf,"%d",variables.monitor_ping_interval); - return strdup(intbuf); - } - if (!strcasecmp(name,"monitor_ping_max_failures")) { - sprintf(intbuf,"%d",variables.monitor_ping_max_failures); - return strdup(intbuf); - } - if (!strcasecmp(name,"monitor_ping_timeout")) { - sprintf(intbuf,"%d",variables.monitor_ping_timeout); - return strdup(intbuf); - } - if (!strcasecmp(name,"monitor_read_only_interval")) { - sprintf(intbuf,"%d",variables.monitor_read_only_interval); - return strdup(intbuf); - } - if (!strcasecmp(name,"monitor_read_only_timeout")) { - sprintf(intbuf,"%d",variables.monitor_read_only_timeout); - return strdup(intbuf); - } - if (!strcasecmp(name,"monitor_read_only_max_timeout_count")) { - sprintf(intbuf,"%d",variables.monitor_read_only_max_timeout_count); - return strdup(intbuf); - } - if (!strcasecmp(name,"monitor_replication_lag_interval")) { - sprintf(intbuf,"%d",variables.monitor_replication_lag_interval); - return strdup(intbuf); - } - if (!strcasecmp(name,"monitor_replication_lag_timeout")) { - sprintf(intbuf,"%d",variables.monitor_replication_lag_timeout); - return strdup(intbuf); - } - if (!strcasecmp(name,"monitor_replication_lag_count")) { - sprintf(intbuf,"%d",variables.monitor_replication_lag_count); - return strdup(intbuf); - } - if (!strcasecmp(name,"monitor_groupreplication_healthcheck_interval")) { - sprintf(intbuf,"%d",variables.monitor_groupreplication_healthcheck_interval); - return strdup(intbuf); - } - if (!strcasecmp(name,"monitor_groupreplication_healthcheck_timeout")) { - sprintf(intbuf,"%d",variables.monitor_groupreplication_healthcheck_timeout); - return strdup(intbuf); - } - if (!strcasecmp(name,"monitor_groupreplication_healthcheck_max_timeout_count")) { - sprintf(intbuf,"%d",variables.monitor_groupreplication_healthcheck_max_timeout_count); - return strdup(intbuf); - } - if (!strcasecmp(name,"monitor_groupreplication_max_transactions_behind_count")) { - sprintf(intbuf,"%d",variables.monitor_groupreplication_max_transactions_behind_count); - return strdup(intbuf); - } if (!strcasecmp(name,"monitor_galera_healthcheck_interval")) { sprintf(intbuf,"%d",variables.monitor_galera_healthcheck_interval); return strdup(intbuf); @@ -1876,10 +1804,6 @@ char * MySQL_Threads_Handler::get_variable(char *name) { // this is the public f sprintf(intbuf,"%d",variables.auditlog_filesize); return strdup(intbuf); } - if (!strcasecmp(name,"max_allowed_packet")) { - sprintf(intbuf,"%d",variables.max_allowed_packet); - return strdup(intbuf); - } if (!strcasecmp(name,"tcp_keepalive_time")) { sprintf(intbuf,"%d",variables.tcp_keepalive_time); return strdup(intbuf); @@ -1905,46 +1829,10 @@ char * MySQL_Threads_Handler::get_variable(char *name) { // this is the public f if (!strcasecmp(name,"log_mysql_warnings_enabled")) { return strdup((variables.log_mysql_warnings_enabled? "true" : "false")); } - if (!strcasecmp(name,"throttle_connections_per_sec_to_hostgroup")) { - sprintf(intbuf,"%d",variables.throttle_connections_per_sec_to_hostgroup); - return strdup(intbuf); - } - if (!strcasecmp(name,"max_transaction_idle_time")) { - sprintf(intbuf,"%d",variables.max_transaction_idle_time); - return strdup(intbuf); - } - if (!strcasecmp(name,"max_transaction_time")) { - sprintf(intbuf,"%d",variables.max_transaction_time); - return strdup(intbuf); - } - if (!strcasecmp(name,"hostgroup_manager_verbose")) { - sprintf(intbuf,"%d",variables.hostgroup_manager_verbose); - return strdup(intbuf); - } if (!strcasecmp(name,"binlog_reader_connect_retry_msec")) { sprintf(intbuf,"%d",variables.binlog_reader_connect_retry_msec); return strdup(intbuf); } - if (!strcasecmp(name,"threshold_query_length")) { - sprintf(intbuf,"%d",variables.threshold_query_length); - return strdup(intbuf); - } - if (!strcasecmp(name,"threshold_resultset_size")) { - sprintf(intbuf,"%d",variables.threshold_resultset_size); - return strdup(intbuf); - } - if (!strcasecmp(name,"query_digests_max_digest_length")) { - sprintf(intbuf,"%d",variables.query_digests_max_digest_length); - return strdup(intbuf); - } - if (!strcasecmp(name,"query_digests_max_query_length")) { - sprintf(intbuf,"%d",variables.query_digests_max_query_length); - return strdup(intbuf); - } - if (!strcasecmp(name,"query_digests_grouping_limit")) { - sprintf(intbuf,"%d",variables.query_digests_grouping_limit); - return strdup(intbuf); - } if (!strcasecmp(name,"wait_timeout")) { sprintf(intbuf,"%d",variables.wait_timeout); return strdup(intbuf); @@ -2156,6 +2044,28 @@ bool MySQL_Threads_Handler::set_variable(char *name, const char *value) { // thi if (!value) return false; size_t vallen=strlen(value); + + // convert name to string, and lowercase + std::string nameS = string(name); + std::transform(nameS.begin(), nameS.end(), nameS.begin(), [](unsigned char c){ return std::tolower(c); }); + { + std::unordered_map>::const_iterator it = VariablesPointers_int.find(nameS); + if (it != VariablesPointers_int.end()) { + bool special_variable = std::get<3>(it->second); // if special_variable is true, min and max values are ignored, and more input validation is needed + if (special_variable == false) { + int intv=atoi(value); + if (intv >= std::get<1>(it->second) && intv <= std::get<2>(it->second)) { + int * v = std::get<0>(it->second); + *v = intv; + return true; + } + return false; + } else { + // we need to perform input validation + } + } + } + // monitor variables if (!strncasecmp(name,"monitor_",8)) { if (!strcasecmp(name,"monitor_username")) { @@ -2207,150 +2117,6 @@ bool MySQL_Threads_Handler::set_variable(char *name, const char *value) { // thi } return false; } - if (!strcasecmp(name,"monitor_history")) { - int intv=atoi(value); - if (intv >= 1000 && intv <= 7*24*3600*1000) { - variables.monitor_history=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"monitor_connect_interval")) { - int intv=atoi(value); - if (intv >= 100 && intv <= 7*24*3600*1000) { - variables.monitor_connect_interval=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"monitor_connect_timeout")) { - int intv=atoi(value); - if (intv >= 100 && intv <= 600*1000) { - variables.monitor_connect_timeout=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"monitor_ping_interval")) { - int intv=atoi(value); - if (intv >= 100 && intv <= 7*24*3600*1000) { - variables.monitor_ping_interval=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"monitor_ping_max_failures")) { - int intv=atoi(value); - if (intv >= 1 && intv <= 1000*1000) { - variables.monitor_ping_max_failures=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"monitor_ping_timeout")) { - int intv=atoi(value); - if (intv >= 100 && intv <= 600*1000) { - variables.monitor_ping_timeout=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"monitor_read_only_interval")) { - int intv=atoi(value); - if (intv >= 100 && intv <= 7*24*3600*1000) { - variables.monitor_read_only_interval=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"monitor_read_only_timeout")) { - int intv=atoi(value); - if (intv >= 100 && intv <= 600*1000) { - variables.monitor_read_only_timeout=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"monitor_read_only_max_timeout_count")) { - int intv=atoi(value); - if (intv >= 1 && intv <= 1000*1000) { - variables.monitor_read_only_max_timeout_count=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"monitor_replication_lag_interval")) { - int intv=atoi(value); - if (intv >= 100 && intv <= 7*24*3600*1000) { - variables.monitor_replication_lag_interval=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"monitor_replication_lag_timeout")) { - int intv=atoi(value); - if (intv >= 100 && intv <= 600*1000) { - variables.monitor_replication_lag_timeout=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"monitor_replication_lag_count")) { - int intv=atoi(value); - if (intv >= 1 && intv <= 10) { - variables.monitor_replication_lag_count=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"monitor_groupreplication_healthcheck_interval")) { - int intv=atoi(value); - if (intv >= 50 && intv <= 7*24*3600*1000) { - variables.monitor_groupreplication_healthcheck_interval=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"monitor_groupreplication_healthcheck_timeout")) { - int intv=atoi(value); - if (intv >= 50 && intv <= 600*1000) { - variables.monitor_groupreplication_healthcheck_timeout=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"monitor_groupreplication_healthcheck_max_timeout_count")) { - int intv=atoi(value); - if (intv >= 1 && intv <= 10) { - variables.monitor_groupreplication_healthcheck_max_timeout_count=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"monitor_groupreplication_max_transactions_behind_count")) { - int intv=atoi(value); - if (intv >= 1 && intv <= 10) { - variables.monitor_groupreplication_max_transactions_behind_count=intv; - return true; - } else { - return false; - } - } if (!strcasecmp(name,"monitor_galera_healthcheck_interval")) { int intv=atoi(value); if (intv >= 50 && intv <= 7*24*3600*1000) { @@ -2455,51 +2221,6 @@ bool MySQL_Threads_Handler::set_variable(char *name, const char *value) { // thi return false; } } - if (!strcasecmp(name,"max_allowed_packet")) { - int intv=atoi(value); - if (intv >= 8192 && intv <= 1024*1024*1024) { - variables.max_allowed_packet=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"max_transaction_idle_time")) { - int intv=atoi(value); - if (intv >= 1000 && intv <= 20*24*3600*1000) { - variables.max_transaction_idle_time=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"max_transaction_time")) { - int intv=atoi(value); - if (intv >= 1000 && intv <= 20*24*3600*1000) { - variables.max_transaction_time=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"throttle_connections_per_sec_to_hostgroup")) { - int intv=atoi(value); - if (intv >= 1 && intv <= 100*1000*1000) { - variables.throttle_connections_per_sec_to_hostgroup=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"hostgroup_manager_verbose")) { - int intv=atoi(value); - if (intv >= 0 && intv <= 2) { - variables.hostgroup_manager_verbose=intv; - return true; - } else { - return false; - } - } if (!strcasecmp(name,"binlog_reader_connect_retry_msec")) { int intv=atoi(value); if (intv >= 200 && intv <= 120000) { @@ -2509,51 +2230,6 @@ bool MySQL_Threads_Handler::set_variable(char *name, const char *value) { // thi return false; } } - if (!strcasecmp(name,"threshold_query_length")) { - int intv=atoi(value); - if (intv >= 1024 && intv <= 1*1024*1024*1024) { - variables.threshold_query_length=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"threshold_resultset_size")) { - int intv=atoi(value); - if (intv >= 1024 && intv <= 1*1024*1024*1024) { - variables.threshold_resultset_size=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"query_digests_max_digest_length")) { - int intv=atoi(value); - if (intv >= 16 && intv <= 1*1024*1024) { - variables.query_digests_max_digest_length=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"query_digests_max_query_length")) { - int intv=atoi(value); - if (intv >= 16 && intv <= 16*1024*1024) { - variables.query_digests_max_query_length=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"query_digests_grouping_limit")) { - int intv=atoi(value); - if (intv >= 1 && intv <= 2089) { - variables.query_digests_grouping_limit=intv; - return true; - } else { - return false; - } - } if (!strcasecmp(name,"wait_timeout")) { int intv=atoi(value); if (intv >= 0 && intv <= 20*24*3600*1000) { @@ -3612,6 +3288,43 @@ bool MySQL_Threads_Handler::set_variable(char *name, const char *value) { // thi // return variables from both mysql_thread_variables_names AND mysql_tracked_variables char ** MySQL_Threads_Handler::get_variables_list() { + + + // initialize VariablesPointers_int + // it is safe to do it here because get_variables_list() is the first function called during start time + if (VariablesPointers_int.size() == 0) { + VariablesPointers_int["max_allowed_packet"] = make_tuple(&variables.max_allowed_packet, 8192, 1024*1024*1024, false); + VariablesPointers_int["max_transaction_idle_time"] = make_tuple(&variables.max_transaction_idle_time, 1000, 20*24*3600*1000, false); + VariablesPointers_int["max_transaction_time"] = make_tuple(&variables.max_transaction_time, 1000, 20*24*3600*1000, false); + VariablesPointers_int["throttle_connections_per_sec_to_hostgroup"] = make_tuple(&variables.throttle_connections_per_sec_to_hostgroup, 1, 100*1000*1000, false); + VariablesPointers_int["hostgroup_manager_verbose"] = make_tuple(&variables.hostgroup_manager_verbose, 1, 2, false); + VariablesPointers_int["threshold_query_length"] = make_tuple(&variables.threshold_query_length, 1024, 1*1024*1024*1024, false); + VariablesPointers_int["threshold_resultset_size"] = make_tuple(&variables.threshold_resultset_size, 1024, 1*1024*1024*1024, false); + VariablesPointers_int["query_digests_max_digest_length"] = make_tuple(&variables.query_digests_max_digest_length, 16, 1*1024*1024, false); + VariablesPointers_int["query_digests_max_query_length"] = make_tuple(&variables.query_digests_max_query_length, 16, 1*1024*1024, false); + VariablesPointers_int["query_digests_grouping_limit"] = make_tuple(&variables.query_digests_grouping_limit, 1, 2089, false); + + + VariablesPointers_int["monitor_history"] = make_tuple(&variables.monitor_history, 1000, 7*24*3600*1000, false); + VariablesPointers_int["monitor_connect_interval"] = make_tuple(&variables.monitor_connect_interval, 100, 7*24*3600*1000, false); + VariablesPointers_int["monitor_connect_timeout"] = make_tuple(&variables.monitor_connect_timeout, 100, 600*1000, false); + VariablesPointers_int["monitor_ping_interval"] = make_tuple(&variables.monitor_ping_interval, 100, 7*24*3600*1000, false); + VariablesPointers_int["monitor_ping_timeout"] = make_tuple(&variables.monitor_ping_timeout, 100, 600*1000, false); + VariablesPointers_int["monitor_ping_max_failures"] = make_tuple(&variables.monitor_ping_max_failures, 1, 1000*1000, false); + VariablesPointers_int["monitor_read_only_interval"] = make_tuple(&variables.monitor_read_only_interval, 100, 7*24*3600*1000, false); + VariablesPointers_int["monitor_read_only_timeout"] = make_tuple(&variables.monitor_read_only_timeout, 100, 600*1000, false); + VariablesPointers_int["monitor_read_only_max_timeout_count"] = make_tuple(&variables.monitor_read_only_max_timeout_count, 1, 1000*1000, false); + VariablesPointers_int["monitor_replication_lag_interval"] = make_tuple(&variables.monitor_replication_lag_interval, 100, 7*24*3600*1000, false); + VariablesPointers_int["monitor_replication_lag_timeout"] = make_tuple(&variables.monitor_replication_lag_timeout, 100, 600*1000, false); + VariablesPointers_int["monitor_replication_lag_count"] = make_tuple(&variables.monitor_replication_lag_count , 1, 10, false); + + VariablesPointers_int["monitor_groupreplication_healthcheck_interval"] = make_tuple(&variables.monitor_groupreplication_healthcheck_interval, 100, 7*24*3600*1000, false); + VariablesPointers_int["monitor_groupreplication_healthcheck_timeout"] = make_tuple(&variables.monitor_groupreplication_healthcheck_timeout, 100, 600*1000, false); + VariablesPointers_int["monitor_groupreplication_healthcheck_max_timeout_count"] = make_tuple(&variables.monitor_groupreplication_healthcheck_max_timeout_count, 1, 10, false); + VariablesPointers_int["monitor_groupreplication_max_transactions_behind_count"] = make_tuple(&variables.monitor_groupreplication_max_transactions_behind_count, 1, 10, false); + } + + const size_t l=sizeof(mysql_thread_variables_names)/sizeof(char *); unsigned int i; size_t ltv = 0; From 519105bb32e85b10f59dc51d3c0858c0edfaa6dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Tue, 11 May 2021 13:19:22 +0200 Subject: [PATCH 09/17] Fixed retrieving 'mysql_ldap_mapping' from peer 'runtime' instead of 'memory' #3419 --- lib/ProxySQL_Cluster.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ProxySQL_Cluster.cpp b/lib/ProxySQL_Cluster.cpp index ec438f0b5..ae5be6813 100644 --- a/lib/ProxySQL_Cluster.cpp +++ b/lib/ProxySQL_Cluster.cpp @@ -1016,7 +1016,7 @@ void ProxySQL_Cluster::pull_mysql_users_from_peer() { if (GloMyLdapAuth) { rc_query = mysql_query( conn, - "SELECT priority, frontend_entity, backend_entity, comment FROM mysql_ldap_mapping" + "SELECT priority, frontend_entity, backend_entity, comment FROM runtime_mysql_ldap_mapping" ); if (rc_query == 0) { From 0e377c2622e28b75af68a1129e6a3271cfb16181 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Tue, 11 May 2021 13:21:37 +0200 Subject: [PATCH 10/17] Fixed typo specifying to load 'MYSQL VARIABLES' instead of correct 'LDAP VARIABLES' to runtime #3419 --- lib/ProxySQL_Cluster.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ProxySQL_Cluster.cpp b/lib/ProxySQL_Cluster.cpp index ae5be6813..b03c228e9 100644 --- a/lib/ProxySQL_Cluster.cpp +++ b/lib/ProxySQL_Cluster.cpp @@ -763,12 +763,12 @@ void ProxySQL_Node_Entry::set_checksums(MYSQL_RES *_r) { } } if ((v->epoch == own_epoch) && v->diff_check && ((v->diff_check % (diff_lv*10)) == 0)) { - proxy_error("Cluster: detected a peer %s:%d with ldap_variables 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 %llu checks until LOAD MYSQL VARIABLES 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_lv*10)); + proxy_error("Cluster: detected a peer %s:%d with ldap_variables 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 %llu checks until LOAD LDAP VARIABLES is executed on candidate master.\n", hostname, port, v->version, v->epoch, v->diff_check, v->checksum, own_version, own_epoch, own_checksum, (diff_lv*10)); GloProxyCluster->metrics.p_counter_array[p_cluster_counter::sync_conflict_ldap_variables_share_epoch]->Increment(); } } else { if (v->diff_check && (v->diff_check % (diff_lv*10)) == 0) { - proxy_warning("Cluster: detected a peer %s:%d with ldap_variables 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 %llu checks until LOAD MYSQL VARIABLES TO RUNTIME is executed on candidate master.\n", hostname, port, v->version, v->epoch, v->diff_check, own_version, own_epoch, (diff_lv*10)); + proxy_warning("Cluster: detected a peer %s:%d with ldap_variables 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 %llu checks until LOAD LDAP VARIABLES TO RUNTIME is executed on candidate master.\n", hostname, port, v->version, v->epoch, v->diff_check, own_version, own_epoch, (diff_lv*10)); GloProxyCluster->metrics.p_counter_array[p_cluster_counter::sync_delayed_ldap_variables_version_one]->Increment(); } } From 9e3d939ed3cc028542f5e8cebbca720a7eae3203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Tue, 11 May 2021 18:15:39 +0200 Subject: [PATCH 11/17] More code cleanup for MySQL variables --- include/MySQL_Thread.h | 6 + lib/MySQL_Thread.cpp | 1397 ++++++---------------------------------- 2 files changed, 202 insertions(+), 1201 deletions(-) diff --git a/include/MySQL_Thread.h b/include/MySQL_Thread.h index 27e285b71..4d56c70cd 100644 --- a/include/MySQL_Thread.h +++ b/include/MySQL_Thread.h @@ -369,6 +369,12 @@ class MySQL_Threads_Handler // max value // special variable : if true, min and max values are ignored, and further input validation is required std::unordered_map> VariablesPointers_int; + // VariablesPointers_bool stores: + // key: variable name + // tuple: + // variable address + // special variable : if true, further input validation is required + std::unordered_map> VariablesPointers_bool; public: struct { int monitor_history; diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index c9d1c5a45..2864d52a4 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -1373,146 +1373,54 @@ int MySQL_Threads_Handler::get_variable_int(const char *name) { std::string nameS = string(name); std::transform(nameS.begin(), nameS.end(), nameS.begin(), [](unsigned char c){ return std::tolower(c); }); { + // integer variable std::unordered_map>::const_iterator it = VariablesPointers_int.find(nameS); if (it != VariablesPointers_int.end()) { int * v = std::get<0>(it->second); return *v; } } + { + // bool variable + std::unordered_map>::const_iterator it = VariablesPointers_bool.find(nameS); + if (it != VariablesPointers_bool.end()) { + bool * v = std::get<0>(it->second); + int a = (int)*v; + return a; + } + } //VALGRIND_DISABLE_ERROR_REPORTING; - if (name[0]=='m' && (strncmp(name,"monitor_",8)==0)) { - char a = name[8]; - if (a == 'g') { - char b = name[9]; - if (b == 'a') { - if (!strcmp(name,"monitor_galera_healthcheck_interval")) return (int)variables.monitor_galera_healthcheck_interval; - if (!strcmp(name,"monitor_galera_healthcheck_timeout")) return (int)variables.monitor_galera_healthcheck_timeout; - if (!strcmp(name,"monitor_galera_healthcheck_max_timeout_count")) return (int)variables.monitor_galera_healthcheck_max_timeout_count; - } - } - if (a == 't') { - if (!strcmp(name,"monitor_threads_min")) return (int)variables.monitor_threads_min; - if (!strcmp(name,"monitor_threads_max")) return (int)variables.monitor_threads_max; - if (!strcmp(name,"monitor_threads_queue_maxsize")) return (int)variables.monitor_threads_queue_maxsize; - } - if (a == 'q') { - if (!strcmp(name,"monitor_query_interval")) return (int)variables.monitor_query_interval; - if (!strcmp(name,"monitor_query_timeout")) return (int)variables.monitor_query_timeout; - } - if (a == 'w') { - if (!strcmp(name,"monitor_wait_timeout")) return (int)variables.monitor_wait_timeout; - if (!strcmp(name,"monitor_writer_is_also_reader")) return (int)variables.monitor_writer_is_also_reader; - } - if (a == 'e') { - if (!strcmp(name,"monitor_enabled")) return (int)variables.monitor_enabled; - } - if (a == 's') { - if (!strcmp(name,"monitor_slave_lag_when_null")) return (int)variables.monitor_slave_lag_when_null; - } - } char a = name[0]; switch (a) { case 'a': - if (!strcmp(name,"auditlog_filesize")) return (int)variables.auditlog_filesize; if (!strcmp(name,"aurora_max_lag_ms_only_read_from_replicas")) return variables.aurora_max_lag_ms_only_read_from_replicas; - if (!strcmp(name,"auto_increment_delay_multiplex")) return (int)variables.auto_increment_delay_multiplex; - if (!strcmp(name,"autocommit_false_is_transaction")) return (int)variables.autocommit_false_is_transaction; - if (!strcmp(name,"autocommit_false_not_reusable")) return (int)variables.autocommit_false_not_reusable; - if (!strcmp(name,"automatic_detect_sqli")) return (int)variables.automatic_detect_sqli; break; case 'b': if (!strcmp(name,"binlog_reader_connect_retry_msec")) return (int)variables.binlog_reader_connect_retry_msec; break; case 'c': - if (name[1]=='l') { - if (!strcmp(name,"client_found_rows")) return (int)variables.client_found_rows; - if (!strcmp(name,"client_multi_statements")) return (int)variables.client_multi_statements; - if (!strcmp(name,"client_session_track_gtid")) return (int)variables.client_session_track_gtid; - } if (name[1]=='o') { - if (!strcmp(name,"commands_stats")) return (int)variables.commands_stats; - if (!strcmp(name,"connect_retries_delay")) return (int)variables.connect_retries_delay; - if (!strcmp(name,"connect_retries_on_failure")) return (int)variables.connect_retries_on_failure; - if (!strcmp(name,"connect_timeout_client")) return (int)variables.connect_timeout_client; - if (!strcmp(name,"connect_timeout_server")) return (int)variables.connect_timeout_server; - if (!strcmp(name,"connect_timeout_server_max")) return (int)variables.connect_timeout_server_max; - if (!strcmp(name,"connection_delay_multiplex_ms")) return (int)variables.connection_delay_multiplex_ms; - if (!strcmp(name,"connection_max_age_ms")) return (int)variables.connection_max_age_ms; - if (!strcmp(name,"connection_warming")) return (int)variables.connection_warming; if (!strcmp(name,"connpoll_reset_queue_length")) return (int)variables.connpoll_reset_queue_length; } break; - case 'd': - if (!strcmp(name,"default_max_latency_ms")) return (int)variables.default_max_latency_ms; - if (!strcmp(name,"default_query_delay")) return (int)variables.default_query_delay; - if (!strcmp(name,"default_query_timeout")) return (int)variables.default_query_timeout; - if (!strcmp(name,"default_reconnect")) return (int)variables.default_reconnect; - break; case 'e': - if (!strcmp(name,"enforce_autocommit_on_reads")) return (int)variables.enforce_autocommit_on_reads; - if (!strcmp(name,"eventslog_default_log")) return (int)variables.eventslog_default_log; - if (!strcmp(name,"eventslog_filesize")) return (int)variables.eventslog_filesize; if (!strcmp(name,"eventslog_format")) return (int)variables.eventslog_format; - if (!strcmp(name,"enable_client_deprecate_eof")) return (int)variables.enable_client_deprecate_eof; - if (!strcmp(name,"enable_server_deprecate_eof")) return (int)variables.enable_server_deprecate_eof; - break; - case 'f': - if (!strcmp(name,"free_connections_pct")) return (int)variables.free_connections_pct; - if (!strcmp(name,"firewall_whitelist_enabled")) return (int)variables.firewall_whitelist_enabled; break; case 'h': if (!strcmp(name,"have_compress")) return (int)variables.have_compress; if (!strcmp(name,"have_ssl")) return (int)variables.have_ssl; break; - case 'k': - if (!strcmp(name,"kill_backend_connection_when_disconnect")) return (int)variables.kill_backend_connection_when_disconnect; - break; - case 'l': - if (!strcmp(name,"long_query_time")) return (int)variables.long_query_time; - if (!strcmp(name,"log_unhealthy_connections")) return (int)variables.log_unhealthy_connections; - if (!strcmp(name,"log_mysql_warnings_enabled")) return (int)variables.log_mysql_warnings_enabled; - break; case 'm': if (name[3]=='_') { - if (!strcmp(name,"max_connections")) return (int)variables.max_connections; - if (!strcmp(name,"max_stmts_cache")) return (int)variables.max_stmts_cache; - if (!strcmp(name,"max_stmts_per_connection")) return (int)variables.max_stmts_per_connection; if (!strcmp(name,"min_num_servers_lantency_awareness")) return (int)variables.min_num_servers_lantency_awareness; } - if (!strcmp(name,"mirror_max_concurrency")) return (int)variables.mirror_max_concurrency; - if (!strcmp(name,"mirror_max_queue_length")) return (int)variables.mirror_max_queue_length; - if (!strcmp(name,"multiplexing")) return (int)variables.multiplexing; break; case 'p': - if (!strcmp(name,"ping_interval_server_msec")) return (int)variables.ping_interval_server_msec; - if (!strcmp(name,"ping_timeout_server")) return (int)variables.ping_timeout_server; if (!strcmp(name,"poll_timeout")) return variables.poll_timeout; if (!strcmp(name,"poll_timeout_on_failure")) return variables.poll_timeout_on_failure; break; - case 'q': - if (name[6]=='c') { - if (!strcmp(name,"query_cache_size_MB")) return (int)variables.query_cache_size_MB; - if (!strcmp(name,"query_cache_stores_empty_result")) return (int)variables.query_cache_stores_empty_result; - } - if (name[6]=='d') { - if (!strcmp(name,"query_digests")) return (int)variables.query_digests; - if (!strcmp(name,"query_digests_lowercase")) return (int)variables.query_digests_lowercase; - if (!strcmp(name,"query_digests_no_digits")) return (int)variables.query_digests_no_digits; - if (!strcmp(name,"query_digests_normalize_digest_text")) return (int)variables.query_digests_normalize_digest_text; - if (!strcmp(name,"query_digests_replace_null")) return (int)variables.query_digests_replace_null; - if (!strcmp(name,"query_digests_track_hostname")) return (int)variables.query_digests_track_hostname; - } - if (name[6]=='p') { - if (!strcmp(name,"query_processor_iterations")) return (int)variables.query_processor_iterations; - if (!strcmp(name,"query_processor_regex")) return (int)variables.query_processor_regex; - } - if (!strcmp(name,"query_retries_on_failure")) return (int)variables.query_retries_on_failure; - break; - case 'r': - if (!strcmp(name,"reset_connection_algorithm")) return (int)variables.reset_connection_algorithm; - break; case 's': if (name[1]=='e') { #ifdef DEBUG @@ -1522,34 +1430,14 @@ int MySQL_Threads_Handler::get_variable_int(const char *name) { if (!strcmp(name,"session_idle_ms")) return (int)variables.session_idle_ms; if (!strcmp(name,"session_idle_show_processlist")) return (int)variables.session_idle_show_processlist; #endif // IDLE_THREADS - if (!strcmp(name,"sessions_sort")) return (int)variables.sessions_sort; - if (!strcmp(name,"servers_stats")) return (int)variables.servers_stats; - if (!strcmp(name,"set_query_lock_on_hostgroup")) return (int)variables.set_query_lock_on_hostgroup; } if (name[1]=='h') { if (!strcmp(name,"show_processlist_extended")) return (int)variables.show_processlist_extended; - if (!strcmp(name,"shun_on_failures")) return (int)variables.shun_on_failures; - if (!strcmp(name,"shun_recovery_time_sec")) return (int)variables.shun_recovery_time_sec; } if (name[1]=='t') { if (!strcmp(name,"stacksize")) return ( stacksize ? stacksize : DEFAULT_STACK_SIZE); - if (!strcmp(name,"stats_time_backend_query")) return (int)variables.stats_time_backend_query; - if (!strcmp(name,"stats_time_query_processor")) return (int)variables.stats_time_query_processor; } break; - case 't': - if (name[8] == '_') { - if (!strcmp(name,"throttle_max_bytes_per_second_to_client")) return (int)variables.throttle_max_bytes_per_second_to_client; - if (!strcmp(name,"throttle_ratio_server_to_client")) return (int)variables.throttle_ratio_server_to_client; - } - if (!strcmp(name,"tcp_keepalive_time")) return (int)variables.tcp_keepalive_time; - break; - case 'u': - if (!strcmp(name,"use_tcp_keepalive")) return (int)variables.use_tcp_keepalive; - break; - case 'v': - if (!strcmp(name,"verbose_query_error")) return (int)variables.verbose_query_error; - break; case 'w': if (!strcmp(name,"wait_timeout")) return (int)variables.wait_timeout; break; @@ -1569,7 +1457,9 @@ char * MySQL_Threads_Handler::get_variable(char *name) { // this is the public f // convert name to string, and lowercase std::string nameS = string(name); std::transform(nameS.begin(), nameS.end(), nameS.begin(), [](unsigned char c){ return std::tolower(c); }); + { + // integer variable std::unordered_map>::const_iterator it = VariablesPointers_int.find(nameS); if (it != VariablesPointers_int.end()) { int * v = std::get<0>(it->second); @@ -1577,6 +1467,14 @@ char * MySQL_Threads_Handler::get_variable(char *name) { // this is the public f return strdup(intbuf); } } + { + // bool variable + std::unordered_map>::const_iterator it = VariablesPointers_bool.find(nameS); + if (it != VariablesPointers_bool.end()) { + bool * v = std::get<0>(it->second); + return strdup((*v ? "true" : "false")); + } + } if (!strcasecmp(name,"firewall_whitelist_errormsg")) { @@ -1681,154 +1579,25 @@ char * MySQL_Threads_Handler::get_variable(char *name) { // this is the public f if (!strcasecmp(name,"monitor_username")) return strdup(variables.monitor_username); if (!strcasecmp(name,"monitor_password")) return strdup(variables.monitor_password); if (!strcasecmp(name,"monitor_replication_lag_use_percona_heartbeat")) return strdup(variables.monitor_replication_lag_use_percona_heartbeat); - if (!strcasecmp(name,"monitor_enabled")) { - return strdup((variables.monitor_enabled ? "true" : "false")); - } - if (!strcasecmp(name,"monitor_galera_healthcheck_interval")) { - sprintf(intbuf,"%d",variables.monitor_galera_healthcheck_interval); - return strdup(intbuf); - } - if (!strcasecmp(name,"monitor_galera_healthcheck_timeout")) { - sprintf(intbuf,"%d",variables.monitor_galera_healthcheck_timeout); - return strdup(intbuf); - } - if (!strcasecmp(name,"monitor_galera_healthcheck_max_timeout_count")) { - sprintf(intbuf,"%d",variables.monitor_galera_healthcheck_max_timeout_count); - return strdup(intbuf); - } - if (!strcasecmp(name,"monitor_query_interval")) { - sprintf(intbuf,"%d",variables.monitor_query_interval); - return strdup(intbuf); - } - if (!strcasecmp(name,"monitor_query_timeout")) { - sprintf(intbuf,"%d",variables.monitor_query_timeout); - return strdup(intbuf); - } - if (!strcasecmp(name,"monitor_slave_lag_when_null")) { - sprintf(intbuf,"%d",variables.monitor_slave_lag_when_null); - return strdup(intbuf); - } - if (!strcasecmp(name,"monitor_threads_min")) { - sprintf(intbuf,"%d",variables.monitor_threads_min); - return strdup(intbuf); - } - if (!strcasecmp(name,"monitor_threads_max")) { - sprintf(intbuf,"%d",variables.monitor_threads_max); - return strdup(intbuf); - } - if (!strcasecmp(name,"monitor_threads_queue_maxsize")) { - sprintf(intbuf,"%d",variables.monitor_threads_queue_maxsize); - return strdup(intbuf); - } - if (!strcasecmp(name,"monitor_writer_is_also_reader")) { - return strdup((variables.monitor_writer_is_also_reader ? "true" : "false")); - } - if (!strcasecmp(name,"monitor_wait_timeout")) { - return strdup((variables.monitor_wait_timeout ? "true" : "false")); - } } if (!strcasecmp(name, "handle_unknown_charset")) { sprintf(intbuf, "%d",variables.handle_unknown_charset); return strdup(intbuf); } - if (!strcasecmp(name,"shun_on_failures")) { - sprintf(intbuf,"%d",variables.shun_on_failures); - return strdup(intbuf); - } - if (!strcasecmp(name,"client_multi_statements")) { - return strdup((variables.client_multi_statements ? "true" : "false")); - } if (!strcasecmp(name,"connpoll_reset_queue_length")) { sprintf(intbuf,"%d",variables.connpoll_reset_queue_length); return strdup(intbuf); } - if (!strcasecmp(name,"shun_recovery_time_sec")) { - sprintf(intbuf,"%d",variables.shun_recovery_time_sec); - return strdup(intbuf); - } - if (!strcasecmp(name,"query_retries_on_failure")) { - sprintf(intbuf,"%d",variables.query_retries_on_failure); - return strdup(intbuf); - } - if (!strcasecmp(name,"connect_retries_on_failure")) { - sprintf(intbuf,"%d",variables.connect_retries_on_failure); - return strdup(intbuf); - } - if (!strcasecmp(name,"connection_delay_multiplex_ms")) { - sprintf(intbuf,"%d",variables.connection_delay_multiplex_ms); - return strdup(intbuf); - } - if (!strcasecmp(name,"connection_max_age_ms")) { - sprintf(intbuf,"%d",variables.connection_max_age_ms); - return strdup(intbuf); - } - if (!strcasecmp(name,"connect_timeout_client")) { - sprintf(intbuf,"%d",variables.connect_timeout_client); - return strdup(intbuf); - } - if (!strcasecmp(name,"connect_timeout_server")) { - sprintf(intbuf,"%d",variables.connect_timeout_server); - return strdup(intbuf); - } - if (!strcasecmp(name,"connect_timeout_server_max")) { - sprintf(intbuf,"%d",variables.connect_timeout_server_max); - return strdup(intbuf); - } - if (!strcasecmp(name,"free_connections_pct")) { - sprintf(intbuf,"%d",variables.free_connections_pct); - return strdup(intbuf); - } #ifdef IDLE_THREADS if (!strcasecmp(name,"session_idle_ms")) { sprintf(intbuf,"%d",variables.session_idle_ms); return strdup(intbuf); } #endif // IDLE_THREADS - if (!strcasecmp(name,"connect_retries_delay")) { - sprintf(intbuf,"%d",variables.connect_retries_delay); - return strdup(intbuf); - } - if (!strcasecmp(name,"eventslog_filesize")) { - sprintf(intbuf,"%d",variables.eventslog_filesize); - return strdup(intbuf); - } - if (!strcasecmp(name,"eventslog_default_log")) { - sprintf(intbuf,"%d",variables.eventslog_default_log); - return strdup(intbuf); - } if (!strcasecmp(name,"eventslog_format")) { sprintf(intbuf,"%d",variables.eventslog_format); return strdup(intbuf); } - if (!strcasecmp(name,"auditlog_filesize")) { - sprintf(intbuf,"%d",variables.auditlog_filesize); - return strdup(intbuf); - } - if (!strcasecmp(name,"tcp_keepalive_time")) { - sprintf(intbuf,"%d",variables.tcp_keepalive_time); - return strdup(intbuf); - } - if (!strcasecmp(name,"use_tcp_keepalive")) { - sprintf(intbuf,"%d",variables.use_tcp_keepalive); - return strdup(intbuf); - } - if (!strcasecmp(name,"firewall_whitelist_enabled")) { - sprintf(intbuf,"%d",variables.firewall_whitelist_enabled); - return strdup(intbuf); - } - if (!strcasecmp(name,"automatic_detect_sqli")) { - sprintf(intbuf,"%d",variables.automatic_detect_sqli); - return strdup(intbuf); - } - if (!strcasecmp(name,"enable_client_deprecate_eof")) { - return strdup((variables.enable_client_deprecate_eof ? "true" : "false")); - } - if (!strcasecmp(name,"enable_server_deprecate_eof")) { - return strdup((variables.enable_server_deprecate_eof ? "true" : "false")); - } - if (!strcasecmp(name,"log_mysql_warnings_enabled")) { - return strdup((variables.log_mysql_warnings_enabled? "true" : "false")); - } if (!strcasecmp(name,"binlog_reader_connect_retry_msec")) { sprintf(intbuf,"%d",variables.binlog_reader_connect_retry_msec); return strdup(intbuf); @@ -1837,82 +1606,6 @@ char * MySQL_Threads_Handler::get_variable(char *name) { // this is the public f sprintf(intbuf,"%d",variables.wait_timeout); return strdup(intbuf); } - if (!strcasecmp(name,"throttle_max_bytes_per_second_to_client")) { - sprintf(intbuf,"%d",variables.throttle_max_bytes_per_second_to_client); - return strdup(intbuf); - } - if (!strcasecmp(name,"throttle_ratio_server_to_client")) { - sprintf(intbuf,"%d",variables.throttle_ratio_server_to_client); - return strdup(intbuf); - } - if (!strcasecmp(name,"max_connections")) { - sprintf(intbuf,"%d",variables.max_connections); - return strdup(intbuf); - } - if (!strcasecmp(name,"max_stmts_per_connection")) { - sprintf(intbuf,"%d",variables.max_stmts_per_connection); - return strdup(intbuf); - } - if (!strcasecmp(name,"max_stmts_cache")) { - sprintf(intbuf,"%d",variables.max_stmts_cache); - return strdup(intbuf); - } - if (!strcasecmp(name,"mirror_max_concurrency")) { - sprintf(intbuf,"%d",variables.mirror_max_concurrency); - return strdup(intbuf); - } - if (!strcasecmp(name,"mirror_max_queue_length")) { - sprintf(intbuf,"%d",variables.mirror_max_queue_length); - return strdup(intbuf); - } - if (!strcasecmp(name,"default_query_delay")) { - sprintf(intbuf,"%d",variables.default_query_delay); - return strdup(intbuf); - } - if (!strcasecmp(name,"default_query_timeout")) { - sprintf(intbuf,"%d",variables.default_query_timeout); - return strdup(intbuf); - } - if (!strcasecmp(name,"query_processor_iterations")) { - sprintf(intbuf,"%d",variables.query_processor_iterations); - return strdup(intbuf); - } - if (!strcasecmp(name,"query_processor_regex")) { - sprintf(intbuf,"%d",variables.query_processor_regex); - return strdup(intbuf); - } - if (!strcasecmp(name,"set_query_lock_on_hostgroup")) { - sprintf(intbuf,"%d",variables.set_query_lock_on_hostgroup); - return strdup(intbuf); - } - if (!strcasecmp(name,"reset_connection_algorithm")) { - sprintf(intbuf,"%d",variables.reset_connection_algorithm); - return strdup(intbuf); - } - if (!strcasecmp(name,"auto_increment_delay_multiplex")) { - sprintf(intbuf,"%d",variables.auto_increment_delay_multiplex); - return strdup(intbuf); - } - if (!strcasecmp(name,"default_max_latency_ms")) { - sprintf(intbuf,"%d",variables.default_max_latency_ms); - return strdup(intbuf); - } - if (!strcasecmp(name,"long_query_time")) { - sprintf(intbuf,"%d",variables.long_query_time); - return strdup(intbuf); - } - if (!strcasecmp(name,"query_cache_size_MB")) { - sprintf(intbuf,"%d",variables.query_cache_size_MB); - return strdup(intbuf); - } - if (!strcasecmp(name,"ping_interval_server_msec")) { - sprintf(intbuf,"%d",variables.ping_interval_server_msec); - return strdup(intbuf); - } - if (!strcasecmp(name,"ping_timeout_server")) { - sprintf(intbuf,"%d",variables.ping_timeout_server); - return strdup(intbuf); - } if (!strcasecmp(name,"poll_timeout")) { sprintf(intbuf,"%d",variables.poll_timeout); return strdup(intbuf); @@ -1948,69 +1641,6 @@ char * MySQL_Threads_Handler::get_variable(char *name) { // this is the public f if (!strcasecmp(name,"have_ssl")) { return strdup((variables.have_ssl ? "true" : "false")); } - if (!strcasecmp(name,"client_found_rows")) { - return strdup((variables.client_found_rows ? "true" : "false")); - } - if (!strcasecmp(name,"multiplexing")) { - return strdup((variables.multiplexing ? "true" : "false")); - } - if (!strcasecmp(name,"log_unhealthy_connections")) { - return strdup((variables.log_unhealthy_connections ? "true" : "false")); - } - if (!strcasecmp(name,"connection_warming")) { - return strdup((variables.connection_warming ? "true" : "false")); - } - if (!strcasecmp(name,"enforce_autocommit_on_reads")) { - return strdup((variables.enforce_autocommit_on_reads ? "true" : "false")); - } - if (!strcasecmp(name,"autocommit_false_not_reusable")) { - return strdup((variables.autocommit_false_not_reusable ? "true" : "false")); - } - if (!strcasecmp(name,"autocommit_false_is_transaction")) { - return strdup((variables.autocommit_false_is_transaction ? "true" : "false")); - } - if (!strcasecmp(name,"verbose_query_error")) { - return strdup((variables.verbose_query_error ? "true" : "false")); - } - if (!strcasecmp(name,"commands_stats")) { - return strdup((variables.commands_stats ? "true" : "false")); - } - if (!strcasecmp(name,"query_digests")) { - return strdup((variables.query_digests ? "true" : "false")); - } - if (!strcasecmp(name,"query_digests_lowercase")) { - return strdup((variables.query_digests_lowercase ? "true" : "false")); - } - if (!strcasecmp(name,"query_digests_replace_null")) { - return strdup((variables.query_digests_replace_null ? "true" : "false")); - } - if (!strcasecmp(name,"query_digests_no_digits")) { - return strdup((variables.query_digests_no_digits ? "true" : "false")); - } - if (!strcasecmp(name,"query_digests_normalize_digest_text")) { - return strdup((variables.query_digests_normalize_digest_text ? "true" : "false")); - } - if (!strcasecmp(name,"query_digests_track_hostname")) { - return strdup((variables.query_digests_track_hostname ? "true" : "false")); - } - if (!strcasecmp(name,"stats_time_backend_query")) { - return strdup((variables.stats_time_backend_query ? "true" : "false")); - } - if (!strcasecmp(name,"stats_time_query_processor")) { - return strdup((variables.stats_time_query_processor ? "true" : "false")); - } - if (!strcasecmp(name,"query_cache_stores_empty_result")) { - return strdup((variables.query_cache_stores_empty_result ? "true" : "false")); - } - if (!strcasecmp(name,"kill_backend_connection_when_disconnect")) { - return strdup((variables.kill_backend_connection_when_disconnect ? "true" : "false")); - } - if (!strcasecmp(name,"client_session_track_gtid")) { - return strdup((variables.client_session_track_gtid ? "true" : "false")); - } - if (!strcasecmp(name,"sessions_sort")) { - return strdup((variables.sessions_sort ? "true" : "false")); - } #ifdef IDLE_THREADS if (!strcasecmp(name,"session_idle_show_processlist")) { return strdup((variables.session_idle_show_processlist ? "true" : "false")); @@ -2020,12 +1650,6 @@ char * MySQL_Threads_Handler::get_variable(char *name) { // this is the public f sprintf(intbuf,"%d",variables.show_processlist_extended); return strdup(intbuf); } - if (!strcasecmp(name,"servers_stats")) { - return strdup((variables.servers_stats ? "true" : "false")); - } - if (!strcasecmp(name,"default_reconnect")) { - return strdup((variables.default_reconnect ? "true" : "false")); - } return NULL; //VALGRIND_ENABLE_ERROR_REPORTING; } @@ -2049,6 +1673,7 @@ bool MySQL_Threads_Handler::set_variable(char *name, const char *value) { // thi std::string nameS = string(name); std::transform(nameS.begin(), nameS.end(), nameS.begin(), [](unsigned char c){ return std::tolower(c); }); { + // integer variable ? std::unordered_map>::const_iterator it = VariablesPointers_int.find(nameS); if (it != VariablesPointers_int.end()) { bool special_variable = std::get<3>(it->second); // if special_variable is true, min and max values are ignored, and more input validation is needed @@ -2065,6 +1690,27 @@ bool MySQL_Threads_Handler::set_variable(char *name, const char *value) { // thi } } } + { + // boolean variable ? + std::unordered_map>::const_iterator it = VariablesPointers_bool.find(nameS); + if (it != VariablesPointers_bool.end()) { + bool special_variable = std::get<1>(it->second); // if special_variable is true, more input validation is needed + if (special_variable == false) { + bool * v = std::get<0>(it->second); + if (strcasecmp(value,"true")==0 || strcasecmp(value,"1")==0) { + *v = true; + return true; + } + if (strcasecmp(value,"false")==0 || strcasecmp(value,"0")==0) { + *v = false; + return true; + } + return false; + } else { + // we need to perform input validation + } + } + } // monitor variables if (!strncasecmp(name,"monitor_",8)) { @@ -2088,512 +1734,57 @@ bool MySQL_Threads_Handler::set_variable(char *name, const char *value) { // thi variables.monitor_replication_lag_use_percona_heartbeat=strdup((value)); return true; } else { - re2::RE2::Options *opt2=new re2::RE2::Options(RE2::Quiet); - opt2->set_case_sensitive(false); - char *patt = (char *)"`?([a-z\\d_]+)`?\\.`?([a-z\\d_]+)`?"; - RE2 *re = new RE2(patt, *opt2); - bool rc=false; - rc = RE2::FullMatch(value,*re); - delete re; - delete opt2; - if(rc) { - free(variables.monitor_replication_lag_use_percona_heartbeat); - variables.monitor_replication_lag_use_percona_heartbeat=strdup(value); - return true; - } else { - proxy_error("%s is an invalid value for %s, not matching regex \"%s\"\n", value, name, patt); - } - } - return false; - } - if (!strcasecmp(name,"monitor_enabled")) { - if (strcasecmp(value,"true")==0 || strcasecmp(value,"1")==0) { - variables.monitor_enabled=true; - return true; - } - if (strcasecmp(value,"false")==0 || strcasecmp(value,"0")==0) { - variables.monitor_enabled=false; - return true; - } - return false; - } - if (!strcasecmp(name,"monitor_galera_healthcheck_interval")) { - int intv=atoi(value); - if (intv >= 50 && intv <= 7*24*3600*1000) { - variables.monitor_galera_healthcheck_interval=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"monitor_galera_healthcheck_timeout")) { - int intv=atoi(value); - if (intv >= 50 && intv <= 600*1000) { - variables.monitor_galera_healthcheck_timeout=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"monitor_galera_healthcheck_max_timeout_count")) { - int intv=atoi(value); - if (intv >= 1 && intv <= 10) { - variables.monitor_galera_healthcheck_max_timeout_count=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"monitor_query_interval")) { - int intv=atoi(value); - if (intv >= 100 && intv <= 7*24*3600*1000) { - variables.monitor_query_interval=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"monitor_query_timeout")) { - int intv=atoi(value); - if (intv >= 100 && intv <= 600*1000) { - variables.monitor_query_timeout=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"monitor_slave_lag_when_null")) { - int intv=atoi(value); - if (intv >= 0 && intv <= 604800) { - variables.monitor_slave_lag_when_null=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"monitor_threads_min")) { - int intv=atoi(value); - if (intv >= 2 && intv <= 16) { - variables.monitor_threads_min = intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"monitor_threads_max")) { - int intv=atoi(value); - if (intv >= 4 && intv <= 256) { - variables.monitor_threads_max = intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"monitor_threads_queue_maxsize")) { - int intv=atoi(value); - if (intv >= 16 && intv <= 1024) { - variables.monitor_threads_queue_maxsize = intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"monitor_wait_timeout")) { - if (strcasecmp(value,"true")==0 || strcasecmp(value,"1")==0) { - variables.monitor_wait_timeout=true; - return true; - } - if (strcasecmp(value,"false")==0 || strcasecmp(value,"0")==0) { - variables.monitor_wait_timeout=false; - return true; - } - return false; - } - if (!strcasecmp(name,"monitor_writer_is_also_reader")) { - if (strcasecmp(value,"true")==0 || strcasecmp(value,"1")==0) { - variables.monitor_writer_is_also_reader=true; - return true; - } - if (strcasecmp(value,"false")==0 || strcasecmp(value,"0")==0) { - variables.monitor_writer_is_also_reader=false; - return true; - } - return false; - } - } - if (!strcasecmp(name,"binlog_reader_connect_retry_msec")) { - int intv=atoi(value); - if (intv >= 200 && intv <= 120000) { - __sync_lock_test_and_set(&variables.binlog_reader_connect_retry_msec,intv); - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"wait_timeout")) { - int intv=atoi(value); - if (intv >= 0 && intv <= 20*24*3600*1000) { - variables.wait_timeout=intv; - if (variables.wait_timeout < 5000) { - proxy_warning("mysql-wait_timeout is set to a low value: %ums\n", variables.wait_timeout); - } - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"free_connections_pct")) { - int intv=atoi(value); - if (intv >= 0 && intv <= 100) { - variables.free_connections_pct=intv; - return true; - } else { - return false; - } - } -#ifdef IDLE_THREADS - if (!strcasecmp(name,"session_idle_ms")) { - int intv=atoi(value); - if (intv >= 1 && intv <= 3600*1000) { - variables.session_idle_ms=intv; - return true; - } else { - return false; - } - } -#endif // IDLE_THREADS - if (!strcasecmp(name,"throttle_max_bytes_per_second_to_client")) { - int intv=atoi(value); - if (intv >= 0 && intv <= 2147483647) { - variables.throttle_max_bytes_per_second_to_client=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"throttle_ratio_server_to_client")) { - int intv=atoi(value); - if (intv >= 0 && intv <= 100) { - variables.throttle_ratio_server_to_client=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"max_connections")) { - int intv=atoi(value); - if (intv >= 1 && intv <= 1000*1000) { - variables.max_connections=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"tcp_keepalive_time")) { - int intv=atoi(value); - if (intv >= 0 && intv <= 7200) { - variables.tcp_keepalive_time=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"use_tcp_keepalive")) { - if (strcasecmp(value,"true")==0 || strcasecmp(value,"1")==0) { - variables.use_tcp_keepalive=true; - return true; - } - if (strcasecmp(value,"false")==0 || strcasecmp(value,"0")==0) { - variables.use_tcp_keepalive=false; - return true; - } - return false; - } - if (!strcasecmp(name,"firewall_whitelist_enabled")) { - if (strcasecmp(value,"true")==0 || strcasecmp(value,"1")==0) { - variables.firewall_whitelist_enabled=true; - return true; - } - if (strcasecmp(value,"false")==0 || strcasecmp(value,"0")==0) { - variables.firewall_whitelist_enabled=false; - return true; - } - return false; - } - if (!strcasecmp(name,"automatic_detect_sqli")) { - if (strcasecmp(value,"true")==0 || strcasecmp(value,"1")==0) { - variables.automatic_detect_sqli=true; - return true; - } - if (strcasecmp(value,"false")==0 || strcasecmp(value,"0")==0) { - variables.automatic_detect_sqli=false; - return true; - } - return false; - } - if (!strcasecmp(name,"max_stmts_per_connection")) { - int intv=atoi(value); - if (intv >= 1 && intv <= 1024) { - variables.max_stmts_per_connection=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"max_stmts_cache")) { - int intv=atoi(value); - if (intv >= 1024 && intv <= 1024*1024) { - variables.max_stmts_cache=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"mirror_max_concurrency")) { - int intv=atoi(value); - if (intv >= 1 && intv <= 8*1024) { - variables.mirror_max_concurrency=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"mirror_max_queue_length")) { - int intv=atoi(value); - if (intv >= 0 && intv <= 1024*1024) { - variables.mirror_max_queue_length=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"default_query_delay")) { - int intv=atoi(value); - if (intv >= 0 && intv <= 3600*1000) { - variables.default_query_delay=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"default_query_timeout")) { - int intv=atoi(value); - if (intv >= 1000 && intv <= 20*24*3600*1000) { - variables.default_query_timeout=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"query_processor_iterations")) { - int intv=atoi(value); - if (intv >= 0 && intv <= 1000*1000) { - variables.query_processor_iterations=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"query_processor_regex")) { - int intv=atoi(value); - if (intv >= 1 && intv <= 2) { - variables.query_processor_regex=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"set_query_lock_on_hostgroup")) { - int intv=atoi(value); - if (intv >= 0 && intv <= 1) { - variables.set_query_lock_on_hostgroup=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"reset_connection_algorithm")) { - int intv=atoi(value); - if (intv >= 1 && intv <= 2) { - variables.reset_connection_algorithm=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"auto_increment_delay_multiplex")) { - int intv=atoi(value); - if (intv >= 0 && intv <= 1000000) { - variables.auto_increment_delay_multiplex=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"default_max_latency_ms")) { - int intv=atoi(value); - if (intv >= 0 && intv <= 20*24*3600*1000) { - variables.default_max_latency_ms=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"long_query_time")) { - int intv=atoi(value); - if (intv >= 0 && intv <= 20*24*3600*1000) { - variables.long_query_time=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"query_cache_size_MB")) { - int intv=atoi(value); - if (intv >= 0 && intv <= 1024*10240) { - variables.query_cache_size_MB=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"ping_interval_server_msec")) { - int intv=atoi(value); - if (intv >= 1000 && intv <= 7*24*3600*1000) { - variables.ping_interval_server_msec=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"ping_timeout_server")) { - int intv=atoi(value); - if (intv >= 10 && intv <= 600*1000) { - variables.ping_timeout_server=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"shun_on_failures")) { - int intv=atoi(value); - if (intv >= 0 && intv <= 10000000) { - variables.shun_on_failures=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"shun_recovery_time_sec")) { - int intv=atoi(value); - if (intv >= 0 && intv <= 3600*24*365) { - variables.shun_recovery_time_sec=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"query_retries_on_failure")) { - int intv=atoi(value); - if (intv >= 0 && intv <= 1000) { - variables.query_retries_on_failure=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"client_multi_statements")) { - if (strcasecmp(value,"true")==0 || strcasecmp(value,"1")==0) { - variables.client_multi_statements=true; - return true; - } - if (strcasecmp(value,"false")==0 || strcasecmp(value,"0")==0) { - variables.client_multi_statements=false; - return true; - } - return false; - } - if (!strcasecmp(name,"connect_retries_on_failure")) { - int intv=atoi(value); - if (intv >= 0 && intv <= 1000) { - variables.connect_retries_on_failure=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"connection_delay_multiplex_ms")) { - int intv=atoi(value); - if (intv >= 0 && intv <= 300*1000) { - variables.connection_delay_multiplex_ms=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"connection_max_age_ms")) { - int intv=atoi(value); - if (intv >= 0 && intv <= 3600*24*1000) { - variables.connection_max_age_ms=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"connect_timeout_client")) { - int intv=atoi(value); - if (intv >= 500 && intv <= 3600*1000) { - variables.connect_timeout_client=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"connect_timeout_server")) { - int intv=atoi(value); - if (intv >= 10 && intv <= 120*1000) { - variables.connect_timeout_server=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"connect_timeout_server_max")) { - int intv=atoi(value); - if (intv >= 10 && intv <= 3600*1000) { - variables.connect_timeout_server_max=intv; - return true; - } else { + re2::RE2::Options *opt2=new re2::RE2::Options(RE2::Quiet); + opt2->set_case_sensitive(false); + char *patt = (char *)"`?([a-z\\d_]+)`?\\.`?([a-z\\d_]+)`?"; + RE2 *re = new RE2(patt, *opt2); + bool rc=false; + rc = RE2::FullMatch(value,*re); + delete re; + delete opt2; + if(rc) { + free(variables.monitor_replication_lag_use_percona_heartbeat); + variables.monitor_replication_lag_use_percona_heartbeat=strdup(value); + return true; + } else { + proxy_error("%s is an invalid value for %s, not matching regex \"%s\"\n", value, name, patt); + } + } return false; } } - if (!strcasecmp(name,"connect_retries_delay")) { + if (!strcasecmp(name,"binlog_reader_connect_retry_msec")) { int intv=atoi(value); - if (intv >= 0 && intv <= 10000) { - variables.connect_retries_delay=intv; + if (intv >= 200 && intv <= 120000) { + __sync_lock_test_and_set(&variables.binlog_reader_connect_retry_msec,intv); return true; } else { return false; } } - if (!strcasecmp(name,"eventslog_filesize")) { + if (!strcasecmp(name,"wait_timeout")) { int intv=atoi(value); - if (intv >= 1024*1024 && intv <= 1*1024*1024*1024) { - variables.eventslog_filesize=intv; + if (intv >= 0 && intv <= 20*24*3600*1000) { + variables.wait_timeout=intv; + if (variables.wait_timeout < 5000) { + proxy_warning("mysql-wait_timeout is set to a low value: %ums\n", variables.wait_timeout); + } return true; } else { return false; } } - if (!strcasecmp(name,"eventslog_default_log")) { +#ifdef IDLE_THREADS + if (!strcasecmp(name,"session_idle_ms")) { int intv=atoi(value); - if (intv >= 0 && intv <= 1) { - variables.eventslog_default_log=intv; + if (intv >= 1 && intv <= 3600*1000) { + variables.session_idle_ms=intv; return true; } else { return false; } } +#endif // IDLE_THREADS if (!strcasecmp(name,"eventslog_format")) { int intv=atoi(value); if (intv >= 1 && intv <= 2) { @@ -2610,15 +1801,6 @@ bool MySQL_Threads_Handler::set_variable(char *name, const char *value) { // thi return false; } } - if (!strcasecmp(name,"auditlog_filesize")) { - int intv=atoi(value); - if (intv >= 1024*1024 && intv <= 1*1024*1024*1024) { - variables.auditlog_filesize=intv; - return true; - } else { - return false; - } - } if (!strcasecmp(name,"default_schema")) { if (vallen) { free(variables.default_schema); @@ -2722,28 +1904,6 @@ bool MySQL_Threads_Handler::set_variable(char *name, const char *value) { // thi } return false; // we couldn't set it to a valid value. It will be reset to default } - if (!strcasecmp(name,"enable_client_deprecate_eof")) { - if (strcasecmp(value,"true")==0 || strcasecmp(value,"1")==0) { - variables.enable_client_deprecate_eof=true; - return true; - } - if (strcasecmp(value,"false")==0 || strcasecmp(value,"0")==0) { - variables.enable_client_deprecate_eof=false; - return true; - } - return false; - } - if (!strcasecmp(name,"enable_server_deprecate_eof")) { - if (strcasecmp(value,"true")==0 || strcasecmp(value,"1")==0) { - variables.enable_server_deprecate_eof=true; - return true; - } - if (strcasecmp(value,"false")==0 || strcasecmp(value,"0")==0) { - variables.enable_server_deprecate_eof=false; - return true; - } - return false; - } if (!strncmp(name,"default_",8)) { for (int i=0; i Date: Tue, 11 May 2021 19:24:49 +0200 Subject: [PATCH 12/17] More code cleanup for MySQL variables --- include/MySQL_Thread.h | 3 +- include/proxysql_structs.h | 4 +- lib/MySQL_Thread.cpp | 280 ++++++------------------------------- 3 files changed, 42 insertions(+), 245 deletions(-) diff --git a/include/MySQL_Thread.h b/include/MySQL_Thread.h index 4d56c70cd..3196578e0 100644 --- a/include/MySQL_Thread.h +++ b/include/MySQL_Thread.h @@ -441,7 +441,7 @@ class MySQL_Threads_Handler char *server_version; char *keep_multiplexing_variables; //unsigned int default_charset; // removed in 2.0.13 . Obsoleted previously using MySQL_Variables instead - unsigned int handle_unknown_charset; + int handle_unknown_charset; bool servers_stats; bool commands_stats; bool query_digests; @@ -559,7 +559,6 @@ class MySQL_Threads_Handler ~MySQL_Threads_Handler(); char *get_variable_string(char *name); - unsigned int get_variable_uint(char *name); uint16_t get_variable_uint16(char *name); int get_variable_int(const char *name); void print_version(); diff --git a/include/proxysql_structs.h b/include/proxysql_structs.h index 682457058..8a1d580c5 100644 --- a/include/proxysql_structs.h +++ b/include/proxysql_structs.h @@ -758,7 +758,7 @@ __thread int mysql_thread___set_query_lock_on_hostgroup; __thread int mysql_thread___reset_connection_algorithm; __thread uint32_t mysql_thread___server_capabilities; __thread int mysql_thread___auto_increment_delay_multiplex; -__thread unsigned int mysql_thread___handle_unknown_charset; +__thread int mysql_thread___handle_unknown_charset; __thread int mysql_thread___poll_timeout; __thread int mysql_thread___poll_timeout_on_failure; __thread bool mysql_thread___connection_warming; @@ -909,7 +909,7 @@ extern __thread int mysql_thread___set_query_lock_on_hostgroup; extern __thread int mysql_thread___reset_connection_algorithm; extern __thread uint32_t mysql_thread___server_capabilities; extern __thread int mysql_thread___auto_increment_delay_multiplex; -extern __thread unsigned int mysql_thread___handle_unknown_charset; +extern __thread int mysql_thread___handle_unknown_charset; extern __thread int mysql_thread___poll_timeout; extern __thread int mysql_thread___poll_timeout_on_failure; extern __thread bool mysql_thread___connection_warming; diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index 2864d52a4..16139075f 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -1358,17 +1358,7 @@ uint16_t MySQL_Threads_Handler::get_variable_uint16(char *name) { return 0; } -unsigned int MySQL_Threads_Handler::get_variable_uint(char *name) { - if (!strcasecmp(name,"handle_unknown_charset")) return variables.handle_unknown_charset; - proxy_error("Not existing variable: %s\n", name); assert(0); - return 0; -} - int MySQL_Threads_Handler::get_variable_int(const char *name) { - - if (!strcasecmp(name,"max_transaction_idle_time")) { - PROXY_TRACE(); - } // convert name to string, and lowercase std::string nameS = string(name); std::transform(nameS.begin(), nameS.end(), nameS.begin(), [](unsigned char c){ return std::tolower(c); }); @@ -1392,58 +1382,7 @@ int MySQL_Threads_Handler::get_variable_int(const char *name) { //VALGRIND_DISABLE_ERROR_REPORTING; - char a = name[0]; - switch (a) { - case 'a': - if (!strcmp(name,"aurora_max_lag_ms_only_read_from_replicas")) return variables.aurora_max_lag_ms_only_read_from_replicas; - break; - case 'b': - if (!strcmp(name,"binlog_reader_connect_retry_msec")) return (int)variables.binlog_reader_connect_retry_msec; - break; - case 'c': - if (name[1]=='o') { - if (!strcmp(name,"connpoll_reset_queue_length")) return (int)variables.connpoll_reset_queue_length; - } - break; - case 'e': - if (!strcmp(name,"eventslog_format")) return (int)variables.eventslog_format; - break; - case 'h': - if (!strcmp(name,"have_compress")) return (int)variables.have_compress; - if (!strcmp(name,"have_ssl")) return (int)variables.have_ssl; - break; - case 'm': - if (name[3]=='_') { - if (!strcmp(name,"min_num_servers_lantency_awareness")) return (int)variables.min_num_servers_lantency_awareness; - } - break; - case 'p': - if (!strcmp(name,"poll_timeout")) return variables.poll_timeout; - if (!strcmp(name,"poll_timeout_on_failure")) return variables.poll_timeout_on_failure; - break; - case 's': - if (name[1]=='e') { -#ifdef DEBUG - if (!strcmp(name,"session_debug")) return (int)variables.session_debug; -#endif /* DEBUG */ -#ifdef IDLE_THREADS - if (!strcmp(name,"session_idle_ms")) return (int)variables.session_idle_ms; - if (!strcmp(name,"session_idle_show_processlist")) return (int)variables.session_idle_show_processlist; -#endif // IDLE_THREADS - } - if (name[1]=='h') { - if (!strcmp(name,"show_processlist_extended")) return (int)variables.show_processlist_extended; - } - if (name[1]=='t') { - if (!strcmp(name,"stacksize")) return ( stacksize ? stacksize : DEFAULT_STACK_SIZE); - } - break; - case 'w': - if (!strcmp(name,"wait_timeout")) return (int)variables.wait_timeout; - break; - default: - break; - } + if (!strcmp(name,"stacksize")) return ( stacksize ? stacksize : DEFAULT_STACK_SIZE); proxy_error("Not existing variable: %s\n", name); assert(0); return 0; //VALGRIND_ENABLE_ERROR_REPORTING; @@ -1580,48 +1519,6 @@ char * MySQL_Threads_Handler::get_variable(char *name) { // this is the public f if (!strcasecmp(name,"monitor_password")) return strdup(variables.monitor_password); if (!strcasecmp(name,"monitor_replication_lag_use_percona_heartbeat")) return strdup(variables.monitor_replication_lag_use_percona_heartbeat); } - if (!strcasecmp(name, "handle_unknown_charset")) { - sprintf(intbuf, "%d",variables.handle_unknown_charset); - return strdup(intbuf); - } - if (!strcasecmp(name,"connpoll_reset_queue_length")) { - sprintf(intbuf,"%d",variables.connpoll_reset_queue_length); - return strdup(intbuf); - } -#ifdef IDLE_THREADS - if (!strcasecmp(name,"session_idle_ms")) { - sprintf(intbuf,"%d",variables.session_idle_ms); - return strdup(intbuf); - } -#endif // IDLE_THREADS - if (!strcasecmp(name,"eventslog_format")) { - sprintf(intbuf,"%d",variables.eventslog_format); - return strdup(intbuf); - } - if (!strcasecmp(name,"binlog_reader_connect_retry_msec")) { - sprintf(intbuf,"%d",variables.binlog_reader_connect_retry_msec); - return strdup(intbuf); - } - if (!strcasecmp(name,"wait_timeout")) { - sprintf(intbuf,"%d",variables.wait_timeout); - return strdup(intbuf); - } - if (!strcasecmp(name,"poll_timeout")) { - sprintf(intbuf,"%d",variables.poll_timeout); - return strdup(intbuf); - } - if (!strcasecmp(name,"poll_timeout_on_failure")) { - sprintf(intbuf,"%d",variables.poll_timeout_on_failure); - return strdup(intbuf); - } - if (!strcasecmp(name,"min_num_servers_lantency_awareness")) { - sprintf(intbuf,"%d",variables.min_num_servers_lantency_awareness); - return strdup(intbuf); - } - if (!strcasecmp(name,"aurora_max_lag_ms_only_read_from_replicas")) { - sprintf(intbuf,"%d",variables.aurora_max_lag_ms_only_read_from_replicas); - return strdup(intbuf); - } if (!strcasecmp(name,"threads")) { sprintf(intbuf,"%d", (num_threads ? num_threads : DEFAULT_NUM_THREADS)); return strdup(intbuf); @@ -1630,26 +1527,7 @@ char * MySQL_Threads_Handler::get_variable(char *name) { // this is the public f sprintf(intbuf,"%d", (int)(stacksize ? stacksize : DEFAULT_STACK_SIZE)); return strdup(intbuf); } -#ifdef DEBUG - if (!strcasecmp(name,"session_debug")) { - return strdup((variables.session_debug ? "true" : "false")); - } -#endif /* DEBUG */ - if (!strcasecmp(name,"have_compress")) { - return strdup((variables.have_compress ? "true" : "false")); - } - if (!strcasecmp(name,"have_ssl")) { - return strdup((variables.have_ssl ? "true" : "false")); - } -#ifdef IDLE_THREADS - if (!strcasecmp(name,"session_idle_show_processlist")) { - return strdup((variables.session_idle_show_processlist ? "true" : "false")); - } -#endif // IDLE_THREADS - if (!strcasecmp(name,"show_processlist_extended")) { - sprintf(intbuf,"%d",variables.show_processlist_extended); - return strdup(intbuf); - } + return NULL; //VALGRIND_ENABLE_ERROR_REPORTING; } @@ -1774,17 +1652,6 @@ bool MySQL_Threads_Handler::set_variable(char *name, const char *value) { // thi return false; } } -#ifdef IDLE_THREADS - if (!strcasecmp(name,"session_idle_ms")) { - int intv=atoi(value); - if (intv >= 1 && intv <= 3600*1000) { - variables.session_idle_ms=intv; - return true; - } else { - return false; - } - } -#endif // IDLE_THREADS if (!strcasecmp(name,"eventslog_format")) { int intv=atoi(value); if (intv >= 1 && intv <= 2) { @@ -2025,66 +1892,6 @@ bool MySQL_Threads_Handler::set_variable(char *name, const char *value) { // thi int intv=atoi(value); if (intv > 10 && intv <= 65535) { variables.server_capabilities=intv; -// if (variables.server_capabilities & CLIENT_SSL) { - // for now disable CLIENT_SSL -// variables.server_capabilities &= ~CLIENT_SSL; -// } -// variables.server_capabilities |= CLIENT_SSL; - - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"poll_timeout")) { - int intv=atoi(value); - if (intv >= 10 && intv <= 20000) { - variables.poll_timeout=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"poll_timeout_on_failure")) { - int intv=atoi(value); - if (intv >= 10 && intv <= 20000) { - variables.poll_timeout_on_failure=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"connpoll_reset_queue_length")) { - int intv=atoi(value); - if (intv >= 0 && intv <= 1000) { - variables.connpoll_reset_queue_length=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"min_num_servers_lantency_awareness")) { - int intv=atoi(value); - if (intv >= 0 && intv <= 10000) { - variables.min_num_servers_lantency_awareness=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"aurora_max_lag_ms_only_read_from_replicas")) { - int intv=atoi(value); - if (intv >= 0 && intv <= 100) { - variables.aurora_max_lag_ms_only_read_from_replicas=intv; - return true; - } else { - return false; - } - } - if (!strcasecmp(name,"handle_unknown_charset")) { - uint8_t intv=atoi(value); - if (intv >= 0 && intv < HANDLE_UNKNOWN_CHARSET__MAX_HANDLE_VALUE) { - variables.handle_unknown_charset=intv; return true; } else { return false; @@ -2109,19 +1916,6 @@ bool MySQL_Threads_Handler::set_variable(char *name, const char *value) { // thi return false; } } -#ifdef DEBUG - if (!strcasecmp(name,"session_debug")) { - if (strcasecmp(value,"true")==0 || strcasecmp(value,"1")==0) { - variables.session_debug=true; - return true; - } - if (strcasecmp(value,"false")==0 || strcasecmp(value,"0")==0) { - variables.session_debug=false; - return true; - } - return false; - } -#endif /* DEBUG */ if (!strcasecmp(name,"have_compress")) { if (strcasecmp(value,"true")==0 || strcasecmp(value,"1")==0) { variables.have_compress=true; @@ -2155,29 +1949,6 @@ bool MySQL_Threads_Handler::set_variable(char *name, const char *value) { // thi } return false; } -#ifdef IDLE_THREADS - if (!strcasecmp(name,"session_idle_show_processlist")) { - if (strcasecmp(value,"true")==0 || strcasecmp(value,"1")==0) { - variables.session_idle_show_processlist=true; - return true; - } - if (strcasecmp(value,"false")==0 || strcasecmp(value,"0")==0) { - variables.session_idle_show_processlist=false; - return true; - } - return false; - } -#endif // IDLE_THREADS - if (!strcasecmp(name,"show_processlist_extended")) { - int intv=atoi(value); - if (intv >= 0 && intv <= 2) { - variables.show_processlist_extended=intv; - return true; - } else { - return false; - } - return false; - } return false; } @@ -2222,8 +1993,16 @@ char ** MySQL_Threads_Handler::get_variables_list() { VariablesPointers_bool["stats_time_query_processor"] = make_tuple(&variables.stats_time_query_processor, false); VariablesPointers_bool["use_tcp_keepalive"] = make_tuple(&variables.use_tcp_keepalive, false); VariablesPointers_bool["verbose_query_error"] = make_tuple(&variables.verbose_query_error, false); - - +#ifdef IDLE_THREADS + VariablesPointers_bool["session_idle_show_processlist"] = make_tuple(&variables.session_idle_show_processlist, false); +#endif // IDLE_THREADS +#ifdef DEBUG + VariablesPointers_bool["session_debug"] = make_tuple(&variables.session_debug, false); +#endif /* DEBUG */ + // variables with special variable == true + // the input validation for these variables MUST be EXPLICIT + VariablesPointers_bool["have_compress"] = make_tuple(&variables.have_compress, true); + VariablesPointers_bool["have_ssl"] = make_tuple(&variables.have_ssl, true); } @@ -2286,13 +2065,18 @@ char ** MySQL_Threads_Handler::get_variables_list() { VariablesPointers_int["throttle_max_bytes_per_second_to_client"] = make_tuple(&variables.throttle_max_bytes_per_second_to_client, 0, 2147483647, false); VariablesPointers_int["throttle_ratio_server_to_client"] = make_tuple(&variables.throttle_ratio_server_to_client, 0, 100, false); // backend management - VariablesPointers_int["default_max_latency_ms"] = make_tuple(&variables.default_max_latency_ms, 0, 20*24*3600*1000, false); - VariablesPointers_int["free_connections_pct"] = make_tuple(&variables.free_connections_pct, 0, 100, false); - VariablesPointers_int["reset_connection_algorithm"] = make_tuple(&variables.reset_connection_algorithm, 1, 2, false); - VariablesPointers_int["shun_on_failures"] = make_tuple(&variables.shun_on_failures, 0, 10000000, false); - VariablesPointers_int["shun_recovery_time_sec"] = make_tuple(&variables.shun_recovery_time_sec, 0, 3600*24*365, false); - VariablesPointers_int["hostgroup_manager_verbose"] = make_tuple(&variables.hostgroup_manager_verbose, 1, 2, false); - VariablesPointers_int["tcp_keepalive_time"] = make_tuple(&variables.tcp_keepalive_time, 0, 7200, false); + VariablesPointers_int["connpoll_reset_queue_length"] = make_tuple(&variables.connpoll_reset_queue_length, 0, 10000, false); + VariablesPointers_int["default_max_latency_ms"] = make_tuple(&variables.default_max_latency_ms, 0, 20*24*3600*1000, false); + VariablesPointers_int["free_connections_pct"] = make_tuple(&variables.free_connections_pct, 0, 100, false); + VariablesPointers_int["poll_timeout"] = make_tuple(&variables.poll_timeout, 10, 20000, false); + VariablesPointers_int["poll_timeout_on_failure"] = make_tuple(&variables.poll_timeout_on_failure, 10, 20000, false); + VariablesPointers_int["reset_connection_algorithm"] = make_tuple(&variables.reset_connection_algorithm, 1, 2, false); + VariablesPointers_int["shun_on_failures"] = make_tuple(&variables.shun_on_failures, 0, 10000000, false); + VariablesPointers_int["shun_recovery_time_sec"] = make_tuple(&variables.shun_recovery_time_sec, 0, 3600*24*365, false); + VariablesPointers_int["hostgroup_manager_verbose"] = make_tuple(&variables.hostgroup_manager_verbose, 1, 2, false); + VariablesPointers_int["tcp_keepalive_time"] = make_tuple(&variables.tcp_keepalive_time, 0, 7200, false); + VariablesPointers_int["min_num_servers_lantency_awareness"] = make_tuple(&variables.min_num_servers_lantency_awareness, 0, 10000, false); + VariablesPointers_int["aurora_max_lag_ms_only_read_from_replicas"] = make_tuple(&variables.aurora_max_lag_ms_only_read_from_replicas, 0, 100, false); // connection management VariablesPointers_int["connect_retries_on_failure"] = make_tuple(&variables.connect_retries_on_failure, 0, 1000, false); VariablesPointers_int["connect_retries_delay"] = make_tuple(&variables.connect_retries_delay, 0, 10000, false); @@ -2301,6 +2085,7 @@ char ** MySQL_Threads_Handler::get_variables_list() { VariablesPointers_int["connect_timeout_server_max"] = make_tuple(&variables.connect_timeout_server_max, 10, 3600*1000, false); VariablesPointers_int["connection_delay_multiplex_ms"] = make_tuple(&variables.connection_delay_multiplex_ms, 0, 300*1000, false); VariablesPointers_int["connection_max_age_ms"] = make_tuple(&variables.connection_max_age_ms, 0, 3600*24*1000, false); + VariablesPointers_int["handle_unknown_charset"] = make_tuple(&variables.handle_unknown_charset, 0, HANDLE_UNKNOWN_CHARSET__MAX_HANDLE_VALUE, false); VariablesPointers_int["ping_interval_server_msec"] = make_tuple(&variables.ping_interval_server_msec, 1000, 7*24*3600*1000, false); VariablesPointers_int["ping_timeout_server"] = make_tuple(&variables.ping_timeout_server, 10, 600*1000, false); // logs @@ -2316,10 +2101,23 @@ char ** MySQL_Threads_Handler::get_variables_list() { VariablesPointers_int["max_transaction_idle_time"] = make_tuple(&variables.max_transaction_idle_time, 1000, 20*24*3600*1000, false); VariablesPointers_int["max_transaction_time"] = make_tuple(&variables.max_transaction_time, 1000, 20*24*3600*1000, false); VariablesPointers_int["query_cache_size_MB"] = make_tuple(&variables.query_cache_size_MB, 0, 1024*10240, false); +#ifdef IDLE_THREADS + VariablesPointers_int["session_idle_ms"] = make_tuple(&variables.session_idle_ms, 1, 3600*1000, false); +#endif // IDLE_THREADS + VariablesPointers_int["show_processlist_extended"] = make_tuple(&variables.show_processlist_extended, 0, 2, false); VariablesPointers_int["threshold_query_length"] = make_tuple(&variables.threshold_query_length, 1024, 1*1024*1024*1024, false); VariablesPointers_int["threshold_resultset_size"] = make_tuple(&variables.threshold_resultset_size, 1024, 1*1024*1024*1024, false); + + // variables with special variable == true + // the input validation for these variables MUST be EXPLICIT + VariablesPointers_int["binlog_reader_connect_retry_msec"] = make_tuple(&variables.binlog_reader_connect_retry_msec, 0, 0, true); + VariablesPointers_int["eventslog_format"] = make_tuple(&variables.eventslog_format, 0, 0, true); + VariablesPointers_int["wait_timeout"] = make_tuple(&variables.wait_timeout, 0, 0, true); + + } + const size_t l=sizeof(mysql_thread_variables_names)/sizeof(char *); unsigned int i; size_t ltv = 0; @@ -3774,7 +3572,7 @@ void MySQL_Thread::refresh_variables() { if (mysql_thread___keep_multiplexing_variables) free(mysql_thread___keep_multiplexing_variables); mysql_thread___keep_multiplexing_variables=GloMTH->get_variable_string((char *)"keep_multiplexing_variables"); mysql_thread___server_capabilities=GloMTH->get_variable_uint16((char *)"server_capabilities"); - mysql_thread___handle_unknown_charset=GloMTH->get_variable_uint((char *)"handle_unknown_charset"); + mysql_thread___handle_unknown_charset=GloMTH->get_variable_int((char *)"handle_unknown_charset"); mysql_thread___poll_timeout=GloMTH->get_variable_int((char *)"poll_timeout"); mysql_thread___poll_timeout_on_failure=GloMTH->get_variable_int((char *)"poll_timeout_on_failure"); mysql_thread___have_compress=(bool)GloMTH->get_variable_int((char *)"have_compress"); From 0643642087a65f510d004275567a5627a69695f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Wed, 12 May 2021 13:05:32 +0200 Subject: [PATCH 13/17] Removing unused variables --- lib/MySQL_Thread.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index c46949980..51ce733e9 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -4093,7 +4093,6 @@ void MySQL_Thread::unregister_session(int idx) { // this function was inline in MySQL_Thread::run() void MySQL_Thread::run___get_multiple_idle_connections(int& num_idles) { - int rc; int i; num_idles=MyHGM->get_multiple_idle_connections(-1, curtime-mysql_thread___ping_interval_server_msec*1000, my_idle_conns, SESSIONS_FOR_CONNECTIONS_HANDLER); for (i=0; i Date: Wed, 12 May 2021 18:37:55 +0200 Subject: [PATCH 14/17] Mofidied 'set_testing' tests to support queries of the shape 'sql_mode=CONCAT(@@sql_mode,'VALUE')' #3442 --- test/tap/tests/set_testing-multi-t.cpp | 46 ++++++++++++++++++++++++-- test/tap/tests/set_testing-t.cpp | 46 ++++++++++++++++++++++++-- test/tap/tests/set_testing-t.csv | 1 + 3 files changed, 89 insertions(+), 4 deletions(-) diff --git a/test/tap/tests/set_testing-multi-t.cpp b/test/tap/tests/set_testing-multi-t.cpp index cf6dfafcf..4ef96d3c3 100644 --- a/test/tap/tests/set_testing-multi-t.cpp +++ b/test/tap/tests/set_testing-multi-t.cpp @@ -12,7 +12,10 @@ #include #include #include + #include "json.hpp" +#include "re2/re2.h" +#include "re2/regexp.h" #include "tap.h" #include "utils.h" @@ -571,9 +574,48 @@ void * my_conn_thread(void *arg) { fprintf(stderr, "Variable %s->%s in proxysql resultset was not found.\nmysql data : %s\nproxysql data: %s\ncsv data %s\n", el.value().dump().c_str(), el.key().c_str(), mysql_vars.dump().c_str(), proxysql_vars.dump().c_str(), vars.dump().c_str()); + bool verified_special_sqlmode = false; + bool special_sqlmode = false; + + if (el.key() == "sql_mode") { + if (!el.value().is_string()) { + diag("Invalid value for 'sql_mode' found. Provided value should be of 'string' type"); + exit(EXIT_FAILURE); + } + + std::string str_val { el.value() }; + + re2::RE2::Options options(RE2::Quiet); + options.set_case_sensitive(false); + options.set_longest_match(false); + re2::RE2 concat_re("^CONCAT\\((|@@|@@session\\.)SQL_MODE,\"(.*)\"\\)", options); + re2::StringPiece sp_input(str_val); + + std::string f_match {}; + std::string s_match {}; + + re2::RE2::Consume(&sp_input, concat_re, &f_match, &s_match); + + if (!s_match.empty()) { + special_sqlmode = true; + + // remove the initial 'comma' if exists + if (s_match[0] == ',') { + s_match = s_match.substr(1, std::string::npos); + } + + std::string k_str_val { k.value() }; + verified_special_sqlmode = + strcasestr(k_str_val.c_str(), s_match.c_str()) != NULL; + } + } + if ( - (el.key() != "session_track_gtids" && (k.value() != el.value() || s.value() != el.value())) || - (el.key() == "session_track_gtids" && !check_session_track_gtids(el.value(), s.value(), k.value())) + (special_sqlmode == true && verified_special_sqlmode == false) || + (special_sqlmode == false && + (el.key() != "session_track_gtids" && (k.value() != el.value() || s.value() != el.value())) || + (el.key() == "session_track_gtids" && !check_session_track_gtids(el.value(), s.value(), k.value())) + ) ) { __sync_fetch_and_add(&g_failed, 1); testPassed = false; diff --git a/test/tap/tests/set_testing-t.cpp b/test/tap/tests/set_testing-t.cpp index c50e73213..7568382c7 100644 --- a/test/tap/tests/set_testing-t.cpp +++ b/test/tap/tests/set_testing-t.cpp @@ -22,7 +22,10 @@ #include #include #include + #include "json.hpp" +#include "re2/re2.h" +#include "re2/regexp.h" #include "tap.h" #include "utils.h" @@ -565,9 +568,48 @@ void * my_conn_thread(void *arg) { fprintf(stderr, "Variable %s->%s in proxysql resultset was not found.\nmysql data : %s\nproxysql data: %s\ncsv data %s\n", el.value().dump().c_str(), el.key().c_str(), mysql_vars.dump().c_str(), proxysql_vars.dump().c_str(), vars.dump().c_str()); + bool verified_special_sqlmode = false; + bool special_sqlmode = false; + + if (el.key() == "sql_mode") { + if (!el.value().is_string()) { + diag("Invalid value for 'sql_mode' found. Provided value should be of 'string' type"); + exit(EXIT_FAILURE); + } + + std::string str_val { el.value() }; + + re2::RE2::Options options(RE2::Quiet); + options.set_case_sensitive(false); + options.set_longest_match(false); + re2::RE2 concat_re("^CONCAT\\((|@@|@@session\\.)SQL_MODE,\"(.*)\"\\)", options); + re2::StringPiece sp_input(str_val); + + std::string f_match {}; + std::string s_match {}; + + re2::RE2::Consume(&sp_input, concat_re, &f_match, &s_match); + + if (!s_match.empty()) { + special_sqlmode = true; + + // remove the initial 'comma' if exists + if (s_match[0] == ',') { + s_match = s_match.substr(1, std::string::npos); + } + + std::string k_str_val { k.value() }; + verified_special_sqlmode = + strcasestr(k_str_val.c_str(), s_match.c_str()) != NULL; + } + } + if ( - (el.key() != "session_track_gtids" && (k.value() != el.value() || s.value() != el.value())) || - (el.key() == "session_track_gtids" && !check_session_track_gtids(el.value(), s.value(), k.value())) + (special_sqlmode == true && verified_special_sqlmode == false) || + (special_sqlmode == false && + (el.key() != "session_track_gtids" && (k.value() != el.value() || s.value() != el.value())) || + (el.key() == "session_track_gtids" && !check_session_track_gtids(el.value(), s.value(), k.value())) + ) ) { __sync_fetch_and_add(&g_failed, 1); testPassed = false; diff --git a/test/tap/tests/set_testing-t.csv b/test/tap/tests/set_testing-t.csv index 408c90d36..6a4776fcb 100644 --- a/test/tap/tests/set_testing-t.csv +++ b/test/tap/tests/set_testing-t.csv @@ -91,3 +91,4 @@ "SET time_zone='+04:00', sql_mode='NO_ENGINE_SUBSTITUTION', max_join_size=10000; SET CHARACTER SET 'latin1'", "{'time_zone':'+04:00', 'sql_mode':'NO_ENGINE_SUBSTITUTION', 'max_join_size':'10000', 'character_set_results':'latin1', 'character_set_client':'latin1'}", "['character_set_connection', 'collation_connection']" "SET time_zone='+04:00', sql_mode='NO_ENGINE_SUBSTITUTION', max_join_size=10000; SET CHARSET 'latin1'", "{'time_zone':'+04:00', 'sql_mode':'NO_ENGINE_SUBSTITUTION', 'max_join_size':'10000', 'character_set_results':'latin1', 'character_set_client':'latin1'}", "['character_set_connection', 'collation_connection']" "SET session_track_gtids=ALL_GTIDS", "{'session_track_gtids':'ALL_GTIDS'}" +"SET sql_safe_updates=1, session_track_schema=1, sql_mode = concat(@@sql_mode,',STRICT_TRANS_TABLES')", "{'sql_safe_updates':'ON', 'sql_mode':'concat(@@sql_mode,\',STRICT_TRANS_TABLES\')'}" From b446dc07184b0112645061220b2a9d03a053fd7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Sun, 16 May 2021 20:29:18 +0200 Subject: [PATCH 15/17] Changing query_cache_size_MB to lowercase --- lib/MySQL_Thread.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index 16139075f..d7da2d367 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -2100,7 +2100,7 @@ char ** MySQL_Threads_Handler::get_variables_list() { VariablesPointers_int["max_stmts_cache"] = make_tuple(&variables.max_stmts_cache, 1024, 1024*1024, false); VariablesPointers_int["max_transaction_idle_time"] = make_tuple(&variables.max_transaction_idle_time, 1000, 20*24*3600*1000, false); VariablesPointers_int["max_transaction_time"] = make_tuple(&variables.max_transaction_time, 1000, 20*24*3600*1000, false); - VariablesPointers_int["query_cache_size_MB"] = make_tuple(&variables.query_cache_size_MB, 0, 1024*10240, false); + VariablesPointers_int["query_cache_size_mb"] = make_tuple(&variables.query_cache_size_MB, 0, 1024*10240, false); #ifdef IDLE_THREADS VariablesPointers_int["session_idle_ms"] = make_tuple(&variables.session_idle_ms, 1, 3600*1000, false); #endif // IDLE_THREADS From d494f6f7b291ed17fb9e78a207a87c4619eddec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Mon, 17 May 2021 12:12:50 +0200 Subject: [PATCH 16/17] Configure use_tcp_keepalive as bool in TAP test test_cluster_sync-t.cpp had incorrectly set use_tcp_keepalive as number instead of bool --- test/tap/tests/test_cluster_sync-t.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tap/tests/test_cluster_sync-t.cpp b/test/tap/tests/test_cluster_sync-t.cpp index a42c5ce2a..d7a9ee9a3 100644 --- a/test/tap/tests/test_cluster_sync-t.cpp +++ b/test/tap/tests/test_cluster_sync-t.cpp @@ -975,7 +975,7 @@ int main(int, char**) { std::make_tuple("mysql-monitor_writer_is_also_reader" , "true" ), std::make_tuple("mysql-max_allowed_packet" , "67108864" ), std::make_tuple("mysql-tcp_keepalive_time" , "0" ), - std::make_tuple("mysql-use_tcp_keepalive" , "0" ), + std::make_tuple("mysql-use_tcp_keepalive" , "false" ), std::make_tuple("mysql-automatic_detect_sqli" , "0" ), std::make_tuple("mysql-firewall_whitelist_enabled" , "0" ), std::make_tuple("mysql-firewall_whitelist_errormsg" , "Firewall blocked this query"), From 218bfa873903cda345d885943f2b78d84b1fcbed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Mon, 17 May 2021 13:02:35 +0200 Subject: [PATCH 17/17] Setting some vars as bool in test_cluster_sync-t Some variables were incorrectly configured as integer and not boolean --- test/tap/tests/test_cluster_sync-t.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/tap/tests/test_cluster_sync-t.cpp b/test/tap/tests/test_cluster_sync-t.cpp index d7a9ee9a3..cf1f7bcd2 100644 --- a/test/tap/tests/test_cluster_sync-t.cpp +++ b/test/tap/tests/test_cluster_sync-t.cpp @@ -976,8 +976,8 @@ int main(int, char**) { std::make_tuple("mysql-max_allowed_packet" , "67108864" ), std::make_tuple("mysql-tcp_keepalive_time" , "0" ), std::make_tuple("mysql-use_tcp_keepalive" , "false" ), - std::make_tuple("mysql-automatic_detect_sqli" , "0" ), - std::make_tuple("mysql-firewall_whitelist_enabled" , "0" ), + std::make_tuple("mysql-automatic_detect_sqli" , "false" ), + std::make_tuple("mysql-firewall_whitelist_enabled" , "false" ), std::make_tuple("mysql-firewall_whitelist_errormsg" , "Firewall blocked this query"), std::make_tuple("mysql-throttle_connections_per_sec_to_hostgroup" , "1000001" ), std::make_tuple("mysql-max_transaction_time" , "14400001" ),