From 80581625c851027a7dc0612f500858066b47da71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Wed, 21 May 2025 12:51:49 +0200 Subject: [PATCH 1/5] Remove non-supported checks from 'pgsql_replication_hostgroups' definition --- include/PgSQL_HostGroups_Manager.h | 2 +- include/ProxySQL_Admin_Tables_Definitions.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/PgSQL_HostGroups_Manager.h b/include/PgSQL_HostGroups_Manager.h index ed1d4dcf62..bea6258593 100644 --- a/include/PgSQL_HostGroups_Manager.h +++ b/include/PgSQL_HostGroups_Manager.h @@ -46,7 +46,7 @@ #define MYHGM_PgSQL_SERVERS "CREATE TABLE pgsql_servers ( hostgroup_id INT NOT NULL DEFAULT 0 , hostname VARCHAR NOT NULL , port INT NOT NULL DEFAULT 5432 , weight INT NOT NULL DEFAULT 1 , status INT NOT NULL DEFAULT 0 , compression INT NOT NULL DEFAULT 0 , max_connections INT NOT NULL DEFAULT 1000 , max_replication_lag INT NOT NULL DEFAULT 0 , use_ssl INT NOT NULL DEFAULT 0 , max_latency_ms INT UNSIGNED NOT NULL DEFAULT 0 , comment VARCHAR NOT NULL DEFAULT '' , mem_pointer INT NOT NULL DEFAULT 0 , PRIMARY KEY (hostgroup_id, hostname, port) )" #define MYHGM_PgSQL_SERVERS_INCOMING "CREATE TABLE pgsql_servers_incoming ( hostgroup_id INT NOT NULL DEFAULT 0 , hostname VARCHAR NOT NULL , port INT NOT NULL DEFAULT 5432 , weight INT NOT NULL DEFAULT 1 , status INT NOT NULL DEFAULT 0 , compression INT NOT NULL DEFAULT 0 , max_connections INT NOT NULL DEFAULT 1000 , max_replication_lag INT NOT NULL DEFAULT 0 , use_ssl INT NOT NULL DEFAULT 0 , max_latency_ms INT UNSIGNED NOT NULL DEFAULT 0 , comment VARCHAR NOT NULL DEFAULT '' , PRIMARY KEY (hostgroup_id, hostname, port))" #endif /* DEBUG */ -#define MYHGM_PgSQL_REPLICATION_HOSTGROUPS "CREATE TABLE pgsql_replication_hostgroups (writer_hostgroup INT CHECK (writer_hostgroup>=0) NOT NULL PRIMARY KEY , reader_hostgroup INT NOT NULL CHECK (reader_hostgroup<>writer_hostgroup AND reader_hostgroup>=0) , check_type VARCHAR CHECK (LOWER(check_type) IN ('read_only','innodb_read_only','super_read_only','read_only|innodb_read_only','read_only&innodb_read_only')) NOT NULL DEFAULT 'read_only' , comment VARCHAR NOT NULL DEFAULT '' , UNIQUE (reader_hostgroup))" +#define MYHGM_PgSQL_REPLICATION_HOSTGROUPS "CREATE TABLE pgsql_replication_hostgroups (writer_hostgroup INT CHECK (writer_hostgroup>=0) NOT NULL PRIMARY KEY , reader_hostgroup INT NOT NULL CHECK (reader_hostgroup<>writer_hostgroup AND reader_hostgroup>=0) , check_type VARCHAR CHECK (LOWER(check_type) IN ('read_only')) NOT NULL DEFAULT 'read_only' , comment VARCHAR NOT NULL DEFAULT '' , UNIQUE (reader_hostgroup))" #define PGHGM_GEN_ADMIN_RUNTIME_SERVERS "SELECT hostgroup_id, hostname, port, CASE status WHEN 0 THEN \"ONLINE\" WHEN 1 THEN \"SHUNNED\" WHEN 2 THEN \"OFFLINE_SOFT\" WHEN 3 THEN \"OFFLINE_HARD\" WHEN 4 THEN \"SHUNNED\" END status, weight, compression, max_connections, max_replication_lag, use_ssl, max_latency_ms, comment FROM pgsql_servers ORDER BY hostgroup_id, hostname, port" diff --git a/include/ProxySQL_Admin_Tables_Definitions.h b/include/ProxySQL_Admin_Tables_Definitions.h index 7a5a5a3c3c..6d9e8b5f1c 100644 --- a/include/ProxySQL_Admin_Tables_Definitions.h +++ b/include/ProxySQL_Admin_Tables_Definitions.h @@ -276,7 +276,7 @@ #define ADMIN_SQLITE_TABLE_PGSQL_FIREWALL_WHITELIST_SQLI_FINGERPRINTS "CREATE TABLE pgsql_firewall_whitelist_sqli_fingerprints (active INT CHECK (active IN (0,1)) NOT NULL DEFAULT 1 , fingerprint VARCHAR NOT NULL , PRIMARY KEY (fingerprint) )" #define ADMIN_SQLITE_TABLE_PGSQL_QUERY_RULES_FAST_ROUTING "CREATE TABLE pgsql_query_rules_fast_routing (username VARCHAR NOT NULL , database VARCHAR NOT NULL , flagIN INT NOT NULL DEFAULT 0 , destination_hostgroup INT CHECK (destination_hostgroup >= 0) NOT NULL , comment VARCHAR NOT NULL , PRIMARY KEY (username, database, flagIN) )" #define ADMIN_SQLITE_TABLE_PGSQL_HOSTGROUP_ATTRIBUTES "CREATE TABLE pgsql_hostgroup_attributes (hostgroup_id INT NOT NULL PRIMARY KEY , max_num_online_servers INT CHECK (max_num_online_servers>=0 AND max_num_online_servers <= 1000000) NOT NULL DEFAULT 1000000 , autocommit INT CHECK (autocommit IN (-1, 0, 1)) NOT NULL DEFAULT -1 , free_connections_pct INT CHECK (free_connections_pct >= 0 AND free_connections_pct <= 100) NOT NULL DEFAULT 10 , init_connect VARCHAR NOT NULL DEFAULT '' , multiplex INT CHECK (multiplex IN (0, 1)) NOT NULL DEFAULT 1 , connection_warming INT CHECK (connection_warming IN (0, 1)) NOT NULL DEFAULT 0 , throttle_connections_per_sec INT CHECK (throttle_connections_per_sec >= 1 AND throttle_connections_per_sec <= 1000000) NOT NULL DEFAULT 1000000 , ignore_session_variables VARCHAR CHECK (JSON_VALID(ignore_session_variables) OR ignore_session_variables = '') NOT NULL DEFAULT '' , hostgroup_settings VARCHAR CHECK (JSON_VALID(hostgroup_settings) OR hostgroup_settings = '') NOT NULL DEFAULT '' , servers_defaults VARCHAR CHECK (JSON_VALID(servers_defaults) OR servers_defaults = '') NOT NULL DEFAULT '' , comment VARCHAR NOT NULL DEFAULT '')" -#define ADMIN_SQLITE_TABLE_PGSQL_REPLICATION_HOSTGROUPS "CREATE TABLE pgsql_replication_hostgroups (writer_hostgroup INT CHECK (writer_hostgroup>=0) NOT NULL PRIMARY KEY , reader_hostgroup INT NOT NULL CHECK (reader_hostgroup<>writer_hostgroup AND reader_hostgroup>=0) , check_type VARCHAR CHECK (LOWER(check_type) IN ('read_only','innodb_read_only','super_read_only','read_only|innodb_read_only','read_only&innodb_read_only')) NOT NULL DEFAULT 'read_only' , comment VARCHAR NOT NULL DEFAULT '', UNIQUE (reader_hostgroup))" +#define ADMIN_SQLITE_TABLE_PGSQL_REPLICATION_HOSTGROUPS "CREATE TABLE pgsql_replication_hostgroups (writer_hostgroup INT CHECK (writer_hostgroup>=0) NOT NULL PRIMARY KEY , reader_hostgroup INT NOT NULL CHECK (reader_hostgroup<>writer_hostgroup AND reader_hostgroup>=0) , check_type VARCHAR CHECK (LOWER(check_type) IN ('read_only')) NOT NULL DEFAULT 'read_only' , comment VARCHAR NOT NULL DEFAULT '', UNIQUE (reader_hostgroup))" #define ADMIN_SQLITE_TABLE_RUNTIME_PGSQL_SERVERS "CREATE TABLE runtime_pgsql_servers (hostgroup_id INT CHECK (hostgroup_id>=0) NOT NULL DEFAULT 0 , hostname VARCHAR NOT NULL , port INT CHECK (port >= 0 AND port <= 65535) NOT NULL DEFAULT 5432 , status VARCHAR CHECK (UPPER(status) IN ('ONLINE','SHUNNED','OFFLINE_SOFT', 'OFFLINE_HARD')) NOT NULL DEFAULT 'ONLINE' , weight INT CHECK (weight >= 0 AND weight <=10000000) NOT NULL DEFAULT 1 , compression INT CHECK (compression IN(0,1)) NOT NULL DEFAULT 0 , max_connections INT CHECK (max_connections >=0) NOT NULL DEFAULT 1000 , max_replication_lag INT CHECK (max_replication_lag >= 0 AND max_replication_lag <= 126144000) NOT NULL DEFAULT 0 , use_ssl INT CHECK (use_ssl IN(0,1)) NOT NULL DEFAULT 0 , max_latency_ms INT UNSIGNED CHECK (max_latency_ms>=0) NOT NULL DEFAULT 0 , comment VARCHAR NOT NULL DEFAULT '' , PRIMARY KEY (hostgroup_id, hostname, port) )" #define ADMIN_SQLITE_TABLE_RUNTIME_PGSQL_USERS "CREATE TABLE runtime_pgsql_users (username VARCHAR NOT NULL , password VARCHAR , active INT CHECK (active IN (0,1)) NOT NULL DEFAULT 1 , use_ssl INT CHECK (use_ssl IN (0,1)) NOT NULL DEFAULT 0 , default_hostgroup INT NOT NULL DEFAULT 0 , transaction_persistent INT CHECK (transaction_persistent IN (0,1)) NOT NULL DEFAULT 1 , fast_forward INT CHECK (fast_forward IN (0,1)) NOT NULL DEFAULT 0 , backend INT CHECK (backend IN (0,1)) NOT NULL DEFAULT 1 , frontend INT CHECK (frontend IN (0,1)) NOT NULL DEFAULT 1 , max_connections INT CHECK (max_connections >=0) NOT NULL DEFAULT 10000 , attributes VARCHAR CHECK (JSON_VALID(attributes) OR attributes = '') NOT NULL DEFAULT '', comment VARCHAR NOT NULL DEFAULT '' , PRIMARY KEY (username, backend) , UNIQUE (username, frontend))" @@ -287,7 +287,7 @@ #define ADMIN_SQLITE_TABLE_RUNTIME_PGSQL_FIREWALL_WHITELIST_SQLI_FINGERPRINTS "CREATE TABLE runtime_pgsql_firewall_whitelist_sqli_fingerprints (active INT CHECK (active IN (0,1)) NOT NULL DEFAULT 1 , fingerprint VARCHAR NOT NULL , PRIMARY KEY (fingerprint) )" #define ADMIN_SQLITE_TABLE_RUNTIME_PGSQL_QUERY_RULES_FAST_ROUTING "CREATE TABLE runtime_pgsql_query_rules_fast_routing (username VARCHAR NOT NULL , database VARCHAR NOT NULL , flagIN INT NOT NULL DEFAULT 0 , destination_hostgroup INT CHECK (destination_hostgroup >= 0) NOT NULL , comment VARCHAR NOT NULL , PRIMARY KEY (username, database, flagIN) )" #define ADMIN_SQLITE_TABLE_RUNTIME_PGSQL_HOSTGROUP_ATTRIBUTES "CREATE TABLE runtime_pgsql_hostgroup_attributes (hostgroup_id INT NOT NULL PRIMARY KEY , max_num_online_servers INT CHECK (max_num_online_servers>=0 AND max_num_online_servers <= 1000000) NOT NULL DEFAULT 1000000 , autocommit INT CHECK (autocommit IN (-1, 0, 1)) NOT NULL DEFAULT -1 , free_connections_pct INT CHECK (free_connections_pct >= 0 AND free_connections_pct <= 100) NOT NULL DEFAULT 10 , init_connect VARCHAR NOT NULL DEFAULT '' , multiplex INT CHECK (multiplex IN (0, 1)) NOT NULL DEFAULT 1 , connection_warming INT CHECK (connection_warming IN (0, 1)) NOT NULL DEFAULT 0 , throttle_connections_per_sec INT CHECK (throttle_connections_per_sec >= 1 AND throttle_connections_per_sec <= 1000000) NOT NULL DEFAULT 1000000 , ignore_session_variables VARCHAR CHECK (JSON_VALID(ignore_session_variables) OR ignore_session_variables = '') NOT NULL DEFAULT '' , hostgroup_settings VARCHAR CHECK (JSON_VALID(hostgroup_settings) OR hostgroup_settings = '') NOT NULL DEFAULT '' , servers_defaults VARCHAR CHECK (JSON_VALID(servers_defaults) OR servers_defaults = '') NOT NULL DEFAULT '' , comment VARCHAR NOT NULL DEFAULT '')" -#define ADMIN_SQLITE_TABLE_RUNTIME_PGSQL_REPLICATION_HOSTGROUPS "CREATE TABLE runtime_pgsql_replication_hostgroups (writer_hostgroup INT CHECK (writer_hostgroup>=0) NOT NULL PRIMARY KEY , reader_hostgroup INT NOT NULL CHECK (reader_hostgroup<>writer_hostgroup AND reader_hostgroup>=0) , check_type VARCHAR CHECK (LOWER(check_type) IN ('read_only','innodb_read_only','super_read_only','read_only|innodb_read_only','read_only&innodb_read_only')) NOT NULL DEFAULT 'read_only' , comment VARCHAR NOT NULL DEFAULT '', UNIQUE (reader_hostgroup))" +#define ADMIN_SQLITE_TABLE_RUNTIME_PGSQL_REPLICATION_HOSTGROUPS "CREATE TABLE runtime_pgsql_replication_hostgroups (writer_hostgroup INT CHECK (writer_hostgroup>=0) NOT NULL PRIMARY KEY , reader_hostgroup INT NOT NULL CHECK (reader_hostgroup<>writer_hostgroup AND reader_hostgroup>=0) , check_type VARCHAR CHECK (LOWER(check_type) IN ('read_only')) NOT NULL DEFAULT 'read_only' , comment VARCHAR NOT NULL DEFAULT '', UNIQUE (reader_hostgroup))" #define STATS_SQLITE_TABLE_PGSQL_GLOBAL "CREATE TABLE stats_pgsql_global (Variable_Name VARCHAR NOT NULL PRIMARY KEY , Variable_Value VARCHAR NOT NULL)" #define STATS_SQLITE_TABLE_PGSQL_CONNECTION_POOL "CREATE TABLE stats_pgsql_connection_pool (hostgroup INT , srv_host VARCHAR , srv_port INT , status VARCHAR , ConnUsed INT , ConnFree INT , ConnOK INT , ConnERR INT , MaxConnUsed INT , Queries INT , Bytes_data_sent INT , Bytes_data_recv INT , Latency_us INT)" From 1a79a9f39d05908cbd6a365ca28462539eb72652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Wed, 21 May 2025 13:20:53 +0200 Subject: [PATCH 2/5] Add new variables for disable/enable MySQL/PostgreSQL modules - Closes #4951 Accessible as config file and command line switches: + --(mysql|pgsql)-workers=(true|false) + --(mysql|pgsql)-admin=(true|false) + --(mysql|pgsql)-monitor=(true|false) The default value for all is 'true'. --- include/proxysql_glovars.hpp | 4 +++ lib/MySQL_Thread.cpp | 8 +++-- lib/PgSQL_Thread.cpp | 8 +++-- lib/ProxySQL_Admin.cpp | 4 +-- lib/ProxySQL_GloVars.cpp | 64 ++++++++++++++++++++++++++++++++++ src/main.cpp | 67 ++++++++++++++++++++++-------------- 6 files changed, 121 insertions(+), 34 deletions(-) diff --git a/include/proxysql_glovars.hpp b/include/proxysql_glovars.hpp index f758662d31..dc9353aab5 100644 --- a/include/proxysql_glovars.hpp +++ b/include/proxysql_glovars.hpp @@ -88,6 +88,10 @@ class ProxySQL_GlobalVariables { bool gdbg; bool nostart; bool my_monitor; + bool mysql_workers; + bool pgsql_workers; + bool mysql_admin; + bool pgsql_admin; bool pg_monitor; bool version_check; #ifdef SO_REUSEPORT diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index 958b905980..5a8ba22c34 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -2060,8 +2060,10 @@ bool MySQL_Threads_Handler::set_variable(char *name, const char *value) { // thi } } if (!strcasecmp(name,"threads")) { - unsigned int intv=atoi(value); - if ((num_threads==0 || num_threads==intv || mysql_threads==NULL) && intv > 0 && intv < 256) { + const uint32_t intv { !GloVars.global.mysql_workers ? uint32_t(0) : atoi(value) }; + const bool valid_val { (intv > 0 && intv < 256) || (!GloVars.global.mysql_workers && intv == 0) }; + + if ((num_threads==0 || num_threads==intv || mysql_threads==NULL) && valid_val) { num_threads=intv; this->status_variables.p_gauge_array[p_th_gauge::mysql_thread_workers]->Set(intv); return true; @@ -2405,7 +2407,7 @@ void MySQL_Threads_Handler::init(unsigned int num, size_t stack) { num_threads=num; this->status_variables.p_gauge_array[p_th_gauge::mysql_thread_workers]->Set(num); } else { - if (num_threads==0) { + if (num_threads==0 && GloVars.global.mysql_workers) { num_threads=DEFAULT_NUM_THREADS; //default this->status_variables.p_gauge_array[p_th_gauge::mysql_thread_workers]->Set(DEFAULT_NUM_THREADS); } diff --git a/lib/PgSQL_Thread.cpp b/lib/PgSQL_Thread.cpp index f6f3c6a53e..9f5112997c 100644 --- a/lib/PgSQL_Thread.cpp +++ b/lib/PgSQL_Thread.cpp @@ -1997,8 +1997,10 @@ bool PgSQL_Threads_Handler::set_variable(char* name, const char* value) { // thi } } if (!strcasecmp(name, "threads")) { - unsigned int intv = atoi(value); - if ((num_threads == 0 || num_threads == intv || pgsql_threads == NULL) && intv > 0 && intv < 256) { + const uint32_t intv { !GloVars.global.pgsql_workers ? uint32_t(0) : atoi(value) }; + const bool valid_val { (intv > 0 && intv < 256) || (!GloVars.global.pgsql_workers && intv == 0) }; + + if ((num_threads == 0 || num_threads == intv || pgsql_threads == NULL) && valid_val) { num_threads = intv; //this->status_variables.p_gauge_array[p_th_gauge::mysql_thread_workers]->Set(intv); return true; @@ -2317,7 +2319,7 @@ void PgSQL_Threads_Handler::init(unsigned int num, size_t stack) { //this->status_variables.p_gauge_array[p_th_gauge::mysql_thread_workers]->Set(num); } else { - if (num_threads == 0) { + if (num_threads==0 && GloVars.global.pgsql_workers) { num_threads = DEFAULT_NUM_THREADS; //default //this->status_variables.p_gauge_array[p_th_gauge::mysql_thread_workers]->Set(DEFAULT_NUM_THREADS); } diff --git a/lib/ProxySQL_Admin.cpp b/lib/ProxySQL_Admin.cpp index a2fcfb23bb..60c0d05e60 100644 --- a/lib/ProxySQL_Admin.cpp +++ b/lib/ProxySQL_Admin.cpp @@ -2388,7 +2388,7 @@ void * admin_main_loop(void *arg) { nfds++; unsigned int j; i=0; j=0; - for (j=0; jifaces->len; j++) { + for (j=0; j < S_amll.ifaces_mysql->ifaces->len && GloVars.global.mysql_admin; j++) { char *add=NULL; char *port=NULL; char *sn=(char *)S_amll.ifaces_mysql->ifaces->index(j); bool is_ipv6 = false; char *h = NULL; @@ -2428,7 +2428,7 @@ void * admin_main_loop(void *arg) { } i = 0; j = 0; - for (; j < S_amll.ifaces_pgsql->ifaces->len; j++) { + for (; j < S_amll.ifaces_pgsql->ifaces->len && GloVars.global.pgsql_admin; j++) { char* add = NULL; char* port = NULL; char* sn = (char*)S_amll.ifaces_pgsql->ifaces->index(j); bool is_ipv6 = false; char* h = NULL; diff --git a/lib/ProxySQL_GloVars.cpp b/lib/ProxySQL_GloVars.cpp index 7273fd15bf..e80904467d 100644 --- a/lib/ProxySQL_GloVars.cpp +++ b/lib/ProxySQL_GloVars.cpp @@ -197,6 +197,10 @@ ProxySQL_GlobalVariables::ProxySQL_GlobalVariables() : global.gdbg=false; global.nostart=false; global.foreground=false; + global.mysql_workers=true; + global.pgsql_workers=true; + global.mysql_admin=true; + global.pgsql_admin=true; global.my_monitor=true; global.pg_monitor=true; #ifdef IDLE_THREADS @@ -261,6 +265,12 @@ ProxySQL_GlobalVariables::ProxySQL_GlobalVariables() : #endif /* DEBUG */ opt->add((const char *)"",0,0,0,(const char *)"Starts only the admin service",(const char *)"-n",(const char *)"--no-start"); opt->add((const char *)"",0,0,0,(const char *)"Do not start Monitor Module",(const char *)"-M",(const char *)"--no-monitor"); + opt->add((const char *)"",0,1,0,(const char *)"Do not start MySQL Monitor Module",(const char *)"--mysql-monitor"); + opt->add((const char *)"",0,1,0,(const char *)"Do not start PgSQL Monitor Module",(const char *)"--pgsql-monitor"); + opt->add((const char *)"",0,1,0,(const char *)"Do not start MySQL Worker Threads",(const char *)"--mysql-workers"); + opt->add((const char *)"",0,1,0,(const char *)"Do not start PgSQL Worker Threads",(const char *)"--pgsql-workers"); + opt->add((const char *)"",0,1,0,(const char *)"Do not start MySQL Admin Module",(const char *)"--mysql-admin"); + opt->add((const char *)"",0,1,0,(const char *)"Do not start PgSQL Admin Module",(const char *)"--pgsql-admin"); opt->add((const char *)"",0,0,0,(const char *)"Run in foreground",(const char *)"-f",(const char *)"--foreground"); #ifdef SO_REUSEPORT opt->add((const char *)"",0,0,0,(const char *)"Use SO_REUSEPORT",(const char *)"-r",(const char *)"--reuseport"); @@ -486,6 +496,60 @@ void ProxySQL_GlobalVariables::process_opts_post() { global.pg_monitor=false; } + if (opt->isSet("--mysql-monitor")) { + string val {}; + opt->get("--mysql-monitor")->getString(val); + + if (val == "false" || val == "0") { + global.my_monitor = false; + } + } + + if (opt->isSet("--pgsql-monitor")) { + string val {}; + opt->get("--pgsql-monitor")->getString(val); + + if (val == "false" || val == "0") { + global.pg_monitor = false; + } + } + + if (opt->isSet("--mysql-workers")) { + string val {}; + opt->get("--mysql-workers")->getString(val); + + if (val == "false" || val == "0") { + global.mysql_workers = false; + } + } + + if (opt->isSet("--pgsql-workers")) { + string val {}; + opt->get("--pgsql-workers")->getString(val); + + if (val == "false" || val == "0") { + global.pgsql_workers = false; + } + } + + if (opt->isSet("--mysql-admin")) { + string val {}; + opt->get("--mysql-admin")->getString(val); + + if (val == "false" || val == "0") { + global.mysql_admin = false; + } + } + + if (opt->isSet("--pgsql-admin")) { + string val {}; + opt->get("--pgsql-admin")->getString(val); + + if (val == "false" || val == "0") { + global.pgsql_admin = false; + } + } + #ifdef SO_REUSEPORT { struct utsname unameData; diff --git a/src/main.cpp b/src/main.cpp index 4fcc2ff57c..af2259a234 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -672,10 +672,21 @@ void* unified_query_cache_purge_thread(void *arg) { return NULL; } -/*void* pgsql_shared_query_cache_funct(void* arg) { - GloPgQC->purgeHash_thread(NULL); - return NULL; -}*/ +template +void update_global_variable(const string& name, T& var) { + const Setting& root { GloVars.confFile->cfg.getRoot() }; + + if (root.exists(name)==true) { + T new_val {}; + bool rc { root.lookupValue(name, new_val) }; + + if (rc == true) { + var = new_val; + } else { + proxy_error("The config file is configured with an invalid '%s'\n", name.c_str()); + } + } +} void ProxySQL_Main_process_global_variables(int argc, const char **argv) { GloVars.errorlog = NULL; @@ -731,27 +742,17 @@ void ProxySQL_Main_process_global_variables(int argc, const char **argv) { } } } + // if cluster_sync_interfaces is true, interfaces variables are synced too - if (root.exists("cluster_sync_interfaces")==true) { - bool value_bool; - bool rc; - rc=root.lookupValue("cluster_sync_interfaces", value_bool); - if (rc==true) { - GloVars.cluster_sync_interfaces=value_bool; - } else { - proxy_error("The config file is configured with an invalid cluster_sync_interfaces\n"); - } - } - if (root.exists("set_thread_name")==true) { - bool value_bool; - bool rc; - rc=root.lookupValue("set_thread_name", value_bool); - if (rc==true) { - GloVars.set_thread_name=value_bool; - } else { - proxy_error("The config file is configured with an invalid set_thread_name\n"); - } - } + update_global_variable("cluster_sync_interfaces", GloVars.cluster_sync_interfaces); + update_global_variable("set_thread_name", GloVars.set_thread_name); + update_global_variable("mysql-workers", GloVars.global.mysql_workers); + update_global_variable("pgsql-workers", GloVars.global.pgsql_workers); + update_global_variable("mysql-admin", GloVars.global.mysql_admin); + update_global_variable("pgsql-admin", GloVars.global.pgsql_admin); + update_global_variable("mysql-monitor", GloVars.global.my_monitor); + update_global_variable("pgsql-monitor", GloVars.global.pg_monitor); + if (root.exists("pidfile")==true) { string pidfile_path; bool rc; @@ -886,6 +887,20 @@ void ProxySQL_Main_process_global_variables(int argc, const char **argv) { GloVars.confFile->ReadGlobals(); GloVars.process_opts_post(); + + // Coherence check on global variables status + if (!GloVars.global.mysql_admin && !GloVars.global.pgsql_admin) { + proxy_info("All Admin interfaces, MySQL and PostgreSQL, disabled by config\n"); + } + if (!GloVars.global.mysql_workers && !GloVars.global.pgsql_workers) { + proxy_info("All worker threads, MySQL and PostgreSQL, disabled by config\n"); + } + if (!GloVars.global.my_monitor && !GloVars.global.pg_monitor) { + proxy_info("All Monitoring, MySQL and PostgreSQL, disabled by config\n"); + } + if (!GloVars.global.pgsql_workers && !GloVars.global.pgsql_admin && !GloVars.global.pg_monitor) { + proxy_info("PostgreSQL support fully disabled by config\n"); + } } void ProxySQL_Main_init_main_modules() { @@ -986,7 +1001,7 @@ void ProxySQL_Main_init_MySQL_Threads_Handler_module() { proxy_warning("proxysql instance running without --idle-threads : enabling it can potentially improve performance\n"); } #endif // IDLE_THREADS - for (i=0; inum_threads; i++) { + for (i=0; i < GloMTH->num_threads && GloVars.global.mysql_workers; i++) { GloMTH->create_thread(i,mysql_worker_thread_func, false); #ifdef IDLE_THREADS if (GloVars.global.idle_threads) { @@ -1010,7 +1025,7 @@ void ProxySQL_Main_init_PgSQL_Threads_Handler_module() { proxy_warning("proxysql instance running without --idle-threads : enabling it can potentially improve performance\n"); } #endif // IDLE_THREADS - for (i = 0; i < GloPTH->num_threads; i++) { + for (i = 0; i < GloPTH->num_threads && GloVars.global.pgsql_workers; i++) { GloPTH->create_thread(i, pgsql_worker_thread_func, false); #ifdef IDLE_THREADS if (GloVars.global.idle_threads) { From 26298bfeda9a9217c851a732a088dea1f0c98d2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Wed, 21 May 2025 13:32:55 +0200 Subject: [PATCH 3/5] Remove old commented code --- lib/ProxySQL_Admin.cpp | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/lib/ProxySQL_Admin.cpp b/lib/ProxySQL_Admin.cpp index 60c0d05e60..e976950b6d 100644 --- a/lib/ProxySQL_Admin.cpp +++ b/lib/ProxySQL_Admin.cpp @@ -2258,9 +2258,6 @@ void * admin_main_loop(void *arg) { __sync_fetch_and_add(&admin_load_main_,1); while (glovars.shutdown==0 && *shutdown==0) { - //int *client; - //int client_t; - //socklen_t addr_size = sizeof(addr); pthread_t child; size_t stacks; unsigned long long curtime=monotonic_time(); @@ -2293,13 +2290,9 @@ void * admin_main_loop(void *arg) { passarg->addr_size = sizeof(custom_sockaddr); memset(passarg->addr, 0, sizeof(custom_sockaddr)); passarg->client_t = accept(fds[i].fd, (struct sockaddr*)passarg->addr, &passarg->addr_size); -// printf("Connected: %s:%d sock=%d\n", inet_ntoa(addr.sin_addr), ntohs(addr.sin_port), client_t); pthread_attr_getstacksize (&attr, &stacks); -// printf("Default stack size = %d\n", stacks); pthread_mutex_lock (&sock_mutex); - //client=(int *)malloc(sizeof(int)); - //*client= client_t; - //if ( pthread_create(&child, &attr, child_func[callback_func[i]], client) != 0 ) { + if ( pthread_create(&child, &attr, child_func[callback_func[i]], passarg) != 0 ) { // LCOV_EXCL_START perror("pthread_create"); @@ -2412,7 +2405,7 @@ void * admin_main_loop(void *arg) { #else int s = ( atoi(port) ? listen_on_port(add, atoi(port), 128) : listen_on_unix(add, 128)); #endif - //if (s>0) { fds[nfds].fd=s; fds[nfds].events=POLLIN; fds[nfds].revents=0; callback_func[nfds]=0; socket_names[nfds]=strdup(sn); nfds++; } + if (s > 0) { fds[nfds].fd = s; fds[nfds].events = POLLIN; @@ -2453,7 +2446,7 @@ void * admin_main_loop(void *arg) { #else int s = (atoi(port) ? listen_on_port(add, atoi(port), 128) : listen_on_unix(add, 128)); #endif - //if (s>0) { fds[nfds].fd=s; fds[nfds].events=POLLIN; fds[nfds].revents=0; callback_func[nfds]=0; socket_names[nfds]=strdup(sn); nfds++; } + if (s > 0) { fds[nfds].fd = s; fds[nfds].events = POLLIN; @@ -2471,7 +2464,7 @@ void * admin_main_loop(void *arg) { } } - //if (__sync_add_and_fetch(shutdown,0)==0) __sync_add_and_fetch(shutdown,1); + for (i=0; i Date: Wed, 21 May 2025 13:34:01 +0200 Subject: [PATCH 4/5] Fix indentation and scope match for 'if' condition Since editors sometimes don't completely disable non-reachable code, like macro-protected, it's cleaner too keep parenthesis open/close outside this. Otherwise this can confuse editors scope matching. --- lib/ProxySQL_Admin.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/ProxySQL_Admin.cpp b/lib/ProxySQL_Admin.cpp index e976950b6d..35f9211d9c 100644 --- a/lib/ProxySQL_Admin.cpp +++ b/lib/ProxySQL_Admin.cpp @@ -2318,12 +2318,15 @@ void * admin_main_loop(void *arg) { if (resultset) { SQLite3_result * resultset2 = NULL; - // In debug, run the code to generate metrics so that it can be tested even if the web interface plugin isn't loaded. - #ifdef DEBUG - if (true) { - #else - if (GloVars.web_interface_plugin) { - #endif + // In debug, run the code to generate metrics so that it can be tested even if + // the 'web_interface_plugin' isn't loaded. + if ( + #ifdef DEBUG + true + #else + GloVars.web_interface_plugin + #endif + ) { resultset2 = MyHGM->SQL3_Connection_Pool(false); } GloProxyStats->MyHGM_Handler_sets(resultset, resultset2); From 18a7eab1ad176f975f7834b0598954bd8c826c71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Wed, 21 May 2025 14:01:43 +0200 Subject: [PATCH 5/5] Fix 'MySQLWorker' threads naming --- 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 5a8ba22c34..358786d5e1 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -2462,7 +2462,7 @@ proxysql_mysql_thread_t * MySQL_Threads_Handler::create_thread(unsigned int tn, if (GloVars.set_thread_name == true) { char thr_name[16]; snprintf(thr_name, sizeof(thr_name), "MySQLIdle%d", tn); - pthread_setname_np(mysql_threads[tn].thread_id, thr_name); + pthread_setname_np(mysql_threads_idles[tn].thread_id, thr_name); } } #endif // defined(__linux__) || defined(__FreeBSD__)