Implement first version of HintRouter

The hintrouter is now in principle capable of routing requests
to the master or to some slave (in a round robin fashion) based
upon hints set by some earlier filter.

Note that as the router is completely oblivious of transaction
boundaries, using it with transactions and autocommit being off
will not make anyone happy.

Recognizing transaction boundaries using regexes and then pinning
the server until transaction commit would be needed.
This commit is contained in:
Johan Wikman
2017-03-06 09:55:06 +02:00
parent 9dbabb666a
commit 7165b4306f
8 changed files with 446 additions and 12 deletions

View File

@ -14,11 +14,13 @@
#define MXS_MODULE_NAME "hintrouter"
#include "hintrouter.hh"
#include <maxscale/log_manager.h>
#include "dcb.hh"
HintRouter::HintRouter(SERVICE* pService)
: maxscale::Router<HintRouter, HintRouterSession>(pService)
{
HR_ENTRY();
MXS_NOTICE("Hint router [%s] created.", pService->name);
}
@ -26,22 +28,61 @@ HintRouter::HintRouter(SERVICE* pService)
//static
HintRouter* HintRouter::create(SERVICE* pService, char** pzOptions)
{
HR_ENTRY();
return new HintRouter(pService);
}
HintRouterSession* HintRouter::newSession(MXS_SESSION *pSession)
{
return new HintRouterSession(pSession, this);
HR_ENTRY();
HintRouterSession* pRouterSession = NULL;
HintRouterSession::Backends backends;
for (SERVER_REF* pSref = m_pService->dbref; pSref; pSref = pSref->next)
{
if (SERVER_REF_IS_ACTIVE(pSref))
{
SERVER* pServer = pSref->server;
HR_DEBUG("Connecting to %s.", pServer->name);
DCB* pDcb = dcb_connect(pServer, pSession, pServer->protocol);
if (pDcb)
{
HR_DEBUG("Connected to %p %s.", pDcb, pServer->name);
// TODO: What's done here, should be done by dcb_connect().
atomic_add(&pSref->connections, 1);
pDcb->service = pSession->service;
backends.push_back(Dcb(pDcb));
}
else
{
HR_DEBUG("Failed to connect to %s.", pServer->name);
}
}
}
if (backends.size() != 0)
{
pRouterSession = new HintRouterSession(pSession, this, backends);
}
return pRouterSession;
}
void HintRouter::diagnostics(DCB* pOut)
{
HR_ENTRY();
}
uint64_t HintRouter::getCapabilities()
{
return 0;
HR_ENTRY();
return RCAP_TYPE_STMT_OUTPUT;
}