From b97976c4eeb97cd4e60f32bddf53a30350915ca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Tue, 5 Mar 2019 11:20:34 +0200 Subject: [PATCH] MXS-2323: Close stale connections Cleaning up and closing stale connections to servers in maintenance mode helps administrators see when a server is no longer in use. --- .../routing/readwritesplit/rwsplitsession.cc | 20 +++++++++++++++++++ .../routing/readwritesplit/rwsplitsession.hh | 1 + 2 files changed, 21 insertions(+) diff --git a/server/modules/routing/readwritesplit/rwsplitsession.cc b/server/modules/routing/readwritesplit/rwsplitsession.cc index 68e7b810a..76d53d293 100644 --- a/server/modules/routing/readwritesplit/rwsplitsession.cc +++ b/server/modules/routing/readwritesplit/rwsplitsession.cc @@ -563,6 +563,17 @@ static bool server_is_shutting_down(GWBUF* writebuf) return err == ER_SERVER_SHUTDOWN || err == ER_NORMAL_SHUTDOWN || err == ER_SHUTDOWN_COMPLETE; } +void RWSplitSession::close_stale_connections() +{ + for (auto& backend : m_backends) + { + if (backend->in_use() && !backend->can_connect()) + { + backend->close(); + } + } +} + void RWSplitSession::clientReply(GWBUF* writebuf, DCB* backend_dcb) { DCB* client_dcb = backend_dcb->session->client_dcb; @@ -721,6 +732,15 @@ void RWSplitSession::clientReply(GWBUF* writebuf, DCB* backend_dcb) m_can_replay_trx = true; } + if (m_expected_responses == 0) + { + /** + * Close stale connections to servers in maintenance. Done here to avoid closing the connections + * before all responses have been received. + */ + close_stale_connections(); + } + if (backend->in_use() && backend->has_session_commands()) { // Backend is still in use and has more session commands to execute diff --git a/server/modules/routing/readwritesplit/rwsplitsession.hh b/server/modules/routing/readwritesplit/rwsplitsession.hh index 242fee32f..8472b9deb 100644 --- a/server/modules/routing/readwritesplit/rwsplitsession.hh +++ b/server/modules/routing/readwritesplit/rwsplitsession.hh @@ -187,6 +187,7 @@ private: void continue_large_session_write(GWBUF* querybuf, uint32_t type); bool route_single_stmt(GWBUF* querybuf); bool route_stored_query(); + void close_stale_connections(); mxs::SRWBackend get_hinted_backend(char* name); mxs::SRWBackend get_slave_backend(int max_rlag);