From 58a1b2d612e57c5c199d3111027e901488cfe2ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Mon, 7 Aug 2017 17:39:04 +0200 Subject: [PATCH] Moved match_regexes in MySQL_Thread #1127 --- include/MySQL_Session.h | 3 ++- include/MySQL_Thread.h | 2 ++ lib/MySQL_Session.cpp | 11 +++++++---- lib/MySQL_Thread.cpp | 28 ++++++++++++++++++++++++++-- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/include/MySQL_Session.h b/include/MySQL_Session.h index 279603354..594feb871 100644 --- a/include/MySQL_Session.h +++ b/include/MySQL_Session.h @@ -109,7 +109,6 @@ class MySQL_Session // it is an attempt to start simplifying the complexing of handler() PtrSize_t *pktH; - Session_Regex **match_regexes; public: void * operator new(size_t); @@ -167,6 +166,8 @@ class MySQL_Session MySQL_STMTs_meta *sess_STMTs_meta; StmtLongDataHandler *SLDH; + Session_Regex **match_regexes; + MySQL_Session(); ~MySQL_Session(); diff --git a/include/MySQL_Thread.h b/include/MySQL_Thread.h index f58977610..6236b5a80 100644 --- a/include/MySQL_Thread.h +++ b/include/MySQL_Thread.h @@ -171,6 +171,8 @@ class MySQL_Thread std::map sessmap; #endif // IDLE_THREADS + Session_Regex **match_regexes; + protected: int nfds; diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index 883dac6a6..735cdc3bf 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -268,11 +268,12 @@ MySQL_Session::MySQL_Session() { active_transactions=0; match_regexes=NULL; +/* match_regexes=(Session_Regex **)malloc(sizeof(Session_Regex *)*3); match_regexes[0]=new Session_Regex((char *)"^SET (|SESSION |@@|@@session.)SQL_LOG_BIN( *)(:|)=( *)"); match_regexes[1]=new Session_Regex((char *)"^SET (|SESSION |@@|@@session.)SQL_MODE( *)(:|)=( *)"); match_regexes[2]=new Session_Regex((char *)"^SET (|SESSION |@@|@@session.)TIME_ZONE( *)(:|)=( *)"); - +*/ init(); // we moved this out to allow CHANGE_USER last_insert_id=0; // #1093 @@ -328,6 +329,7 @@ MySQL_Session::~MySQL_Session() { assert(qpo); delete qpo; { +/* Session_Regex *sr=NULL; sr=match_regexes[0]; delete sr; @@ -336,6 +338,7 @@ MySQL_Session::~MySQL_Session() { sr=match_regexes[2]; delete sr; free(match_regexes); +*/ match_regexes=NULL; } if (mirror) { @@ -3391,7 +3394,7 @@ bool MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C int rc; string nq=string((char *)CurrentQuery.QueryPointer,CurrentQuery.QueryLength); RE2::GlobalReplace(&nq,(char *)"(?U)/\\*.*\\*/",(char *)""); - if (match_regexes[0]->match(dig)) { + if (match_regexes && match_regexes[0]->match(dig)) { re2::RE2::Options *opt2=new re2::RE2::Options(RE2::Quiet); opt2->set_case_sensitive(false); char *pattern=(char *)"(?: *)SET *(?:|SESSION +|@@|@@session.)SQL_LOG_BIN *(?:|:)= *(\\d+) *(?:(|;|-- .*|#.*))$"; @@ -3419,7 +3422,7 @@ bool MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C return false; } } - if (match_regexes[1]->match(dig)) { + if (match_regexes && match_regexes[1]->match(dig)) { // set sql_mode re2::RE2::Options *opt2=new re2::RE2::Options(RE2::Quiet); opt2->set_case_sensitive(false); @@ -3456,7 +3459,7 @@ bool MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C return false; } } - if (match_regexes[2]->match(dig)) { + if (match_regexes && match_regexes[2]->match(dig)) { // set time_zone re2::RE2::Options *opt2=new re2::RE2::Options(RE2::Quiet); opt2->set_case_sensitive(false); diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index eec827ad4..efd6aff15 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -2049,6 +2049,20 @@ MySQL_Thread::~MySQL_Thread() { if (mysql_thread___ssl_p2s_cert) { free(mysql_thread___ssl_p2s_cert); mysql_thread___ssl_p2s_cert=NULL; } if (mysql_thread___ssl_p2s_key) { free(mysql_thread___ssl_p2s_key); mysql_thread___ssl_p2s_key=NULL; } if (mysql_thread___ssl_p2s_cipher) { free(mysql_thread___ssl_p2s_cipher); mysql_thread___ssl_p2s_cipher=NULL; } + + + if (match_regexes) { + Session_Regex *sr=NULL; + sr=match_regexes[0]; + delete sr; + sr=match_regexes[1]; + delete sr; + sr=match_regexes[2]; + delete sr; + free(match_regexes); + match_regexes=NULL; + } + } MySQL_Session * MySQL_Thread::create_new_session_and_client_data_stream(int _fd) { @@ -2107,6 +2121,13 @@ bool MySQL_Thread::init() { ioctl_FIONBIO(pipefd[1],1); mypolls.add(POLLIN, pipefd[0], NULL, 0); assert(i==0); + + match_regexes=(Session_Regex **)malloc(sizeof(Session_Regex *)*3); + match_regexes[0]=new Session_Regex((char *)"^SET (|SESSION |@@|@@session.)SQL_LOG_BIN( *)(:|)=( *)"); + match_regexes[1]=new Session_Regex((char *)"^SET (|SESSION |@@|@@session.)SQL_MODE( *)(:|)=( *)"); + match_regexes[2]=new Session_Regex((char *)"^SET (|SESSION |@@|@@session.)TIME_ZONE( *)(:|)=( *)"); + + return true; } @@ -2139,6 +2160,7 @@ void MySQL_Thread::register_session(MySQL_Session *_sess, bool up_start) { } mysql_sessions->add(_sess); _sess->thread=this; + _sess->match_regexes=match_regexes; if (up_start) _sess->start_time=curtime; proxy_debug(PROXY_DEBUG_NET,1,"Thread=%p, Session=%p -- Registered new session\n", _sess->thread, _sess); @@ -3132,6 +3154,8 @@ MySQL_Thread::MySQL_Thread() { status_variables.ConnPool_get_conn_success=0; status_variables.ConnPool_get_conn_failure=0; status_variables.active_transactions=0; + + match_regexes=NULL; } void MySQL_Thread::register_session_connection_handler(MySQL_Session *_sess, bool _new) { @@ -3160,10 +3184,10 @@ void MySQL_Thread::listener_handle_new_connection(MySQL_Data_Stream *myds, unsig // there are more than 1 thread . We pause for a little bit to avoid all connections to be handled by the same thread #ifdef SO_REUSEPORT if (GloVars.global.reuseport==false) { // only if reuseport is not enabled - usleep(10+rand()%50); + //usleep(10+rand()%50); } #else - usleep(10+rand()%50); + //usleep(10+rand()%50); #endif /* SO_REUSEPORT */ } c=accept(myds->fd, addr, &addrlen);