From ca1704ba4051fa2b936370b2d02f4ae4e5e6c825 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Fri, 30 Jan 2015 12:47:48 +0000 Subject: [PATCH] Bug fixes Fixed crashing bug in Admin module when ProxySQL is started with --no-start When a client connection is terminated, the backend connection is returned to connection pool on if not in a transaction --- lib/MySQL_Session.cpp | 6 +++++- lib/Standard_ProxySQL_Admin.cpp | 3 +++ lib/mysql_backend.cpp | 3 ++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index 0e32b24e0..256704dfd 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -347,6 +347,9 @@ int MySQL_Session::handler() { handler___client_DSS_QUERY_SENT___server_DSS_NOT_INITIALIZED__get_connection(); + // FIXME : handle missing connection from connection pool + // FIXME : perhaps is a goto __exit_DSS__STATE_NOT_INITIALIZED after setting time wait + thread->mypolls.add(POLLIN|POLLOUT, server_fd, server_myds, curtime); if (server_myds->DSS!=STATE_READY) { @@ -518,7 +521,7 @@ void MySQL_Session::handler___status_WAITING_SERVER_DATA___STATE_EOF1(PtrSize_t if (c==0xfe) { myprot_server.process_pkt_EOF((unsigned char *)pkt->ptr,pkt->size); //fprintf(stderr,"hid=%d status=%d\n", mybe->hostgroup_id, myprot_server.prot_status); - if ((myprot_server.prot_status & SERVER_STATUS_IN_TRANS)==0) { + if ((mybe->myconn->reusable==true) && ((myprot_server.prot_status & SERVER_STATUS_IN_TRANS)==0)) { MyHGM->push_MyConn_to_pool(mybe->myconn); mybe->myconn=NULL; server_myds->unplug_backend(); @@ -752,6 +755,7 @@ void MySQL_Session::handler___client_DSS_QUERY_SENT___server_DSS_NOT_INITIALIZED // Get a MySQL Connection mybe->myconn=MyHGM->get_MyConn_from_pool(mybe->hostgroup_id); + mybe->myconn->myds=server_myds; if (mybe->myconn->fd==-1) { // we didn't get a valid connection, we need to create one diff --git a/lib/Standard_ProxySQL_Admin.cpp b/lib/Standard_ProxySQL_Admin.cpp index c8d36e205..00fa07a62 100644 --- a/lib/Standard_ProxySQL_Admin.cpp +++ b/lib/Standard_ProxySQL_Admin.cpp @@ -1925,6 +1925,7 @@ bool Standard_ProxySQL_Admin::set_variable(char *name, char *value) { // this i void Standard_ProxySQL_Admin::stats___mysql_commands_counters() { + if (!GloQPro) return; SQLite3_result * resultset=GloQPro->get_stats_commands_counters(); if (resultset==NULL) return; // fprintf(stderr,"Number of columns: %d, rows: %d\n", result->columns, result->rows_count); @@ -1946,7 +1947,9 @@ void Standard_ProxySQL_Admin::stats___mysql_commands_counters() { statsdb->execute("COMMIT"); delete resultset; } + void Standard_ProxySQL_Admin::stats___mysql_query_rules() { + if (!GloQPro) return; SQLite3_result * resultset=GloQPro->get_stats_query_rules(); if (resultset==NULL) return; // fprintf(stderr,"Number of columns: %d, rows: %d\n", result->columns, result->rows_count); diff --git a/lib/mysql_backend.cpp b/lib/mysql_backend.cpp index a0542d058..0852b7cc3 100644 --- a/lib/mysql_backend.cpp +++ b/lib/mysql_backend.cpp @@ -160,7 +160,7 @@ void MySQL_Backend::reset() { server_myds=NULL; } if (myconn) { - if (myconn->reusable==true) { + if (myconn->reusable==true && ((myconn->myds->sess->myprot_server.prot_status & SERVER_STATUS_IN_TRANS)==0)) { //server_myds->myconn=NULL; //delete myconn; MyHGM->push_MyConn_to_pool(myconn); @@ -168,6 +168,7 @@ void MySQL_Backend::reset() { myconn=NULL; } else { // MyConnArray *MCA=MyConnPool->MyConnArray_lookup(myconn->mshge->MSptr->address, myconn->myconn.user, myconn->mshge->MSptr->password, myconn->mshge->MSptr->db, myconn->mshge->MSptr->port); + MyHGM->destroy_MyConn_from_pool(myconn); delete myconn; } };