Chapter 5 Plugins

Table of Contents

5.1 Connection Routing Plugin
5.2 Fabric Cache Plug-in

Introduction to MySQL Router plugins.

Each plugin is loaded and configured from the configuration file, and then started by the Router Harness.

5.1 Connection Routing Plugin

The Connection Routing plugin performs connection-based routing, meaning that it forwards the packets to the server without looking at them. This is a simplistic approach that provides a high throughput.

Note

MySQL Fabric usage is optional, and the example below does not use Fabric.

A simple connection-based routing setup is shown below. These options were documented in the Configuration File Setup chapter.

[DEFAULT]
logging_folder = /var/log/mysql/router
config_folder  = /usr/local/etc/mysqlrouter
plugin_folder  = /usr/local/lib/mysqlrouter
runtime_folder = /usr/local/

[logger]
level = INFO

[routing]
bind_address = 127.0.0.1:7002
destinations = slave1.example.com,slave2.example.com,slave3.example.com
mode = read-only

Here we use connection routing to round-robin MySQL connections to three MySQL servers. The read-only mode causes round-robin behavior, and logs are sent to /var/log/mysql/router/mysqlrouter.log.

5.2 Fabric Cache Plug-in

The Fabric Cache plug-in maintains the connection with the MySQL Fabric instance, and caches the connection information for the servers under Fabric control.

Note

This section describes a plugin for accessing information from a Fabric installation. See the online reference manual for MySQL Fabric for additional information about Fabric installation and configuration.

Fabric Cache Destinations

The Fabric cache destination is a special string used to define the connection to Fabric. It is a uniform resource identifier (URI). The URI is specified with the destinations option for the routing strategy in the configuration file. The following presents an example and explanation of each part. They must appear in the order shown.

destinations = plugin://section_key/target/group_id
  • plugin : This string instructs the router to use a particular plugin. Currently, the only plugin available is the Fabric Cache plugin for Fabric integrated connection routing. Thus, we use the string fabric+cache.

  • section_key : The section key for the Fabric Cache plugin configuration options. For example, [fabric_cache:web]. Thus, your configuration file will contain another section with this key.

  • target : The type of Fabric object we are request. Currently, the only value is group.

  • group_id : The Fabric HA group identifier.

The following shows a complete example of the entries in the configuration file. Notice how the parts match for the

[fabric_cache:web]
address = 192.168.14.29
user = routeruser

[routing:web]
bind_port = 7001
destinations = fabric+cache://web/group/webforum
mode = read-write
      

This URI is used to retrieve the list of MySQL servers through the Fabric Cache plugin, which stores and manages information fetched from MySQL Fabric. When Fabric becomes unavailable, Fabric Cache will keep trying to connect to Fabric will keep retrying regularly to connect to Fabric.

A Fabric Cache section without a key means that the "fabric+cache" URI is used with an empty authority.

Destinations read from different locations are configured using the destinations option. The Routing Plugin determines if a URI or a comma-separated value should be used.

Only one Fabric Cache plug-in can be active. An empty "host" part of the URI means the first Fabric Cache plugin without a key is used. Specifying a host in the URI will result in an error, as demonstrated here:

[fabric_cache]
...
[routing:production_rw]
...
mode = read-write

# Works, no host
destinations = fabric+cache:///hagroup/dev1

# Fails, a host is specified
destinations = fabric+cache://cache_2/hagroup/dev1

With Fabric, allow_primary_reads can not be passed to Fabric in read-write mode, as it only functions with read-only mode.

Additional Fabric Cache examples:

[fabric_cache:fabric1]
address = fabric1.example.com
user = fabric_user

[routing:homepage_rw]
mode = read-write
destinations = fabric+cache://fabric1/group/homepage

[routing:homepage_ro]
mode = read-only
destinations = fabric+cache://fabric1/group/homepage?allow_primary_reads=yes

[routing:homepage_ro]
mode = read-only
destinations = fabric+cache:///group/homepage   # empty authority