diff --git a/include/MySQL_Thread.h b/include/MySQL_Thread.h index a15b9637e..11fe67130 100644 --- a/include/MySQL_Thread.h +++ b/include/MySQL_Thread.h @@ -178,6 +178,7 @@ class MySQL_Thread unsigned long long curtime; unsigned long long pre_poll_time; unsigned long long last_maintenance_time; + unsigned long long last_move_to_idle_thread_time; std::atomic atomic_curtime; PtrArray *mysql_sessions; PtrArray *mirror_queue_mysql_sessions; diff --git a/include/gen_utils.h b/include/gen_utils.h index 7cda6981d..f2fa0105b 100644 --- a/include/gen_utils.h +++ b/include/gen_utils.h @@ -41,9 +41,9 @@ class PtrArray { size=new_size; } public: - void **pdata; unsigned int len; unsigned int size; + void **pdata; PtrArray(unsigned int __size=0) { len=0; pdata=NULL; @@ -128,9 +128,9 @@ class PtrSizeArray { public: void * operator new(size_t); void operator delete(void *); - PtrSize_t *pdata; unsigned int len; unsigned int size; + PtrSize_t *pdata; PtrSizeArray(unsigned int __size=0); ~PtrSizeArray(); diff --git a/include/proxysql_structs.h b/include/proxysql_structs.h index d41ab6271..49fded5dd 100644 --- a/include/proxysql_structs.h +++ b/include/proxysql_structs.h @@ -493,8 +493,8 @@ struct __SQP_query_parser_t { }; struct _PtrSize_t { - void *ptr; unsigned int size; + void *ptr; }; // struct for debugging module #ifdef DEBUG diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index 6aec0b149..560186068 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -2964,13 +2964,22 @@ void MySQL_Thread::run___get_multiple_idle_connections(int& num_idles) { // this function was inline in MySQL_Thread::run() void MySQL_Thread::ProcessAllMyDS_BeforePoll() { + bool check_if_move_to_idle_thread = false; +#ifdef IDLE_THREADS + if (GloVars.global.idle_threads) { + if (curtime > last_move_to_idle_thread_time + (unsigned long long)mysql_thread___session_idle_ms * 1000) { + last_move_to_idle_thread_time=curtime; + check_if_move_to_idle_thread=true; + } + } +#endif for (unsigned int n = 0; n < mypolls.len; n++) { MySQL_Data_Stream *myds=NULL; myds=mypolls.myds[n]; mypolls.fds[n].revents=0; if (myds) { #ifdef IDLE_THREADS - if (GloVars.global.idle_threads) { + if (check_if_move_to_idle_thread == true) { // here we try to move it to the maintenance thread if (myds->myds_type==MYDS_FRONTEND && myds->sess) { if (myds->DSS==STATE_SLEEP && myds->sess->status==WAITING_CLIENT_DATA) { @@ -4055,6 +4064,7 @@ MySQL_Thread::MySQL_Thread() { mysql_thread___ssl_p2s_crlpath=NULL; last_maintenance_time=0; + last_move_to_idle_thread_time=0; maintenance_loop=true; retrieve_gtids_required = false; diff --git a/lib/mysql_data_stream.cpp b/lib/mysql_data_stream.cpp index 1324e8d96..5f27ddff9 100644 --- a/lib/mysql_data_stream.cpp +++ b/lib/mysql_data_stream.cpp @@ -896,8 +896,9 @@ int MySQL_Data_Stream::read_pkts() { int MySQL_Data_Stream::buffer2array() { int ret=0; bool fast_mode=sess->session_fast_forward; - if (queue_data(queueIN)==0) return ret; - if ((queueIN.pkt.size==0) && queue_data(queueIN)