Merge branch '2.3' into develop

This commit is contained in:
Esa Korhonen
2019-01-21 13:51:50 +02:00
5 changed files with 70 additions and 15 deletions

View File

@ -256,6 +256,31 @@ ResponseStat& RWBackend::response_stat()
return m_response_stat;
}
void RWBackend::change_rlag_state(SERVER::RLagState new_state, int max_rlag)
{
mxb_assert(new_state == SERVER::RLagState::BELOW_LIMIT || new_state == SERVER::RLagState::ABOVE_LIMIT);
namespace atom = maxbase::atomic;
auto srv = server();
auto old_state = atom::load(&srv->rlag_state, atom::RELAXED);
if (new_state != old_state)
{
atom::store(&srv->rlag_state, new_state, atom::RELAXED);
// State has just changed, log warning. Don't log catchup if old state was RLAG_NONE.
if (new_state == SERVER::RLagState::ABOVE_LIMIT)
{
MXS_WARNING("Replication lag of '%s' is %is, which is above the configured limit %is. "
"'%s' is excluded from query routing.",
srv->name(), srv->rlag, max_rlag, srv->name());
}
else if (old_state == SERVER::RLagState::ABOVE_LIMIT)
{
MXS_WARNING("Replication lag of '%s' is %is, which is below the configured limit %is. "
"'%s' is returned to query routing.",
srv->name(), srv->rlag, max_rlag, srv->name());
}
}
}
mxs::SRWBackends RWBackend::from_servers(SERVER_REF* servers)
{
SRWBackends backends;

View File

@ -605,14 +605,25 @@ RWBackend* RWSplitSession::get_slave_backend(int max_rlag)
&& counts.second < m_router->max_slave_count();
bool master_or_slave = backend->is_master() || backend->is_slave();
bool is_useable = backend->in_use() || can_take_slave_into_use;
bool not_a_slacker = rpl_lag_is_ok(backend, max_rlag);
bool is_usable = backend->in_use() || can_take_slave_into_use;
bool rlag_ok = rpl_lag_is_ok(backend, max_rlag);
bool server_is_candidate = master_or_slave && is_useable && not_a_slacker;
if (server_is_candidate)
if (master_or_slave && is_usable)
{
candidates.push_back(backend);
if (rlag_ok)
{
candidates.push_back(backend);
if (max_rlag > 0)
{
// Replication lag discrimination is on and the server passed.
backend->change_rlag_state(SERVER::RLagState::BELOW_LIMIT, max_rlag);
}
}
else
{
// The server is otherwise usable except it's lagging too much.
backend->change_rlag_state(SERVER::RLagState::ABOVE_LIMIT, max_rlag);
}
}
}