MXS-2702: Update m_current_master on session command

When lazy_connect is enabled and the first query is `SET autocommit=0`, a
master connection can be created. If it is, then the m_current_master
pointer must also be updated.

Also fixed the case where a failure to connect to one slave would cause
the connection attempts to stop too early.
This commit is contained in:
Markus Mäkelä
2019-09-26 22:59:31 +03:00
parent f6b2a7f3d5
commit a444484310

View File

@ -105,21 +105,32 @@ bool RWSplitSession::prepare_target(RWBackend* target, route_target_t route_targ
bool RWSplitSession::create_one_connection()
{
mxb_assert(m_config.lazy_connect);
// Try to first find a master
for (auto backend : m_raw_backends)
{
if (backend->can_connect() && backend->is_master())
{
return prepare_target(backend, TARGET_MASTER);
if (prepare_target(backend, TARGET_MASTER))
{
if (!m_current_master)
{
MXS_INFO("Chose '%s' as master due to session write", backend->name());
m_current_master = backend;
}
return true;
}
}
}
// If no master was found, find a slave
for (auto backend : m_raw_backends)
{
if (backend->can_connect() && backend->is_slave())
if (backend->can_connect() && backend->is_slave() && prepare_target(backend, TARGET_SLAVE))
{
return prepare_target(backend, TARGET_SLAVE);
return true;
}
}