MXS-2520: Do master replacement if it's possible

This allows a new master to be chosen regardless of the target server
type.
This commit is contained in:
Markus Mäkelä
2019-07-26 20:37:53 +03:00
parent 918a2964d5
commit dda02b45ee

View File

@ -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() : "<no previous master>",
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() : "<no previous master>",
target->name());
replace_master(target);
}
if (target && target == m_current_master)
{
mxb::atomic::add(&m_router->stats().n_master, 1, mxb::atomic::RELAXED);