MXS-2556 Use configured master
This commit is contained in:
@ -122,10 +122,9 @@ SmartRouterSession* SmartRouterSession::create(SmartRouter* pRouter, MXS_SESSION
|
|||||||
Clusters clusters;
|
Clusters clusters;
|
||||||
|
|
||||||
SERVER* pMaster = pRouter->config().master();
|
SERVER* pMaster = pRouter->config().master();
|
||||||
// TODO: Use pMaster below.
|
|
||||||
|
|
||||||
bool is_master = true; // TODO this will be read from config
|
int master_pos = -1;
|
||||||
int master_pos = 0; // and this will be initialized to the position of the master
|
int i = 0;
|
||||||
|
|
||||||
for (SERVER_REF* ref = pRouter->service()->dbref; ref; ref = ref->next)
|
for (SERVER_REF* ref = pRouter->service()->dbref; ref; ref = ref->next)
|
||||||
{
|
{
|
||||||
@ -139,17 +138,35 @@ SmartRouterSession* SmartRouterSession::create(SmartRouter* pRouter, MXS_SESSION
|
|||||||
DCB* dcb = dcb_connect(ref->server, pSession, ref->server->protocol().c_str());
|
DCB* dcb = dcb_connect(ref->server, pSession, ref->server->protocol().c_str());
|
||||||
if (dcb)
|
if (dcb)
|
||||||
{
|
{
|
||||||
|
bool is_master = (ref->server == pMaster);
|
||||||
|
|
||||||
clusters.push_back({ref, dcb, is_master});
|
clusters.push_back({ref, dcb, is_master});
|
||||||
is_master = false; // TODO, will come from config, there must be exactly one!
|
|
||||||
|
if (is_master)
|
||||||
|
{
|
||||||
|
master_pos = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (master_pos)
|
SmartRouterSession* pSess = nullptr;
|
||||||
|
|
||||||
|
if (master_pos != -1)
|
||||||
|
{
|
||||||
|
if (master_pos > 0)
|
||||||
{ // put the master first. There must be exactly one master cluster.
|
{ // put the master first. There must be exactly one master cluster.
|
||||||
std::swap(clusters[0], clusters[master_pos]);
|
std::swap(clusters[0], clusters[master_pos]);
|
||||||
}
|
}
|
||||||
|
|
||||||
SmartRouterSession* pSess = new SmartRouterSession(pRouter, pSession, std::move(clusters));
|
pSess = new SmartRouterSession(pRouter, pSession, std::move(clusters));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MXS_ERROR("No master found for %s, smartrouter session cannot be created.",
|
||||||
|
pRouter->config().name().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
return pSess;
|
return pSess;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user