Skip to content

Commit

Permalink
Fixed accounting of Server_Connections_connected
Browse files Browse the repository at this point in the history
  • Loading branch information
renecannao committed Feb 3, 2016
1 parent 19bbce4 commit 2ea4149
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions lib/MySQL_HostGroups_Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ bool MySQL_HostGroups_Manager::commit() {
proxy_warning("Removed server at address %lld, hostgroup %s, address %s port %s. Setting status OFFLINE HARD and immediately dropping all free connections. Used connections will be dropped when trying to use them\n", ptr, r->fields[1], r->fields[2], r->fields[3]);
MySrvC *mysrvc=(MySrvC *)ptr;
mysrvc->status=MYSQL_SERVER_STATUS_OFFLINE_HARD;
__sync_fetch_and_sub(&status.server_connections_connected, mysrvc->ConnectionsFree->conns->len);
//__sync_fetch_and_sub(&status.server_connections_connected, mysrvc->ConnectionsFree->conns->len);
mysrvc->ConnectionsFree->drop_all_connections();
}
}
Expand Down Expand Up @@ -706,7 +706,7 @@ void MySQL_HostGroups_Manager::destroy_MyConn_from_pool(MySQL_Connection *c) {
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL, 7, "Destroying MySQL_Connection %p, server %s:%d\n", c, mysrvc->address, mysrvc->port);
mysrvc->ConnectionsUsed->remove(c);
status.myconnpoll_destroy++;
status.server_connections_connected--;
//status.server_connections_connected--;
wrunlock();
delete c;
}
Expand Down Expand Up @@ -762,22 +762,22 @@ void MySQL_HostGroups_Manager::drop_all_idle_connections() {
MySrvC *mysrvc=(MySrvC *)myhgc->mysrvs->servers->index(j);
if (mysrvc->status!=MYSQL_SERVER_STATUS_ONLINE) {
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL, 5, "Server %s:%d is not online\n", mysrvc->address, mysrvc->port);
__sync_fetch_and_sub(&status.server_connections_connected, mysrvc->ConnectionsFree->conns->len);
//__sync_fetch_and_sub(&status.server_connections_connected, mysrvc->ConnectionsFree->conns->len);
mysrvc->ConnectionsFree->drop_all_connections();
}

// Drop idle connections if beyond max_connection
while (mysrvc->ConnectionsFree->conns->len && mysrvc->ConnectionsUsed->conns->len+mysrvc->ConnectionsFree->conns->len > mysrvc->max_connections) {
MySQL_Connection *conn=(MySQL_Connection *)mysrvc->ConnectionsFree->conns->remove_index_fast(0);
delete conn;
__sync_fetch_and_sub(&status.server_connections_connected, 1);
//__sync_fetch_and_sub(&status.server_connections_connected, 1);
}

PtrArray *pa=mysrvc->ConnectionsFree->conns;
while (pa->len > mysql_thread___free_connections_pct*mysrvc->max_connections/100) {
MySQL_Connection *mc=(MySQL_Connection *)pa->remove_index_fast(0);
delete mc;
__sync_fetch_and_sub(&status.server_connections_connected, 1);
//__sync_fetch_and_sub(&status.server_connections_connected, 1);
}
}
}
Expand Down Expand Up @@ -856,14 +856,14 @@ SQLite3_result * MySQL_HostGroups_Manager::SQL3_Connection_Pool() {
MySrvC *mysrvc=(MySrvC *)myhgc->mysrvs->servers->index(j);
if (mysrvc->status!=MYSQL_SERVER_STATUS_ONLINE) {
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL, 5, "Server %s:%d is not online\n", mysrvc->address, mysrvc->port);
__sync_fetch_and_sub(&status.server_connections_connected, mysrvc->ConnectionsFree->conns->len);
//__sync_fetch_and_sub(&status.server_connections_connected, mysrvc->ConnectionsFree->conns->len);
mysrvc->ConnectionsFree->drop_all_connections();
}
// drop idle connections if beyond max_connection
while (mysrvc->ConnectionsFree->conns->len && mysrvc->ConnectionsUsed->conns->len+mysrvc->ConnectionsFree->conns->len > mysrvc->max_connections) {
MySQL_Connection *conn=(MySQL_Connection *)mysrvc->ConnectionsFree->conns->remove_index_fast(0);
delete conn;
__sync_fetch_and_sub(&status.server_connections_connected, 1);
//__sync_fetch_and_sub(&status.server_connections_connected, 1);
}
char buf[1024];
char **pta=(char **)malloc(sizeof(char *)*colnum);
Expand Down
2 changes: 1 addition & 1 deletion lib/mysql_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,14 +468,14 @@ MDB_ASYNC_ST MySQL_Connection::handler(short event) {
case ASYNC_CONNECT_END:
if (!ret_mysql) {
// always increase the counter
__sync_fetch_and_add(&MyHGM->status.server_connections_connected,1);
proxy_error("Failed to mysql_real_connect() on %s:%d , %d: %s\n", parent->address, parent->port, mysql_errno(mysql), mysql_error(mysql));
NEXT_IMMEDIATE(ASYNC_CONNECT_FAILED);
} else {
NEXT_IMMEDIATE(ASYNC_CONNECT_SUCCESSFUL);
}
break;
case ASYNC_CONNECT_SUCCESSFUL:
__sync_fetch_and_add(&MyHGM->status.server_connections_connected,1);
__sync_fetch_and_add(&parent->connect_OK,1);
break;
case ASYNC_CONNECT_FAILED:
Expand Down

0 comments on commit 2ea4149

Please sign in to comment.