MXS-2566: Use connection counts more often

The connection counts are now always used to pick the best servers where
the initial connections are created. This covers both master and slaves
selection. Reconnections done while routing queries still pick the "best"
server according to the slave selection criteria. This allows better
servers to be taken into use when `lazy_connect` is enabled.
This commit is contained in:
Markus Mäkelä 2019-06-18 16:14:59 +03:00
parent ef3136c5c9
commit 2bd614ce8e
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19
3 changed files with 10 additions and 10 deletions

View File

@ -127,7 +127,7 @@ static const char gtid_wait_stmt[] =
/** Function that returns a "score" for a server to enable comparison.
* Smaller numbers are better.
*/
using BackendSelectFunction = std::function<mxs::PRWBackends::iterator (mxs::PRWBackends& sBackends)>;
using BackendSelectFunction = mxs::PRWBackends::iterator (*)(mxs::PRWBackends& sBackends);
BackendSelectFunction get_backend_select_function(select_criteria_t);
using std::chrono::seconds;
@ -409,8 +409,7 @@ inline bool can_continue_using_master(const mxs::RWBackend* current_master)
&& session_trx_is_active(current_master->dcb()->session));
}
mxs::RWBackend* get_root_master(const mxs::PRWBackends& backends, mxs::RWBackend* current_master,
const BackendSelectFunction& func);
mxs::RWBackend* get_root_master(const mxs::PRWBackends& backends, mxs::RWBackend* current_master);
/**
* Get total slave count and connected slave count

View File

@ -637,7 +637,7 @@ RWBackend* RWSplitSession::get_master_backend()
{
RWBackend* rval = nullptr;
/** get root master from available servers */
RWBackend* master = get_root_master(m_raw_backends, m_current_master, m_config.backend_select_fct);
RWBackend* master = get_root_master(m_raw_backends, m_current_master);
if (master)
{

View File

@ -396,8 +396,7 @@ static void log_server_connections(select_criteria_t criteria, const PRWBackends
}
}
RWBackend* get_root_master(const PRWBackends& backends, RWBackend* current_master,
const BackendSelectFunction& func)
RWBackend* get_root_master(const PRWBackends& backends, RWBackend* current_master)
{
if (current_master && current_master->in_use() && can_continue_using_master(current_master))
{
@ -427,7 +426,7 @@ RWBackend* get_root_master(const PRWBackends& backends, RWBackend* current_maste
}
}
auto it = func(candidates);
auto it = backend_cmp_global_conn(candidates);
return it != candidates.end() ? *it : nullptr;
}
@ -467,7 +466,7 @@ bool RWSplitSession::open_connections()
return true; // No need to create connections
}
RWBackend* master = get_root_master(m_raw_backends, m_current_master, m_config.backend_select_fct);
RWBackend* master = get_root_master(m_raw_backends, m_current_master);
if ((!master || !master->can_connect()) && m_config.master_failure_mode == RW_FAIL_INSTANTLY)
{
@ -514,9 +513,11 @@ bool RWSplitSession::open_connections()
}
}
for (auto ite = m_config.backend_select_fct(candidates);
auto func = backend_cmp_global_conn;
for (auto ite = func(candidates);
n_slaves < max_nslaves && !candidates.empty() && ite != candidates.end();
ite = m_config.backend_select_fct(candidates))
ite = func(candidates))
{
if (prepare_connection(*ite))
{