MXS-2313: Use servers of same rank in readwritesplit
When a readwritesplit session has a connection to a master server, servers of the same rank as the master are used. If no master connection is available, the server with the highest rank among all connected servers is used. If there are no open connections, the server with the best rank is chosen and a connection to it is made. Connections with different rank values than what is the current rank value of the session will be discarded. This reduces the use of server with different ranks when the master server of a session fails. Without the active pruning of connections, slave connections to primary clusters without masters would remain in use even after the primary master fails. This guarantees full switchover to a secondary cluster if a master change occurs.
This commit is contained in:
@ -563,11 +563,23 @@ static bool server_is_shutting_down(GWBUF* writebuf)
|
||||
|
||||
void RWSplitSession::close_stale_connections()
|
||||
{
|
||||
auto current_rank = get_current_rank();
|
||||
|
||||
for (auto& backend : m_backends)
|
||||
{
|
||||
if (backend->in_use() && !backend->can_connect())
|
||||
if (backend->in_use())
|
||||
{
|
||||
backend->close();
|
||||
if (!backend->can_connect())
|
||||
{
|
||||
MXS_INFO("Discarding connection to '%s': Server is in maintenance", backend->name());
|
||||
backend->close();
|
||||
}
|
||||
else if (backend->server()->rank() != current_rank)
|
||||
{
|
||||
MXS_INFO("Discarding connection to '%s': Server has rank %ld and current rank is %ld",
|
||||
backend->name(), backend->server()->rank(), current_rank);
|
||||
backend->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user