Skip to content

Commit

Permalink
Merge pull request #2924 from sysown/v2.0.13-2916_2918_2919_2920_2921
Browse files Browse the repository at this point in the history
Fixes #2916, #2918, #2919, #2920 and #2921
  • Loading branch information
renecannao authored Jul 11, 2020
2 parents 68f2dab + f48e4ff commit d4622b1
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion include/proxysql_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class SQLite3DB;
extern const char* config_header;

class ProxySQL_Config {
SQLite3DB* admindb;
public:
SQLite3DB* admindb;
ProxySQL_Config(SQLite3DB* db);
virtual ~ProxySQL_Config();

Expand Down
1 change: 1 addition & 0 deletions include/proxysql_glovars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class ProxySQL_GlobalVariables {
#ifdef PROXYSQLCLICKHOUSE
bool clickhouse_server;
#endif /* PROXYSQLCLICKHOUSE */
pthread_mutex_t ext_glomth_mutex;
} global;
struct mysql {
char *server_version;
Expand Down
2 changes: 1 addition & 1 deletion include/proxysql_restapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class Restapi_Row {
};

class ProxySQL_Restapi {
SQLite3DB* admindb;
public:
SQLite3DB* admindb;
ProxySQL_Restapi(SQLite3DB* db);
virtual ~ProxySQL_Restapi();

Expand Down
2 changes: 2 additions & 0 deletions lib/MySQL_Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4360,6 +4360,7 @@ void MySQL_Thread::process_all_sessions() {
}

void MySQL_Thread::refresh_variables() {
pthread_mutex_lock(&GloVars.global.ext_glomth_mutex);
if (GloMTH==NULL) {
return;
}
Expand Down Expand Up @@ -4538,6 +4539,7 @@ void MySQL_Thread::refresh_variables() {
mysql_thread___session_debug=(bool)GloMTH->get_variable_int((char *)"session_debug");
#endif /* DEBUG */
GloMTH->wrunlock();
pthread_mutex_unlock(&GloVars.global.ext_glomth_mutex);
}

MySQL_Thread::MySQL_Thread() {
Expand Down
24 changes: 24 additions & 0 deletions lib/ProxySQL_Admin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,11 +575,17 @@ int ProxySQL_Test___GetDigestTable(bool reset, bool use_swap) {

ProxySQL_Config& ProxySQL_Admin::proxysql_config() {
static ProxySQL_Config instance = ProxySQL_Config(admindb);
if (instance.admindb != admindb) {
instance.admindb = admindb;
}
return instance;
}

ProxySQL_Restapi& ProxySQL_Admin::proxysql_restapi() {
static ProxySQL_Restapi instance = ProxySQL_Restapi(admindb);
if (instance.admindb != admindb) {
instance.admindb = admindb;
}
return instance;
}

Expand Down Expand Up @@ -997,7 +1003,13 @@ bool admin_handler_command_proxysql(char *query_no_space, unsigned int query_no_
rc=__sync_bool_compare_and_swap(&GloVars.global.nostart,1,0);
}
if (rc) {
// Set the status variable 'threads_initialized' to 0 because it's initialized back
// in main 'init_phase3'. After GloMTH have been initialized again.
__sync_bool_compare_and_swap(&GloMTH->status_variables.threads_initialized, 1, 0);
proxy_debug(PROXY_DEBUG_ADMIN, 4, "Starting ProxySQL following PROXYSQL START command\n");
while(__sync_fetch_and_add(&GloMTH->status_variables.threads_initialized, 0) == 1) {
usleep(1000);
}
SPA->send_MySQL_OK(&sess->client_myds->myprot, NULL);
} else {
proxy_warning("ProxySQL was already started when received PROXYSQL START command\n");
Expand Down Expand Up @@ -1028,6 +1040,17 @@ bool admin_handler_command_proxysql(char *query_no_space, unsigned int query_no_
GloMTH->commit();
glovars.reload=2;
__sync_bool_compare_and_swap(&glovars.shutdown,0,1);
// After setting the shutdown flag, we should wake all threads and wait for
// the shutdown phase to complete.
GloMTH->signal_all_threads(0);
while (__sync_fetch_and_add(&glovars.shutdown,0)==1) {
usleep(1000);
}
// After shutdown phase is completed, we must to send a 'OK' to the
// mysql client, otherwise, since this session might not be drop due
// to the waiting condition, the client wont disconnect and will
// keep forever waiting for acknowledgement.
SPA->send_MySQL_OK(&sess->client_myds->myprot, NULL);
return false;
}

Expand Down Expand Up @@ -4396,6 +4419,7 @@ void ProxySQL_Admin::vacuum_stats(bool is_admin) {


void *child_mysql(void *arg) {
if (GloMTH == nullptr) { return NULL; }

pthread_attr_t thread_attr;
size_t tmp_stack_size=0;
Expand Down
1 change: 1 addition & 0 deletions lib/ProxySQL_GloVars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ ProxySQL_GlobalVariables::ProxySQL_GlobalVariables() {
// global.use_proxysql_mem=false;
pthread_mutex_init(&global.start_mutex,NULL);
pthread_mutex_init(&checksum_mutex,NULL);
pthread_mutex_init(&global.ext_glomth_mutex,NULL);
epoch_version = 0;
checksums_values.updates_cnt = 0;
checksums_values.dumped_at = 0;
Expand Down
3 changes: 3 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@ void * mysql_worker_thread_func(void *arg) {
worker->run();
//delete worker;
delete worker;
mysql_thread->worker=NULL;
// l_mem_destroy(__thr_sfp);
__sync_fetch_and_sub(&GloVars.statuses.stack_memory_mysql_threads,tmp_stack_size);
return NULL;
Expand Down Expand Up @@ -1165,8 +1166,10 @@ void ProxySQL_Main_shutdown_all_modules() {
}
if (GloMTH) {
cpu_timer t;
pthread_mutex_lock(&GloVars.global.ext_glomth_mutex);
delete GloMTH;
GloMTH=NULL;
pthread_mutex_unlock(&GloVars.global.ext_glomth_mutex);
#ifdef DEBUG
std::cerr << "GloMTH shutdown in ";
#endif
Expand Down

0 comments on commit d4622b1

Please sign in to comment.