MXS-2273 A master is a master even if it is not connectible
When looking for a master, if it does exist it should be found even if it is not connectible. The fact that it is not connectible should be dealt with when a connection is created.
This commit is contained in:
@ -86,7 +86,7 @@ SERVER_REF* RCR::get_root_master()
|
|||||||
SERVER_REF* master_host = nullptr;
|
SERVER_REF* master_host = nullptr;
|
||||||
for (SERVER_REF* ref = m_pService->dbref; ref; ref = ref->next)
|
for (SERVER_REF* ref = m_pService->dbref; ref; ref = ref->next)
|
||||||
{
|
{
|
||||||
if (server_ref_is_active(ref) && ref->server->is_master() && ref->server->is_connectable())
|
if (server_ref_is_active(ref) && ref->server->is_master())
|
||||||
{
|
{
|
||||||
// No master found yet or this one has better weight.
|
// No master found yet or this one has better weight.
|
||||||
if (!master_host || ref->server_weight > master_host->server_weight)
|
if (!master_host || ref->server_weight > master_host->server_weight)
|
||||||
@ -211,6 +211,8 @@ RCRSession* RCR::newSession(MXS_SESSION* session)
|
|||||||
*/
|
*/
|
||||||
SERVER_REF* master_host = get_root_master();
|
SERVER_REF* master_host = get_root_master();
|
||||||
|
|
||||||
|
bool connectable_master = master_host ? master_host->server->is_connectable() : false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find a backend server to connect to. This is the extent of the
|
* Find a backend server to connect to. This is the extent of the
|
||||||
* load balancing algorithm we need to implement for this simple
|
* load balancing algorithm we need to implement for this simple
|
||||||
@ -242,7 +244,7 @@ RCRSession* RCR::newSession(MXS_SESSION* session)
|
|||||||
/* Check server status bits against bitvalue from router_options */
|
/* Check server status bits against bitvalue from router_options */
|
||||||
if (ref && (ref->server->status & bitmask & bitvalue))
|
if (ref && (ref->server->status & bitmask & bitvalue))
|
||||||
{
|
{
|
||||||
if (master_host)
|
if (master_host && connectable_master)
|
||||||
{
|
{
|
||||||
if (ref == master_host
|
if (ref == master_host
|
||||||
&& (bitvalue & (SERVER_SLAVE | SERVER_MASTER)) == SERVER_SLAVE)
|
&& (bitvalue & (SERVER_SLAVE | SERVER_MASTER)) == SERVER_SLAVE)
|
||||||
@ -299,7 +301,7 @@ RCRSession* RCR::newSession(MXS_SESSION* session)
|
|||||||
*/
|
*/
|
||||||
if (!candidate)
|
if (!candidate)
|
||||||
{
|
{
|
||||||
if (master_host)
|
if (master_host && connectable_master)
|
||||||
{
|
{
|
||||||
candidate = master_host;
|
candidate = master_host;
|
||||||
// Even if we had 'router_options=slave' in the configuration file, we
|
// Even if we had 'router_options=slave' in the configuration file, we
|
||||||
@ -315,12 +317,25 @@ RCRSession* RCR::newSession(MXS_SESSION* session)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
if (!master_host)
|
||||||
{
|
{
|
||||||
MXS_ERROR("Failed to create new routing session. Couldn't find eligible"
|
MXS_ERROR("Failed to create new routing session. Couldn't find eligible"
|
||||||
" candidate server. Freeing allocated resources.");
|
" candidate server. Freeing allocated resources.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mxb_assert(!connectable_master);
|
||||||
|
MXS_ERROR("The only possible candidate server (%s) is being drained "
|
||||||
|
"and thus cannot be used.", master_host->server->address);
|
||||||
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mxb_assert(candidate->server->is_connectable());
|
||||||
|
}
|
||||||
|
|
||||||
/** Open the backend connection */
|
/** Open the backend connection */
|
||||||
DCB* backend_dcb = dcb_connect(candidate->server, session, candidate->server->protocol().c_str());
|
DCB* backend_dcb = dcb_connect(candidate->server, session, candidate->server->protocol().c_str());
|
||||||
|
Reference in New Issue
Block a user