From 547236b7a4c46d7d30bc7119154b5b14e1779be4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Wed, 7 Aug 2019 13:23:11 +0300 Subject: [PATCH] MXS-2609: Store history size in Backend When a connection is created, the size of the history that is about to be replayed is known. Storing this and decrementing it each time a session command is completed tells us when the Backend has finished replaying the session command history. This can then be used to distinguish whether a session command executed on a master should be retried or whether to simply discard the connection. --- include/maxscale/backend.hh | 13 ++++++++++++- server/core/backend.cc | 11 ++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/include/maxscale/backend.hh b/include/maxscale/backend.hh index a71074878..ab8416317 100644 --- a/include/maxscale/backend.hh +++ b/include/maxscale/backend.hh @@ -303,6 +303,16 @@ public: return m_state & FATAL_FAILURE; } + /** + * Is the backend replaying session command history + * + * @return If a list of session commands was provided at connect time, the function returns true as long + * as the backend has not completed those session commands. + */ + inline bool is_replaying_history() const + { + return m_history_size > 0; + } /** * @brief Get the object name of this server @@ -389,7 +399,8 @@ private: maxbase::StopWatch m_session_timer; maxbase::IntervalTimer m_select_timer; - int64_t m_num_selects = 0; + int64_t m_num_selects {0}; + int64_t m_history_size {0}; }; typedef std::shared_ptr SBackend; diff --git a/server/core/backend.cc b/server/core/backend.cc index 201ae5c6d..f837f7957 100644 --- a/server/core/backend.cc +++ b/server/core/backend.cc @@ -54,6 +54,7 @@ void Backend::close(close_type type) m_closed = true; m_closed_at = time(NULL); m_session_commands.clear(); + m_history_size = 0; if (in_use()) { @@ -139,6 +140,12 @@ uint64_t Backend::complete_session_command() { uint64_t rval = m_session_commands.front()->get_position(); m_session_commands.pop_front(); + + if (m_history_size > 0) + { + --m_history_size; + } + return rval; } @@ -192,10 +199,12 @@ bool Backend::connect(MXS_SESSION* session, SessionCommandList* sescmd) m_state = IN_USE; mxb::atomic::add(&m_backend->connections, 1, mxb::atomic::RELAXED); rval = true; + m_history_size = 0; - if (sescmd && sescmd->size()) + if (sescmd && !sescmd->empty()) { append_session_command(*sescmd); + m_history_size = sescmd->size(); if (!execute_session_command()) {