Skip to content

Commit

Permalink
Add global variable mysql-kill_backend_connection_when_disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
renecannao committed Aug 6, 2018
1 parent e3a35e0 commit d23ed74
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
1 change: 1 addition & 0 deletions include/MySQL_Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ class MySQL_Threads_Handler
int query_cache_size_MB;
bool stats_time_backend_query;
bool stats_time_query_processor;
bool kill_backend_connection_when_disconnect;
} variables;
struct {
unsigned int mirror_sessions_current;
Expand Down
2 changes: 2 additions & 0 deletions include/proxysql_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@ __thread bool mysql_thread___default_reconnect;
__thread bool mysql_thread___session_idle_show_processlist;
__thread bool mysql_thread___sessions_sort;
__thread bool mysql_thread___session_idle_ms;
__thread bool mysql_thread___kill_backend_connection_when_disconnect;

/* variables used for Query Cache */
__thread int mysql_thread___query_cache_size_MB;
Expand Down Expand Up @@ -750,6 +751,7 @@ extern __thread bool mysql_thread___default_reconnect;
extern __thread bool mysql_thread___session_idle_show_processlist;
extern __thread bool mysql_thread___sessions_sort;
extern __thread bool mysql_thread___session_idle_ms;
extern __thread bool mysql_thread___kill_backend_connection_when_disconnect;

/* variables used for Query Cache */
extern __thread int mysql_thread___query_cache_size_MB;
Expand Down
30 changes: 16 additions & 14 deletions lib/MySQL_HostGroups_Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1531,22 +1531,24 @@ void MySQL_HostGroups_Manager::destroy_MyConn_from_pool(MySQL_Connection *c, boo
// the connection seems health, but we are trying to destroy it
// probably because there is a long running query
// therefore we will try to kill the connection
MySQL_Connection_userinfo *ui=c->userinfo;
char *auth_password=NULL;
if (ui->password) {
if (ui->password[0]=='*') { // we don't have the real password, let's pass sha1
auth_password=ui->sha1_pass;
} else {
auth_password=ui->password;
if (mysql_thread___kill_backend_connection_when_disconnect) {
MySQL_Connection_userinfo *ui=c->userinfo;
char *auth_password=NULL;
if (ui->password) {
if (ui->password[0]=='*') { // we don't have the real password, let's pass sha1
auth_password=ui->sha1_pass;
} else {
auth_password=ui->password;
}
}
KillArgs *ka = new KillArgs(ui->username, auth_password, c->parent->address, c->parent->port, c->mysql->thread_id, KILL_CONNECTION);
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
pthread_attr_setstacksize (&attr, 256*1024);
pthread_t pt;
pthread_create(&pt, &attr, &kill_query_thread, ka);
}
KillArgs *ka = new KillArgs(ui->username, auth_password, c->parent->address, c->parent->port, c->mysql->thread_id, KILL_CONNECTION);
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
pthread_attr_setstacksize (&attr, 256*1024);
pthread_t pt;
pthread_create(&pt, &attr, &kill_query_thread, ka);
}
}
if (to_del) {
Expand Down
18 changes: 18 additions & 0 deletions lib/MySQL_Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ static char * mysql_thread_variables_names[]= {
(char *)"poll_timeout_on_failure",
(char *)"server_capabilities",
(char *)"server_version",
(char *)"kill_backend_connection_when_disconnect",
(char *)"sessions_sort",
#ifdef IDLE_THREADS
(char *)"session_idle_show_processlist",
Expand Down Expand Up @@ -419,6 +420,7 @@ MySQL_Threads_Handler::MySQL_Threads_Handler() {
variables.connpoll_reset_queue_length = 50;
variables.stats_time_backend_query=false;
variables.stats_time_query_processor=false;
variables.kill_backend_connection_when_disconnect=true;
variables.sessions_sort=true;
#ifdef IDLE_THREADS
variables.session_idle_ms=1000;
Expand Down Expand Up @@ -672,6 +674,7 @@ int MySQL_Threads_Handler::get_variable_int(char *name) {
if (!strcasecmp(name,"connpoll_reset_queue_length")) return (int)variables.connpoll_reset_queue_length;
if (!strcasecmp(name,"stats_time_backend_query")) return (int)variables.stats_time_backend_query;
if (!strcasecmp(name,"stats_time_query_processor")) return (int)variables.stats_time_query_processor;
if (!strcasecmp(name,"kill_backend_connection_when_disconnect")) return (int)variables.kill_backend_connection_when_disconnect;
if (!strcasecmp(name,"sessions_sort")) return (int)variables.sessions_sort;
#ifdef IDLE_THREADS
if (!strcasecmp(name,"session_idle_show_processlist")) return (int)variables.session_idle_show_processlist;
Expand Down Expand Up @@ -1052,6 +1055,9 @@ char * MySQL_Threads_Handler::get_variable(char *name) { // this is the public f
if (!strcasecmp(name,"stats_time_query_processor")) {
return strdup((variables.stats_time_query_processor ? "true" : "false"));
}
if (!strcasecmp(name,"kill_backend_connection_when_disconnect")) {
return strdup((variables.kill_backend_connection_when_disconnect ? "true" : "false"));
}
if (!strcasecmp(name,"sessions_sort")) {
return strdup((variables.sessions_sort ? "true" : "false"));
}
Expand Down Expand Up @@ -2033,6 +2039,17 @@ bool MySQL_Threads_Handler::set_variable(char *name, char *value) { // this is t
}
return false;
}
if (!strcasecmp(name,"kill_backend_connection_when_disconnect")) {
if (strcasecmp(value,"true")==0 || strcasecmp(value,"1")==0) {
variables.kill_backend_connection_when_disconnect=true;
return true;
}
if (strcasecmp(value,"false")==0 || strcasecmp(value,"0")==0) {
variables.kill_backend_connection_when_disconnect=false;
return true;
}
return false;
}
if (!strcasecmp(name,"servers_stats")) {
if (strcasecmp(value,"true")==0 || strcasecmp(value,"1")==0) {
variables.servers_stats=true;
Expand Down Expand Up @@ -3389,6 +3406,7 @@ void MySQL_Thread::refresh_variables() {
mysql_thread___query_digests_lowercase=(bool)GloMTH->get_variable_int((char *)"query_digests_lowercase");
variables.stats_time_backend_query=(bool)GloMTH->get_variable_int((char *)"stats_time_backend_query");
variables.stats_time_query_processor=(bool)GloMTH->get_variable_int((char *)"stats_time_query_processor");
mysql_thread___kill_backend_connection_when_disconnect=(bool)GloMTH->get_variable_int((char *)"kill_backend_connection_when_disconnect");
mysql_thread___sessions_sort=(bool)GloMTH->get_variable_int((char *)"sessions_sort");
#ifdef IDLE_THREADS
mysql_thread___session_idle_show_processlist=(bool)GloMTH->get_variable_int((char *)"session_idle_show_processlist");
Expand Down

0 comments on commit d23ed74

Please sign in to comment.