HintRouter: Support various hint types, round-robin rotate slaves

Supports hint types:
-master
-slave
-named server
-all

A default action, which is performed when no hint exists or on error,
can be set. The different actions are analogous to the hint types.

A maximum connection number for slaves can be set. If more slaves are
configured for the service, the filter will rotate slaves for new sessions.

Within a session with multiple slaves, the "route_to_slave"-hint will
also rotate among the slave backends.
This commit is contained in:
Esa Korhonen
2017-03-27 10:07:51 +03:00
parent ddcd1f960c
commit 90c249a8b2
5 changed files with 377 additions and 93 deletions

View File

@ -13,26 +13,42 @@
*/
#include "hintrouterdefs.hh"
#include <deque>
#include <tr1/unordered_map>
#include <vector>
#include <string>
#include <maxscale/router.hh>
#include "dcb.hh"
using std::string;
class HintRouter;
class HintRouterSession : public maxscale::RouterSession
{
public:
typedef std::deque<Dcb> Backends;
typedef std::tr1::unordered_map<string, Dcb> BackendMap; // All backends, indexed by name
typedef std::vector<Dcb> BackendArray;
typedef std::vector<SERVER_REF*> RefArray;
typedef BackendMap::value_type MapElement;
typedef BackendArray::size_type size_type;
HintRouterSession(MXS_SESSION* pSession,
HintRouter* pRouter,
const Backends& backends);
const BackendMap& backends
);
~HintRouterSession();
void close();
int32_t routeQuery(GWBUF* pPacket);
bool route_by_hint(GWBUF* pPacket, HINT* current_hint, bool ignore_errors);
bool route_to_slave(GWBUF* pPacket);
void clientReply(GWBUF* pPacket, DCB* pBackend);
@ -41,13 +57,17 @@ public:
mxs_error_action_t action,
bool* pSuccess);
private:
HintRouterSession(const HintRouterSession&);
HintRouterSession& operator = (const HintRouterSession&);
void update_connections();
private:
HintRouter* m_pRouter;
Backends m_backends;
size_t m_surplus_replies;
HintRouterSession(const HintRouterSession&); // denied
HintRouterSession& operator = (const HintRouterSession&); // denied
private:
HintRouter* m_router;
BackendMap m_backends; // all connections
Dcb m_master; // connection to master
BackendArray m_slaves; // connections to slaves
size_type m_n_routed_to_slave; // packets routed to a single slave, used for rr
size_t m_surplus_replies; // how many replies should be ignored
};