From 11924ca1294d809aa742bd3db0d0cc008a8e68ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Wed, 16 Jan 2019 00:07:28 +1100 Subject: [PATCH] Optimize connection pool to find matching username Try to get from connection pool and connections cache, a connection with the same schemaname --- lib/MySQL_HostGroups_Manager.cpp | 7 ++++--- lib/MySQL_Thread.cpp | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/MySQL_HostGroups_Manager.cpp b/lib/MySQL_HostGroups_Manager.cpp index c6b9e150c..c63ad7264 100644 --- a/lib/MySQL_HostGroups_Manager.cpp +++ b/lib/MySQL_HostGroups_Manager.cpp @@ -2341,13 +2341,14 @@ MySQL_Connection * MySrvConnList::get_random_MyConn(MySQL_Session *sess, bool ff i=fastrand()%l; } if (sess && sess->client_myds && sess->client_myds->myconn && sess->client_myds->myconn->userinfo) { - // try to match schemaname + // try to match schemaname AND username char *schema = sess->client_myds->myconn->userinfo->schemaname; + char *username = sess->client_myds->myconn->userinfo->username; bool conn_found = false; unsigned int k; for (k = i; conn_found == false && k < l; k++) { conn = (MySQL_Connection *)conns->index(k); - if (strcmp(conn->userinfo->schemaname,schema)==0) { + if (strcmp(conn->userinfo->schemaname,schema)==0 && strcmp(conn->userinfo->username,username)==0) { conn_found = true; i = k; } @@ -2355,7 +2356,7 @@ MySQL_Connection * MySrvConnList::get_random_MyConn(MySQL_Session *sess, bool ff if (conn_found == false ) { for (k = 0; conn_found == false && k < i; k++) { conn = (MySQL_Connection *)conns->index(k); - if (strcmp(conn->userinfo->schemaname,schema)==0) { + if (strcmp(conn->userinfo->schemaname,schema)==0 && strcmp(conn->userinfo->username,username)==0) { conn_found = true; i = k; } diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index 0528898c7..4703a3bbe 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -5097,7 +5097,8 @@ MySQL_Connection * MySQL_Thread::get_MyConn_local(unsigned int _hid, MySQL_Sessi //npc++; if (sess && sess->client_myds && sess->client_myds->myconn && sess->client_myds->myconn->userinfo) { char *schema = sess->client_myds->myconn->userinfo->schemaname; - if (strcmp(c->userinfo->schemaname,schema)==0) { + char *username = sess->client_myds->myconn->userinfo->username; + if (strcmp(c->userinfo->schemaname,schema)==0 && strcmp(c->userinfo->username,username)==0) { c=(MySQL_Connection *)cached_connections->remove_index_fast(i); return c; } @@ -5125,7 +5126,8 @@ MySQL_Connection * MySQL_Thread::get_MyConn_local(unsigned int _hid, MySQL_Sessi npc++; if (sess && sess->client_myds && sess->client_myds->myconn && sess->client_myds->myconn->userinfo) { char *schema = sess->client_myds->myconn->userinfo->schemaname; - if (strcmp(c->userinfo->schemaname,schema)==0) { + char *username = sess->client_myds->myconn->userinfo->username; + if (strcmp(c->userinfo->schemaname,schema)==0 && strcmp(c->userinfo->username,username)==0) { c=(MySQL_Connection *)cached_connections->remove_index_fast(i); return c; }