MXS-2564: Reconnect only when necessary

By doing the reconnection only when a new query arrives, we prevent the
excessive reconnecting that is done when a server's actual and monitored
states are in conflict.
This commit is contained in:
Markus Mäkelä 2019-09-19 13:18:06 +03:00
parent 40d05e8278
commit fd0c156655
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19
2 changed files with 14 additions and 29 deletions

View File

@ -1175,39 +1175,16 @@ bool RWSplitSession::handle_error_new_connection(DCB* backend_dcb, GWBUF* errmsg
route_stored_query();
}
bool succp = false;
/**
* Try to get replacement slave or at least the minimum
* number of slave connections for router session.
*/
if (m_recv_sescmd > 0 && m_config.disable_sescmd_history)
{
for (const auto& a : m_backends)
{
if (a->in_use())
{
succp = true;
break;
}
}
bool ok = can_recover_servers() || have_open_connections();
if (!succp)
{
MXS_ERROR("Unable to continue session as all connections have failed, "
"last server to fail was '%s'.", backend->name());
}
}
else
if (!ok)
{
succp = m_router->select_connect_backend_servers(ses,
m_backends,
m_current_master,
&m_sescmd_list,
&m_expected_responses,
connection_type::SLAVE);
MXS_ERROR("Unable to continue session as all connections have failed and "
"new connections cannot be created. Last server to fail was '%s'.",
backend->name());
}
return succp;
return ok;
}
/**

View File

@ -293,6 +293,14 @@ private:
return !m_config.disable_sescmd_history || m_recv_sescmd == 0;
}
inline bool have_open_connections() const
{
return std::any_of(
m_backends.begin(), m_backends.end(), [](const mxs::SRWBackend& b) {
return b->in_use();
});
}
inline bool is_large_query(GWBUF* buf)
{
uint32_t buflen = gwbuf_length(buf);