MXS-2350: Connect on session command with lazy_connect

If a session command is executed when lazy_connect is enabled and no
connections have been created, a connection must be made. This makes sure
that the session isn't closed and that the client receives a response.
This commit is contained in:
Markus Mäkelä
2019-03-04 12:43:43 +02:00
parent 24ea222ed6
commit bfc874dea1
2 changed files with 34 additions and 0 deletions

View File

@ -91,6 +91,30 @@ bool RWSplitSession::prepare_target(RWBackend* target, route_target_t route_targ
return rval;
}
bool RWSplitSession::create_one_connection()
{
// 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 no master was found, find a slave
for (auto backend : m_raw_backends)
{
if (backend->can_connect() && backend->is_slave())
{
return prepare_target(backend, TARGET_SLAVE);
}
}
// No servers are available
return false;
}
void RWSplitSession::retry_query(GWBUF* querybuf, int delay)
{
mxb_assert(querybuf);
@ -560,6 +584,15 @@ bool RWSplitSession::route_session_write(GWBUF* querybuf, uint8_t command, uint3
m_sescmd_list.push_back(sescmd);
}
if (m_config.lazy_connect && !attempted_write && nsucc == 0)
{
// If no connections are open, create one and execute the session command on it
if (create_one_connection())
{
nsucc = 1;
}
}
if (nsucc)
{
m_sent_sescmd = id;

View File

@ -163,6 +163,7 @@ private:
bool handle_got_target(GWBUF* querybuf, mxs::RWBackend* target, bool store);
void handle_connection_keepalive(mxs::RWBackend* target);
bool prepare_target(mxs::RWBackend* target, route_target_t route_target);
bool create_one_connection();
void retry_query(GWBUF* querybuf, int delay = 1);
bool should_replace_master(mxs::RWBackend* target);