Skip to content

Commit

Permalink
Do not kill Session if a backend failed
Browse files Browse the repository at this point in the history
This new algorithm makes the backend connection fails instead of killing the session
This is an improvement over issue #1085
  • Loading branch information
renecannao committed Feb 28, 2019
1 parent 278605c commit d1b467e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/MySQL_Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ class MySQL_Session
void MySQL_Stmt_Result_to_MySQL_wire(MYSQL_STMT *stmt, MySQL_Connection *myconn);
unsigned int NumActiveTransactions();
bool HasOfflineBackends();
bool SetEventInOfflineBackends();
int FindOneActiveTransaction();
unsigned long long IdleTime();

Expand Down
17 changes: 17 additions & 0 deletions lib/MySQL_Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4902,6 +4902,23 @@ bool MySQL_Session::HasOfflineBackends() {
return ret;
}

bool MySQL_Session::SetEventInOfflineBackends() {
bool ret=false;
if (mybes==0) return ret;
MySQL_Backend *_mybe;
unsigned int i;
for (i=0; i < mybes->len; i++) {
_mybe=(MySQL_Backend *)mybes->index(i);
if (_mybe->server_myds)
if (_mybe->server_myds->myconn)
if (_mybe->server_myds->myconn->IsServerOffline()) {
_mybe->server_myds->revents|=POLLIN;
ret = true;
}
}
return ret;
}

int MySQL_Session::FindOneActiveTransaction() {
int ret=-1;
if (mybes==0) return ret;
Expand Down
10 changes: 8 additions & 2 deletions lib/MySQL_Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3579,8 +3579,14 @@ void MySQL_Thread::process_all_sessions() {
}
if (servers_table_version_current != servers_table_version_previous) { // bug fix for #1085
// Immediatelly kill all client connections using an OFFLINE node
if (sess->HasOfflineBackends()) {
sess->killed=true;
//if (sess->HasOfflineBackends()) {
// sess->killed=true;
//}
// Search for connections that should be terminated, and simulate data in them
// the following 2 lines of code replace the previous 2 lines
// instead of killing the sessions, fails the backend connections
if (sess->SetEventInOfflineBackends()) {
sess->to_process=1;
}
}
}
Expand Down

0 comments on commit d1b467e

Please sign in to comment.