Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions include/proxysql_glovars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,50 @@ class ProxySQL_GlobalVariables {
unsigned long long start_time;
bool gdbg;
bool nostart;
/**
* @brief Disable/Enable the MySQL Monitor module.
* @details Meant to be configured as an startup switch. Possible to change it's value only via a
* command line switch or via config file option.
*/
bool my_monitor;
/**
* @brief Disable/Enable the PostgreSQL Monitor module.
* @details Meant to be configured as an startup switch. Possible to change it's value only via a
* command line switch or via config file option.
*/
bool pg_monitor;
/**
* @brief Disable/Enable the MySQL Workers module. This disables ProxySQL capability for handling
* MySQL traffic to be routed to the MySQL backend servers.
* @details Meant to be configured as an startup switch. Possible to change it's value only via a
* command line switch or via config file option. Disabling this module doesn't affect MySQL
* Monitoring.
*/
bool mysql_workers;
/**
* @brief Disable/Enable the PostgreSQL Workers module. This disables ProxySQL capability for handling
* PostgreSQL traffic to be routed to the PostgreSQL backend servers.
* @details Meant to be configured as an startup switch. Possible to change it's value only via a
* command line switch or via config file option. Disabling this module doesn't affect PostgreSQL
* Monitoring.
*/
bool pgsql_workers;
/**
* @brief Disable/Enable MySQL Admin module. This disables access, via MySQL protocol, to
* ProxySQL Administration interface.
* @details Meant to be configured as an startup switch. Possible to change it's value only via a
* command line switch or via config file option. It's important to notice that Administrative access
* remains possible via PostgreSQL Admin interface, if enabled.
*/
bool mysql_admin;
/**
* @brief Disable/Enable PostgreSQL Admin module. This disables access, via PostgreSQL
* protocol, to ProxySQL Administration interface.
* @details Meant to be configured as an startup switch. Possible to change it's value only via a
* command line switch or via config file option. It's important to notice that Administrative access
* remains possible via the MySQL Admin interface, if enabled.
*/
bool pgsql_admin;
bool version_check;
#ifdef SO_REUSEPORT
bool reuseport;
Expand Down
10 changes: 6 additions & 4 deletions lib/MySQL_Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2073,8 +2073,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;
Expand Down Expand Up @@ -2428,7 +2430,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);
}
Expand Down Expand Up @@ -2483,7 +2485,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__)
Expand Down
8 changes: 5 additions & 3 deletions lib/PgSQL_Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1962,8 +1962,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;
Expand Down Expand Up @@ -2277,7 +2279,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);
}
Expand Down
34 changes: 15 additions & 19 deletions lib/ProxySQL_Admin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2248,9 +2248,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();
Expand Down Expand Up @@ -2283,13 +2280,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");
Expand All @@ -2315,12 +2308,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);
Expand Down Expand Up @@ -2378,7 +2374,7 @@ void * admin_main_loop(void *arg) {
nfds++;
unsigned int j;
i=0; j=0;
for (j=0; j<S_amll.ifaces_mysql->ifaces->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;
Expand All @@ -2402,7 +2398,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;
Expand All @@ -2418,7 +2414,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;
Expand All @@ -2443,7 +2439,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;
Expand All @@ -2461,7 +2457,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<nfds; i++) {
char *add=NULL; char *port=NULL;
close(fds[i].fd);
Expand Down
64 changes: 64 additions & 0 deletions lib/ProxySQL_GloVars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@
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
Expand Down Expand Up @@ -262,6 +266,12 @@
#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");
Expand Down Expand Up @@ -468,7 +478,7 @@
proxysql_keylog_init();
};

void ProxySQL_GlobalVariables::process_opts_post() {

Check failure on line 481 in lib/ProxySQL_GloVars.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 43 to the 25 allowed.

See more on https://sonarcloud.io/project/issues?id=sysown_proxysql&issues=AZqvUW1uhJMJg08I36yS&open=AZqvUW1uhJMJg08I36yS&pullRequest=4960

if (opt->isSet("-n")) {
//global.nostart=true;
Expand All @@ -490,6 +500,60 @@
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;
Expand Down
Loading