Skip to content

Commit

Permalink
Merge pull request #1867 from sysown/v2.0.0-conn_pool_username
Browse files Browse the repository at this point in the history
Optimize connection pool to find matching username
  • Loading branch information
renecannao authored Jan 21, 2019
2 parents 1797144 + 11924ca commit 68ae38b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 4 additions & 3 deletions lib/MySQL_HostGroups_Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2341,21 +2341,22 @@ 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;
}
}
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;
}
Expand Down
6 changes: 4 additions & 2 deletions lib/MySQL_Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 68ae38b

Please sign in to comment.