Skip to content

Commit ee61753

Browse files
committed
Resolve merge conflict in groups.json - include both PR tests
2 parents fb638a7 + 2304303 commit ee61753

File tree

9 files changed

+1251
-53
lines changed

9 files changed

+1251
-53
lines changed

include/proxysql_glovars.hpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,50 @@ class ProxySQL_GlobalVariables {
8787
unsigned long long start_time;
8888
bool gdbg;
8989
bool nostart;
90+
/**
91+
* @brief Disable/Enable the MySQL Monitor module.
92+
* @details Meant to be configured as an startup switch. Possible to change it's value only via a
93+
* command line switch or via config file option.
94+
*/
9095
bool my_monitor;
96+
/**
97+
* @brief Disable/Enable the PostgreSQL Monitor module.
98+
* @details Meant to be configured as an startup switch. Possible to change it's value only via a
99+
* command line switch or via config file option.
100+
*/
91101
bool pg_monitor;
102+
/**
103+
* @brief Disable/Enable the MySQL Workers module. This disables ProxySQL capability for handling
104+
* MySQL traffic to be routed to the MySQL backend servers.
105+
* @details Meant to be configured as an startup switch. Possible to change it's value only via a
106+
* command line switch or via config file option. Disabling this module doesn't affect MySQL
107+
* Monitoring.
108+
*/
109+
bool mysql_workers;
110+
/**
111+
* @brief Disable/Enable the PostgreSQL Workers module. This disables ProxySQL capability for handling
112+
* PostgreSQL traffic to be routed to the PostgreSQL backend servers.
113+
* @details Meant to be configured as an startup switch. Possible to change it's value only via a
114+
* command line switch or via config file option. Disabling this module doesn't affect PostgreSQL
115+
* Monitoring.
116+
*/
117+
bool pgsql_workers;
118+
/**
119+
* @brief Disable/Enable MySQL Admin module. This disables access, via MySQL protocol, to
120+
* ProxySQL Administration interface.
121+
* @details Meant to be configured as an startup switch. Possible to change it's value only via a
122+
* command line switch or via config file option. It's important to notice that Administrative access
123+
* remains possible via PostgreSQL Admin interface, if enabled.
124+
*/
125+
bool mysql_admin;
126+
/**
127+
* @brief Disable/Enable PostgreSQL Admin module. This disables access, via PostgreSQL
128+
* protocol, to ProxySQL Administration interface.
129+
* @details Meant to be configured as an startup switch. Possible to change it's value only via a
130+
* command line switch or via config file option. It's important to notice that Administrative access
131+
* remains possible via the MySQL Admin interface, if enabled.
132+
*/
133+
bool pgsql_admin;
92134
bool version_check;
93135
#ifdef SO_REUSEPORT
94136
bool reuseport;

lib/MySQL_Thread.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,8 +2073,10 @@ bool MySQL_Threads_Handler::set_variable(char *name, const char *value) { // thi
20732073
}
20742074
}
20752075
if (!strcasecmp(name,"threads")) {
2076-
unsigned int intv=atoi(value);
2077-
if ((num_threads==0 || num_threads==intv || mysql_threads==NULL) && intv > 0 && intv < 256) {
2076+
const uint32_t intv { !GloVars.global.mysql_workers ? uint32_t(0) : atoi(value) };
2077+
const bool valid_val { (intv > 0 && intv < 256) || (!GloVars.global.mysql_workers && intv == 0) };
2078+
2079+
if ((num_threads==0 || num_threads==intv || mysql_threads==NULL) && valid_val) {
20782080
num_threads=intv;
20792081
this->status_variables.p_gauge_array[p_th_gauge::mysql_thread_workers]->Set(intv);
20802082
return true;
@@ -2428,7 +2430,7 @@ void MySQL_Threads_Handler::init(unsigned int num, size_t stack) {
24282430
num_threads=num;
24292431
this->status_variables.p_gauge_array[p_th_gauge::mysql_thread_workers]->Set(num);
24302432
} else {
2431-
if (num_threads==0) {
2433+
if (num_threads==0 && GloVars.global.mysql_workers) {
24322434
num_threads=DEFAULT_NUM_THREADS; //default
24332435
this->status_variables.p_gauge_array[p_th_gauge::mysql_thread_workers]->Set(DEFAULT_NUM_THREADS);
24342436
}
@@ -2483,7 +2485,7 @@ proxysql_mysql_thread_t * MySQL_Threads_Handler::create_thread(unsigned int tn,
24832485
if (GloVars.set_thread_name == true) {
24842486
char thr_name[16];
24852487
snprintf(thr_name, sizeof(thr_name), "MySQLIdle%d", tn);
2486-
pthread_setname_np(mysql_threads[tn].thread_id, thr_name);
2488+
pthread_setname_np(mysql_threads_idles[tn].thread_id, thr_name);
24872489
}
24882490
}
24892491
#endif // defined(__linux__) || defined(__FreeBSD__)

lib/PgSQL_Thread.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,8 +1962,10 @@ bool PgSQL_Threads_Handler::set_variable(char* name, const char* value) { // thi
19621962
}
19631963
}
19641964
if (!strcasecmp(name, "threads")) {
1965-
unsigned int intv = atoi(value);
1966-
if ((num_threads == 0 || num_threads == intv || pgsql_threads == NULL) && intv > 0 && intv < 256) {
1965+
const uint32_t intv { !GloVars.global.pgsql_workers ? uint32_t(0) : atoi(value) };
1966+
const bool valid_val { (intv > 0 && intv < 256) || (!GloVars.global.pgsql_workers && intv == 0) };
1967+
1968+
if ((num_threads == 0 || num_threads == intv || pgsql_threads == NULL) && valid_val) {
19671969
num_threads = intv;
19681970
//this->status_variables.p_gauge_array[p_th_gauge::mysql_thread_workers]->Set(intv);
19691971
return true;
@@ -2277,7 +2279,7 @@ void PgSQL_Threads_Handler::init(unsigned int num, size_t stack) {
22772279
//this->status_variables.p_gauge_array[p_th_gauge::mysql_thread_workers]->Set(num);
22782280
}
22792281
else {
2280-
if (num_threads == 0) {
2282+
if (num_threads==0 && GloVars.global.pgsql_workers) {
22812283
num_threads = DEFAULT_NUM_THREADS; //default
22822284
//this->status_variables.p_gauge_array[p_th_gauge::mysql_thread_workers]->Set(DEFAULT_NUM_THREADS);
22832285
}

lib/ProxySQL_Admin.cpp

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,9 +2248,6 @@ void * admin_main_loop(void *arg) {
22482248
__sync_fetch_and_add(&admin_load_main_,1);
22492249
while (glovars.shutdown==0 && *shutdown==0)
22502250
{
2251-
//int *client;
2252-
//int client_t;
2253-
//socklen_t addr_size = sizeof(addr);
22542251
pthread_t child;
22552252
size_t stacks;
22562253
unsigned long long curtime=monotonic_time();
@@ -2283,13 +2280,9 @@ void * admin_main_loop(void *arg) {
22832280
passarg->addr_size = sizeof(custom_sockaddr);
22842281
memset(passarg->addr, 0, sizeof(custom_sockaddr));
22852282
passarg->client_t = accept(fds[i].fd, (struct sockaddr*)passarg->addr, &passarg->addr_size);
2286-
// printf("Connected: %s:%d sock=%d\n", inet_ntoa(addr.sin_addr), ntohs(addr.sin_port), client_t);
22872283
pthread_attr_getstacksize (&attr, &stacks);
2288-
// printf("Default stack size = %d\n", stacks);
22892284
pthread_mutex_lock (&sock_mutex);
2290-
//client=(int *)malloc(sizeof(int));
2291-
//*client= client_t;
2292-
//if ( pthread_create(&child, &attr, child_func[callback_func[i]], client) != 0 ) {
2285+
22932286
if ( pthread_create(&child, &attr, child_func[callback_func[i]], passarg) != 0 ) {
22942287
// LCOV_EXCL_START
22952288
perror("pthread_create");
@@ -2315,12 +2308,15 @@ void * admin_main_loop(void *arg) {
23152308
if (resultset) {
23162309
SQLite3_result * resultset2 = NULL;
23172310

2318-
// In debug, run the code to generate metrics so that it can be tested even if the web interface plugin isn't loaded.
2319-
#ifdef DEBUG
2320-
if (true) {
2321-
#else
2322-
if (GloVars.web_interface_plugin) {
2323-
#endif
2311+
// In debug, run the code to generate metrics so that it can be tested even if
2312+
// the 'web_interface_plugin' isn't loaded.
2313+
if (
2314+
#ifdef DEBUG
2315+
true
2316+
#else
2317+
GloVars.web_interface_plugin
2318+
#endif
2319+
) {
23242320
resultset2 = MyHGM->SQL3_Connection_Pool(false);
23252321
}
23262322
GloProxyStats->MyHGM_Handler_sets(resultset, resultset2);
@@ -2378,7 +2374,7 @@ void * admin_main_loop(void *arg) {
23782374
nfds++;
23792375
unsigned int j;
23802376
i=0; j=0;
2381-
for (j=0; j<S_amll.ifaces_mysql->ifaces->len; j++) {
2377+
for (j=0; j < S_amll.ifaces_mysql->ifaces->len && GloVars.global.mysql_admin; j++) {
23822378
char *add=NULL; char *port=NULL; char *sn=(char *)S_amll.ifaces_mysql->ifaces->index(j);
23832379
bool is_ipv6 = false;
23842380
char *h = NULL;
@@ -2402,7 +2398,7 @@ void * admin_main_loop(void *arg) {
24022398
#else
24032399
int s = ( atoi(port) ? listen_on_port(add, atoi(port), 128) : listen_on_unix(add, 128));
24042400
#endif
2405-
//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++; }
2401+
24062402
if (s > 0) {
24072403
fds[nfds].fd = s;
24082404
fds[nfds].events = POLLIN;
@@ -2418,7 +2414,7 @@ void * admin_main_loop(void *arg) {
24182414
}
24192415

24202416
i = 0; j = 0;
2421-
for (; j < S_amll.ifaces_pgsql->ifaces->len; j++) {
2417+
for (; j < S_amll.ifaces_pgsql->ifaces->len && GloVars.global.pgsql_admin; j++) {
24222418
char* add = NULL; char* port = NULL; char* sn = (char*)S_amll.ifaces_pgsql->ifaces->index(j);
24232419
bool is_ipv6 = false;
24242420
char* h = NULL;
@@ -2443,7 +2439,7 @@ void * admin_main_loop(void *arg) {
24432439
#else
24442440
int s = (atoi(port) ? listen_on_port(add, atoi(port), 128) : listen_on_unix(add, 128));
24452441
#endif
2446-
//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++; }
2442+
24472443
if (s > 0) {
24482444
fds[nfds].fd = s;
24492445
fds[nfds].events = POLLIN;
@@ -2461,7 +2457,7 @@ void * admin_main_loop(void *arg) {
24612457
}
24622458

24632459
}
2464-
//if (__sync_add_and_fetch(shutdown,0)==0) __sync_add_and_fetch(shutdown,1);
2460+
24652461
for (i=0; i<nfds; i++) {
24662462
char *add=NULL; char *port=NULL;
24672463
close(fds[i].fd);

lib/ProxySQL_GloVars.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ ProxySQL_GlobalVariables::ProxySQL_GlobalVariables() :
197197
global.gdbg=false;
198198
global.nostart=false;
199199
global.foreground=false;
200+
global.mysql_workers=true;
201+
global.pgsql_workers=true;
202+
global.mysql_admin=true;
203+
global.pgsql_admin=true;
200204
global.my_monitor=true;
201205
global.pg_monitor=true;
202206
#ifdef IDLE_THREADS
@@ -262,6 +266,12 @@ ProxySQL_GlobalVariables::ProxySQL_GlobalVariables() :
262266
#endif /* DEBUG */
263267
opt->add((const char *)"",0,0,0,(const char *)"Starts only the admin service",(const char *)"-n",(const char *)"--no-start");
264268
opt->add((const char *)"",0,0,0,(const char *)"Do not start Monitor Module",(const char *)"-M",(const char *)"--no-monitor");
269+
opt->add((const char *)"",0,1,0,(const char *)"Do not start MySQL Monitor Module",(const char *)"--mysql-monitor");
270+
opt->add((const char *)"",0,1,0,(const char *)"Do not start PgSQL Monitor Module",(const char *)"--pgsql-monitor");
271+
opt->add((const char *)"",0,1,0,(const char *)"Do not start MySQL Worker Threads",(const char *)"--mysql-workers");
272+
opt->add((const char *)"",0,1,0,(const char *)"Do not start PgSQL Worker Threads",(const char *)"--pgsql-workers");
273+
opt->add((const char *)"",0,1,0,(const char *)"Do not start MySQL Admin Module",(const char *)"--mysql-admin");
274+
opt->add((const char *)"",0,1,0,(const char *)"Do not start PgSQL Admin Module",(const char *)"--pgsql-admin");
265275
opt->add((const char *)"",0,0,0,(const char *)"Run in foreground",(const char *)"-f",(const char *)"--foreground");
266276
#ifdef SO_REUSEPORT
267277
opt->add((const char *)"",0,0,0,(const char *)"Use SO_REUSEPORT",(const char *)"-r",(const char *)"--reuseport");
@@ -490,6 +500,60 @@ void ProxySQL_GlobalVariables::process_opts_post() {
490500
global.pg_monitor=false;
491501
}
492502

503+
if (opt->isSet("--mysql-monitor")) {
504+
string val {};
505+
opt->get("--mysql-monitor")->getString(val);
506+
507+
if (val == "false" || val == "0") {
508+
global.my_monitor = false;
509+
}
510+
}
511+
512+
if (opt->isSet("--pgsql-monitor")) {
513+
string val {};
514+
opt->get("--pgsql-monitor")->getString(val);
515+
516+
if (val == "false" || val == "0") {
517+
global.pg_monitor = false;
518+
}
519+
}
520+
521+
if (opt->isSet("--mysql-workers")) {
522+
string val {};
523+
opt->get("--mysql-workers")->getString(val);
524+
525+
if (val == "false" || val == "0") {
526+
global.mysql_workers = false;
527+
}
528+
}
529+
530+
if (opt->isSet("--pgsql-workers")) {
531+
string val {};
532+
opt->get("--pgsql-workers")->getString(val);
533+
534+
if (val == "false" || val == "0") {
535+
global.pgsql_workers = false;
536+
}
537+
}
538+
539+
if (opt->isSet("--mysql-admin")) {
540+
string val {};
541+
opt->get("--mysql-admin")->getString(val);
542+
543+
if (val == "false" || val == "0") {
544+
global.mysql_admin = false;
545+
}
546+
}
547+
548+
if (opt->isSet("--pgsql-admin")) {
549+
string val {};
550+
opt->get("--pgsql-admin")->getString(val);
551+
552+
if (val == "false" || val == "0") {
553+
global.pgsql_admin = false;
554+
}
555+
}
556+
493557
#ifdef SO_REUSEPORT
494558
{
495559
struct utsname unameData;

0 commit comments

Comments
 (0)