From fd0c156655c6c2f3aaa61bf4d74c84c96d2664b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Thu, 19 Sep 2019 13:18:06 +0300 Subject: [PATCH] MXS-2564: Reconnect only when necessary By doing the reconnection only when a new query arrives, we prevent the excessive reconnecting that is done when a server's actual and monitored states are in conflict. --- .../routing/readwritesplit/rwsplitsession.cc | 35 ++++--------------- .../routing/readwritesplit/rwsplitsession.hh | 8 +++++ 2 files changed, 14 insertions(+), 29 deletions(-) diff --git a/server/modules/routing/readwritesplit/rwsplitsession.cc b/server/modules/routing/readwritesplit/rwsplitsession.cc index aad2e8a20..0cc70e97d 100644 --- a/server/modules/routing/readwritesplit/rwsplitsession.cc +++ b/server/modules/routing/readwritesplit/rwsplitsession.cc @@ -1175,39 +1175,16 @@ bool RWSplitSession::handle_error_new_connection(DCB* backend_dcb, GWBUF* errmsg route_stored_query(); } - bool succp = false; - /** - * Try to get replacement slave or at least the minimum - * number of slave connections for router session. - */ - if (m_recv_sescmd > 0 && m_config.disable_sescmd_history) - { - for (const auto& a : m_backends) - { - if (a->in_use()) - { - succp = true; - break; - } - } + bool ok = can_recover_servers() || have_open_connections(); - if (!succp) - { - MXS_ERROR("Unable to continue session as all connections have failed, " - "last server to fail was '%s'.", backend->name()); - } - } - else + if (!ok) { - succp = m_router->select_connect_backend_servers(ses, - m_backends, - m_current_master, - &m_sescmd_list, - &m_expected_responses, - connection_type::SLAVE); + MXS_ERROR("Unable to continue session as all connections have failed and " + "new connections cannot be created. Last server to fail was '%s'.", + backend->name()); } - return succp; + return ok; } /** diff --git a/server/modules/routing/readwritesplit/rwsplitsession.hh b/server/modules/routing/readwritesplit/rwsplitsession.hh index 9da56dcf2..ded4b20b5 100644 --- a/server/modules/routing/readwritesplit/rwsplitsession.hh +++ b/server/modules/routing/readwritesplit/rwsplitsession.hh @@ -293,6 +293,14 @@ private: return !m_config.disable_sescmd_history || m_recv_sescmd == 0; } + inline bool have_open_connections() const + { + return std::any_of( + m_backends.begin(), m_backends.end(), [](const mxs::SRWBackend& b) { + return b->in_use(); + }); + } + inline bool is_large_query(GWBUF* buf) { uint32_t buflen = gwbuf_length(buf);