From 5a554a36f61529d2cd3a0c700f5051f6a2ab06ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Fri, 23 Feb 2018 17:19:41 +0100 Subject: [PATCH] Variable mysql-binlog_reader_connect_retry_msec This variable control the retry interval to connect to binlog reader --- include/MySQL_Thread.h | 1 + lib/MySQL_HostGroups_Manager.cpp | 4 ++-- lib/MySQL_Thread.cpp | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/include/MySQL_Thread.h b/include/MySQL_Thread.h index 8ed67459d..18844f743 100644 --- a/include/MySQL_Thread.h +++ b/include/MySQL_Thread.h @@ -397,6 +397,7 @@ class MySQL_Threads_Handler int query_processor_regex; int long_query_time; int hostgroup_manager_verbose; + int binlog_reader_connect_retry_msec; char *init_connect; char *default_sql_mode; char *default_time_zone; diff --git a/lib/MySQL_HostGroups_Manager.cpp b/lib/MySQL_HostGroups_Manager.cpp index 04a240ea4..97febe6d2 100644 --- a/lib/MySQL_HostGroups_Manager.cpp +++ b/lib/MySQL_HostGroups_Manager.cpp @@ -59,7 +59,7 @@ static void gtid_async_cb(struct ev_loop *loop, struct ev_async *watcher, int re static void gtid_timer_cb (struct ev_loop *loop, struct ev_timer *timer, int revents) { ev_timer_stop(loop, timer); - ev_timer_set(timer, 3, 0); + ev_timer_set(timer, __sync_add_and_fetch(&GloMTH->variables.binlog_reader_connect_retry_msec,0)/1000, 0); if (glovars.shutdown) { ev_break(loop); } @@ -493,7 +493,7 @@ static void * GTID_syncer_run() { MyHGM->gtid_ev_timer = (struct ev_timer *)malloc(sizeof(struct ev_timer)); ev_async_init(MyHGM->gtid_ev_async, gtid_async_cb); ev_async_start(MyHGM->gtid_ev_loop, MyHGM->gtid_ev_async); - ev_timer_init(MyHGM->gtid_ev_timer, gtid_timer_cb, 3, 0); + ev_timer_init(MyHGM->gtid_ev_timer, gtid_timer_cb, __sync_add_and_fetch(&GloMTH->variables.binlog_reader_connect_retry_msec,0)/1000, 0); ev_timer_start(MyHGM->gtid_ev_loop, MyHGM->gtid_ev_timer); //ev_ref(gtid_ev_loop); ev_run(MyHGM->gtid_ev_loop, 0); diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index 01cbdc155..79b07f83b 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -259,6 +259,7 @@ static char * mysql_thread_variables_names[]= { (char *)"autocommit_false_is_transaction", (char *)"verbose_query_error", (char *)"hostgroup_manager_verbose", + (char *)"binlog_reader_connect_retry_msec", (char *)"threshold_query_length", (char *)"threshold_resultset_size", (char *)"query_digests_max_digest_length", @@ -370,6 +371,7 @@ MySQL_Threads_Handler::MySQL_Threads_Handler() { variables.throttle_connections_per_sec_to_hostgroup=1000000; variables.max_transaction_time=4*3600*1000; variables.hostgroup_manager_verbose=1; + variables.binlog_reader_connect_retry_msec=3000; variables.threshold_query_length=512*1024; variables.threshold_resultset_size=4*1024*1024; variables.query_digests_max_digest_length=2*1024; @@ -631,6 +633,7 @@ int MySQL_Threads_Handler::get_variable_int(char *name) { if (!strcasecmp(name,"throttle_connections_per_sec_to_hostgroup")) return (int)variables.throttle_connections_per_sec_to_hostgroup; if (!strcasecmp(name,"max_transaction_time")) return (int)variables.max_transaction_time; if (!strcasecmp(name,"hostgroup_manager_verbose")) return (int)variables.hostgroup_manager_verbose; + if (!strcasecmp(name,"binlog_reader_connect_retry_msec")) return (int)variables.binlog_reader_connect_retry_msec; if (!strcasecmp(name,"threshold_query_length")) return (int)variables.threshold_query_length; if (!strcasecmp(name,"threshold_resultset_size")) return (int)variables.threshold_resultset_size; if (!strcasecmp(name,"query_digests_max_digest_length")) return (int)variables.query_digests_max_digest_length; @@ -902,6 +905,10 @@ char * MySQL_Threads_Handler::get_variable(char *name) { // this is the public f sprintf(intbuf,"%d",variables.hostgroup_manager_verbose); return strdup(intbuf); } + if (!strcasecmp(name,"binlog_reader_connect_retry_msec")) { + sprintf(intbuf,"%d",variables.binlog_reader_connect_retry_msec); + return strdup(intbuf); + } if (!strcasecmp(name,"threshold_query_length")) { sprintf(intbuf,"%d",variables.threshold_query_length); return strdup(intbuf); @@ -1331,6 +1338,15 @@ bool MySQL_Threads_Handler::set_variable(char *name, char *value) { // this is t return false; } } + if (!strcasecmp(name,"binlog_reader_connect_retry_msec")) { + int intv=atoi(value); + if (intv >= 200 && intv <= 120000) { + __sync_lock_test_and_set(&variables.binlog_reader_connect_retry_msec,intv); + return true; + } else { + return false; + } + } if (!strcasecmp(name,"threshold_query_length")) { int intv=atoi(value); if (intv >= 1024 && intv <= 1*1024*1024*1024) {