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);