From 8cf22dbb56066cbb96b075180d2c9a5394ba0e49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Mon, 25 Jun 2018 02:01:25 +0300 Subject: [PATCH] MXS-1549: Prevent optimistic transaction with no slaves If the router session does not have an already open slave connection, optimistic transactions are not attempted. --- .../readwritesplit/rwsplit_route_stmt.cc | 24 +++++++++++++++---- .../routing/readwritesplit/rwsplitsession.hh | 3 +++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc b/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc index 6f6f24c08..4c586750e 100644 --- a/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc +++ b/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc @@ -151,13 +151,27 @@ void replace_binary_ps_id(GWBUF* buffer, uint32_t id) } +bool RWSplitSession::have_connected_slaves() const +{ + for (const auto& b: m_backends) + { + if (b->is_slave() && b->in_use()) + { + return true; + } + } + + return false; +} + bool RWSplitSession::should_try_trx_on_slave(route_target_t route_target) const { - return m_config.optimistic_trx && // Optimistic transactions are enabled - !is_locked_to_master() && // Not locked to master - !m_is_replay_active && // Not replaying a transaction - m_otrx_state == OTRX_INACTIVE && // Not yet in optimistic mode - TARGET_IS_MASTER(route_target); // The target type is master + return m_config.optimistic_trx && // Optimistic transactions are enabled + !is_locked_to_master() && // Not locked to master + !m_is_replay_active && // Not replaying a transaction + m_otrx_state == OTRX_INACTIVE && // Not yet in optimistic mode + TARGET_IS_MASTER(route_target) && // The target type is master + have_connected_slaves(); // At least one connected slave } bool RWSplitSession::track_optimistic_trx(GWBUF** buffer) diff --git a/server/modules/routing/readwritesplit/rwsplitsession.hh b/server/modules/routing/readwritesplit/rwsplitsession.hh index ea9487465..ac2e1bdb3 100644 --- a/server/modules/routing/readwritesplit/rwsplitsession.hh +++ b/server/modules/routing/readwritesplit/rwsplitsession.hh @@ -204,6 +204,9 @@ private: void handle_trx_replay(); + // Do we have at least one open slave connection + bool have_connected_slaves() const; + /** * Start the replaying of the latest transaction *