Implemented variable mysql-poll_timeout_on_failure (issue #251)

pull/252/head
René Cannaò 11 years ago
parent 29e19b78f1
commit 77dbe91974

@ -343,6 +343,7 @@ class Standard_MySQL_Threads_Handler: public MySQL_Threads_Handler
#endif /* DEBUG */
uint16_t server_capabilities;
int poll_timeout;
int poll_timeout_on_failure;
} variables;
PtrArray *bind_fds;
MySQL_Listeners_Manager *MLM;

@ -621,6 +621,7 @@ __thread char *mysql_thread___connect_timeout_server_error;
__thread uint16_t mysql_thread___server_capabilities;
__thread uint8_t mysql_thread___default_charset;
__thread int mysql_thread___poll_timeout;
__thread int mysql_thread___poll_timeout_on_failure;
__thread bool mysql_thread___have_compress;
__thread bool mysql_thread___servers_stats;
#ifdef DEBUG
@ -641,6 +642,7 @@ extern __thread char *mysql_thread___connect_timeout_server_error;
extern __thread uint16_t mysql_thread___server_capabilities;
extern __thread uint8_t mysql_thread___default_charset;
extern __thread int mysql_thread___poll_timeout;
extern __thread int mysql_thread___poll_timeout_on_failure;
extern __thread bool mysql_thread___have_compress;
extern __thread bool mysql_thread___servers_stats;
#ifdef DEBUG

@ -1280,7 +1280,15 @@ void MySQL_Session::handler___client_DSS_QUERY_SENT___server_DSS_NOT_INITIALIZED
mybe->server_myds->myconn=MyHGM->get_MyConn_from_pool(mybe->hostgroup_id);
// }
proxy_debug(PROXY_DEBUG_MYSQL_CONNECTION, 5, "Sess=%p -- server_myds=%p -- MySQL_Connection %p\n", this, mybe->server_myds, mybe->server_myds->myconn);
if (mybe->server_myds->myconn==NULL) { return; }
if (mybe->server_myds->myconn==NULL) {
// we couldn't get a connection for whatever reason, ex: no backends, or too busy
if (thread->mypolls.poll_timeout==0) { // tune poll timeout
if (thread->mypolls.poll_timeout > mysql_thread___poll_timeout_on_failure) {
thread->mypolls.poll_timeout = mysql_thread___poll_timeout_on_failure;
}
}
return;
}
if (mybe->server_myds->myconn->fd==-1) {
// we didn't get a valid connection, we need to create one
proxy_debug(PROXY_DEBUG_MYSQL_CONNECTION, 5, "Sess=%p -- MySQL Connection has no FD\n", this);

@ -121,6 +121,7 @@ static char * mysql_thread_variables_names[]= {
(char *)"ping_timeout_server",
(char *)"default_schema",
(char *)"poll_timeout",
(char *)"poll_timeout_on_failure",
(char *)"server_capabilities",
(char *)"server_version",
(char *)"servers_stats",
@ -157,6 +158,7 @@ Standard_MySQL_Threads_Handler::Standard_MySQL_Threads_Handler() {
variables.server_version=strdup((char *)"5.1.30");
variables.server_capabilities=CLIENT_FOUND_ROWS | CLIENT_PROTOCOL_41 | CLIENT_IGNORE_SIGPIPE | CLIENT_TRANSACTIONS | CLIENT_SECURE_CONNECTION | CLIENT_CONNECT_WITH_DB | CLIENT_SSL;
variables.poll_timeout=2000;
variables.poll_timeout_on_failure=100;
variables.have_compress=true;
variables.servers_stats=true;
#ifdef DEBUG
@ -261,6 +263,7 @@ int Standard_MySQL_Threads_Handler::get_variable_int(char *name) {
if (!strcmp(name,"have_compress")) return (int)variables.have_compress;
if (!strcmp(name,"servers_stats")) return (int)variables.servers_stats;
if (!strcmp(name,"poll_timeout")) return variables.poll_timeout;
if (!strcmp(name,"poll_timeout_on_failure")) return variables.poll_timeout_on_failure;
if (!strcmp(name,"stacksize")) return ( stacksize ? stacksize : DEFAULT_STACK_SIZE);
proxy_error("Not existing variable: %s\n", name); assert(0);
return 0;
@ -298,6 +301,10 @@ char * Standard_MySQL_Threads_Handler::get_variable(char *name) { // this is the
sprintf(intbuf,"%d",variables.poll_timeout);
return strdup(intbuf);
}
if (!strcmp(name,"poll_timeout_on_failure")) {
sprintf(intbuf,"%d",variables.poll_timeout_on_failure);
return strdup(intbuf);
}
if (!strcmp(name,"threads")) {
sprintf(intbuf,"%d", (num_threads ? num_threads : DEFAULT_NUM_THREADS));
return strdup(intbuf);
@ -415,6 +422,15 @@ bool Standard_MySQL_Threads_Handler::set_variable(char *name, char *value) { //
return false;
}
}
if (!strcmp(name,"poll_timeout_on_failure")) {
int intv=atoi(value);
if (intv > 10 && intv < 20000) {
variables.poll_timeout_on_failure=intv;
return true;
} else {
return false;
}
}
if (!strcmp(name,"default_charset")) {
int intv=atoi(value);
if (intv > 0 && intv < 256) {
@ -977,6 +993,7 @@ void Standard_MySQL_Thread::refresh_variables() {
mysql_thread___server_capabilities=GloMTH->get_variable_uint16((char *)"server_capabilities");
mysql_thread___default_charset=GloMTH->get_variable_uint8((char *)"default_charset");
mysql_thread___poll_timeout=GloMTH->get_variable_int((char *)"poll_timeout");
mysql_thread___poll_timeout_on_failure=GloMTH->get_variable_int((char *)"poll_timeout_on_failure");
mysql_thread___have_compress=(bool)GloMTH->get_variable_int((char *)"have_compress");
mysql_thread___servers_stats=(bool)GloMTH->get_variable_int((char *)"servers_stats");
#ifdef DEBUG

Loading…
Cancel
Save