From dda02b45ee8e40ab37e0a7068668be5a0da9899f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Fri, 26 Jul 2019 20:37:53 +0300 Subject: [PATCH] MXS-2520: Do master replacement if it's possible This allows a new master to be chosen regardless of the target server type. --- .../readwritesplit/rwsplit_route_stmt.cc | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc b/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc index 1ec1d8076..4ac85bed1 100644 --- a/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc +++ b/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc @@ -210,6 +210,17 @@ bool RWSplitSession::route_single_stmt(GWBUF* querybuf) { update_trx_statistics(); + auto next_master = get_target_backend(BE_MASTER, NULL, MXS_RLAG_UNDEFINED); + + if (should_replace_master(next_master)) + { + MXS_INFO("Replacing old master '%s' with new master '%s'", + m_current_master ? + m_current_master->name() : "", + next_master->name()); + replace_master(next_master); + } + if (m_qc.is_trx_starting() // A transaction is starting && !session_trx_is_read_only(m_client->session) // Not explicitly read-only && should_try_trx_on_slave(route_target)) // Qualifies for speculative routing @@ -1052,15 +1063,6 @@ bool RWSplitSession::handle_master_is_target(SRWBackend* dest) SRWBackend target = get_target_backend(BE_MASTER, NULL, MXS_RLAG_UNDEFINED); bool succp = true; - if (should_replace_master(target)) - { - MXS_INFO("Replacing old master '%s' with new master '%s'", - m_current_master ? - m_current_master->name() : "", - target->name()); - replace_master(target); - } - if (target && target == m_current_master) { mxb::atomic::add(&m_router->stats().n_master, 1, mxb::atomic::RELAXED);