# HintRouter

HintRouter was introduced in 2.2 and is still beta.

### Overview

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.

### Configuration

The HintRouter is a rather simple router and only accepts a few configuration\
settings.

```
default_action=<master|slave|named|all>
```

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:

| Value  | Description                                                                |
| ------ | -------------------------------------------------------------------------- |
| master | Route to the primary server.                                               |
| slave  | Route to any single replica server.                                        |
| named  | Route to a named server. The name is given in the default\_server-setting. |
| all    | 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.

```
default_server=<server-name>
```

Defines the default backend name if `default_action=named`. `<server-name>` must\
be a valid backend name.

```
max_slaves=<limit>
```

`<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\
an error.

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.

### Examples

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
```

<sub>*This page is licensed: CC BY-SA / Gnu FDL*</sub>

{% @marketo/form formId="4316" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mariadb.com/docs/maxscale/maxscale-archive/archive/mariadb-maxscale-23-02/mariadb-maxscale-23-02-routers/mariadb-maxscale-2302-hintrouter.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
