HintRouter was introduced in 2.2 and is still beta.
The HintRouter module is a simple router intended to operate in conjunction with the NamedServerFilter. The router looks at the hints embedded in a packet buffer and attempts to route the packet according to the hint. The user can also set a default action to be taken when a query has no hints or when the hints could not be applied.
If a packet has multiple hints attached, the router will read them in order and attempt routing. Any successful routing ends the process and any further hints are ignored for the packet.
The HintRouter is a rather simple router and only accepts a few configuration settings.
This setting defines what happens when a query has no routing hint or applying the routing hint(s) fails. If also the default action fails, the routing will end in error and the session closes. The different values are:
|Route to the primary server.
|Route to any single replica server.
|Route to a named server. The name is given in the
|Default value. Route to all connected servers.
Note that setting default action to anything other than
all means that session
variable write commands are by default not routed to all backends.
Defines the default backend name if
be a valid backend name.
<limit> should be an integer, -1 by default. Defines how many backend replica
servers a session should attempt to connect to. Having less replicas defined in
the services and/or less successful connections during session creation is not
an error. The router will attempt to distribute replicas evenly between sessions
by assigning them in a round robin fashion. The session will always try to
connect to a primary regardless of this setting, although not finding one is not
Negative values activate default mode, in which case this value is set to the number of backends in the service - 1, so that the sessions are connected to all replicas.
If the hints or the
default_action point to a named server, this setting is
probably best left to default to ensure that the specific server is connected to
at session creation. The router will not attempt to connect to additional
servers after session creation.
A minimal configuration doesn't require any parameters as all settings have reasonable defaults.
[Routing-Service] type=service router=hintrouter servers=replica1,replica2,replica3
If packets should be routed to the primary server by default and only a few connections are required, the configuration might be as follows.
[Routing-Service] type=service router=hintrouter servers=MyPrimary, replica1,replica2,replica3,replica4,replica5,replica6,replica7 default_action=master max_slaves=2