From 42c37585f4f5bfbc06c7cc6eb44d80013027f468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Thu, 27 Jun 2019 00:45:54 +0300 Subject: [PATCH] Throttle query retry attempts It was possible that a one-second outage that caused immediate rejection of network connections would cause all of the query retry attempts to fail within a very short period of time. By preventing rapid reconnections, query_retries is more effective as an error filtering mechanism. --- server/core/mysql_utils.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/server/core/mysql_utils.cc b/server/core/mysql_utils.cc index c82b8d8fd..34430ec7d 100644 --- a/server/core/mysql_utils.cc +++ b/server/core/mysql_utils.cc @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include #include @@ -251,6 +253,14 @@ int mxs_mysql_query_ex(MYSQL* conn, const char* query, int query_retries, time_t && mxs_mysql_is_net_error(mysql_errno(conn)) && time(NULL) - start < query_retry_timeout; n++) { + if (n > 0) + { + // The first reconnection didn't work, wait for one second before attempting again. This + // should reduce the likelihood of transient problems causing state changes due to too many + // reconnection attemps in a short period of time. + std::this_thread::sleep_for(std::chrono::seconds(1)); + } + rc = mysql_query(conn, query); }