From f4c7df34cf01a76baac43aeccb25723c96d69fb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Sat, 16 Jul 2016 00:54:49 +0000 Subject: [PATCH] Limit the amount of data received by a backend Issue #527 Limit the amount of data received by a backend during a single poll() iteration. Right now the default is mysql_thread___threshold_resultset_size*2, and it is arbitary. Unrelated to #527, MySQL_Connection::async_ping() was modified to return a different value in case of timeout --- lib/MySQL_Session.cpp | 9 +++++++-- lib/mysql_connection.cpp | 16 +++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index 4bc0ce791..d3fd35a3b 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -944,8 +944,13 @@ handler_again: set_status(NONE); return -1; } else { - if (rc==-1) { - proxy_error("Detected a broken connection during ping on %s , %d\n", myconn->parent->address, myconn->parent->port); + if (rc==-1 || rc==-2) { + if (rc==-2) { + proxy_error("Ping timeout during ping on %s , %d\n", myconn->parent->address, myconn->parent->port); + } else { // rc==-1 + int myerr=mysql_errno(myconn->mysql); + proxy_error("Detected a broken connection during ping on (%d,%s,%d) , FD (Conn:%d , MyDS:%d) : %d, %s\n", myconn->parent->myhgc->hid, myconn->parent->address, myconn->parent->port, myds->fd, myds->myconn->fd, myerr, mysql_error(myconn->mysql)); + } myds->destroy_MySQL_Connection_From_Pool(false); myds->fd=0; delete mybe->server_myds; diff --git a/lib/mysql_connection.cpp b/lib/mysql_connection.cpp index f7ceee64d..f95347f32 100644 --- a/lib/mysql_connection.cpp +++ b/lib/mysql_connection.cpp @@ -453,6 +453,7 @@ void MySQL_Connection::store_result_cont(short event) { #define NEXT_IMMEDIATE(new_st) do { async_state_machine = new_st; goto handler_again; } while (0) MDB_ASYNC_ST MySQL_Connection::handler(short event) { + unsigned int processed_bytes=0; // issue #527 : this variable will store the amount of bytes processed during this event if (mysql==NULL) { // it is the first time handler() is being called async_state_machine=ASYNC_CONNECT_START; @@ -697,7 +698,12 @@ handler_again: unsigned int br=MyRS->add_row(mysql_row); __sync_fetch_and_add(&parent->bytes_recv,br); myds->sess->thread->status_variables.queries_backends_bytes_recv+=br; - NEXT_IMMEDIATE(ASYNC_USE_RESULT_CONT); + processed_bytes+=br; // issue #527 : this variable will store the amount of bytes processed during this event + if (processed_bytes > (unsigned int)mysql_thread___threshold_resultset_size*2) { + next_event(ASYNC_USE_RESULT_CONT); // we temporarily pause + } else { + NEXT_IMMEDIATE(ASYNC_USE_RESULT_CONT); // we continue looping + } } else { MyRS->add_eof(); NEXT_IMMEDIATE(ASYNC_QUERY_END); @@ -947,9 +953,11 @@ int MySQL_Connection::async_ping(short event) { return 0; break; case ASYNC_PING_FAILED: - case ASYNC_PING_TIMEOUT: return -1; break; + case ASYNC_PING_TIMEOUT: + return -2; + break; case ASYNC_IDLE: async_state_machine=ASYNC_PING_START; default: @@ -964,9 +972,11 @@ int MySQL_Connection::async_ping(short event) { return 0; break; case ASYNC_PING_FAILED: - case ASYNC_PING_TIMEOUT: return -1; break; + case ASYNC_PING_TIMEOUT: + return -2; + break; default: return 1; break;