Skip to content

Commit

Permalink
Bug fix for #1085
Browse files Browse the repository at this point in the history
Immediatelly kill all client connections using an OFFLINE node
  • Loading branch information
renecannao committed Jul 13, 2017
1 parent 4149a5e commit d559459
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/MySQL_Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ class MySQL_Session
void MySQL_Result_to_MySQL_wire(MYSQL *mysql, MySQL_ResultSet *MyRS, MySQL_Data_Stream *_myds=NULL);
void MySQL_Stmt_Result_to_MySQL_wire(MYSQL_STMT *stmt, MySQL_Connection *myconn);
unsigned int NumActiveTransactions();
bool HasOfflineBackends();
int FindOneActiveTransaction();
unsigned long long IdleTime();

Expand Down
2 changes: 2 additions & 0 deletions include/MySQL_Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ class ProxySQL_Poll {
class MySQL_Thread
{
private:
unsigned int servers_table_version_previous;
unsigned int servers_table_version_current;
unsigned long long last_processing_idles;
MySQL_Connection **my_idle_conns;
bool processing_idles;
Expand Down
1 change: 1 addition & 0 deletions include/mysql_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ class MySQL_Connection {
}
return ret;
}
bool IsServerOffline();
bool IsAutoCommit();
bool MultiplexDisabled();
void ProcessQueryAndSetStatusFlags(char *query_digest_text);
Expand Down
17 changes: 17 additions & 0 deletions lib/MySQL_Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3755,6 +3755,23 @@ unsigned int MySQL_Session::NumActiveTransactions() {
return ret;
}

bool MySQL_Session::HasOfflineBackends() {
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()) {
ret=true;
return ret;
}
}
return ret;
}

int MySQL_Session::FindOneActiveTransaction() {
int ret=-1;
if (mybes==0) return ret;
Expand Down
12 changes: 12 additions & 0 deletions lib/MySQL_Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2474,6 +2474,8 @@ void MySQL_Thread::run() {
if (curtime > last_maintenance_time + maintenance_interval) {
last_maintenance_time=curtime;
maintenance_loop=true;
servers_table_version_previous = servers_table_version_current;
servers_table_version_current = MyHGM->get_servers_table_version();
} else {
maintenance_loop=false;
}
Expand Down Expand Up @@ -2907,6 +2909,12 @@ void MySQL_Thread::process_all_sessions() {
if (sess_time/1000 > (unsigned long long)mysql_thread___wait_timeout) sess->killed=true;
}
}
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;
}
}
}
#ifdef IDLE_THREADS
else
Expand Down Expand Up @@ -3104,6 +3112,10 @@ MySQL_Thread::MySQL_Thread() {
status_variables.frontend_stmt_prepare=0;
status_variables.frontend_stmt_execute=0;
status_variables.frontend_stmt_close=0;

servers_table_version_previous=0;
servers_table_version_current=0;

status_variables.queries=0;
status_variables.queries_slow=0;
status_variables.queries_backends_bytes_sent=0;
Expand Down
16 changes: 16 additions & 0 deletions lib/mysql_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,22 @@ int MySQL_Connection::async_connect(short event) {
}


bool MySQL_Connection::IsServerOffline() {
bool ret=false;
if (parent==NULL)
return ret;
server_status=parent->status; // we copy it here to avoid race condition. The caller will see this
if (
(server_status==MYSQL_SERVER_STATUS_OFFLINE_HARD) // the server is OFFLINE as specific by the user
||
(server_status==MYSQL_SERVER_STATUS_SHUNNED && parent->shunned_automatic==true && parent->shunned_and_kill_all_connections==true) // the server is SHUNNED due to a serious issue
||
(server_status==MYSQL_SERVER_STATUS_SHUNNED_REPLICATION_LAG) // slave is lagging! see #774
) {
ret=true;
}
return ret;
}

// Returns:
// 0 when the query is completed
Expand Down

0 comments on commit d559459

Please sign in to comment.