This version of MariaDB MaxScale marked a major step in usability. It introduced the MaxGUI for web-based administration and monitoring, and added other feature enhancements.
About MaxScale 23.02
MariaDB MaxScale 23.02 was a landmark release focused on usability. It introduced the MaxGUI, a new web-based interface for easy administration and monitoring of your database cluster. Sources
MaxScale 23.02 Filters
Filters are powerful modules that intercept and process database traffic in MaxScale. Use them to log, transform, block, or reroute queries to add control, security, and monitoring.
MaxScale 23.02 Connectors
Explore connectors for MariaDB MaxScale 23.02. This section details the CDC Connector, a C++ API enabling applications to connect and consume a real-time stream of database change events.
MaxScale 23.02 Getting-Started
This is your starting point for MariaDB MaxScale 23.02. Find guides for installation, learn to use the MaxGUI, and explore tutorials to get your database proxy up and running.
MaxScale 23.02 Authenticators
Secure your MaxScale deployment by configuring authenticators. These modules manage client authentication against backend MariaDB servers, supporting various mechanisms for robust security.
MaxScale 23.02 Reference
Access detailed technical information for MariaDB MaxScale 23.02. This section is your complete reference for configuration settings, command-line tools, hint syntax, and more.
MaxScale 23.02 Monitors
Monitors are essential for high availability. They track backend server status, detect failures, promote replicas, and perform automatic failovers, ensuring service continuity.
MaxScale 23.02 Protocols
Protocol modules interpret client-server communication for MaxScale. This section covers the available modules, including the standard MariaDB protocol, NoSQL, and Change Data Capture (CDC).
MaxScale 23.02 Design-Documents
Explore the internal architecture of MariaDB MaxScale. This section contains the detailed design documents and specifications used by developers for core features and modules.
MaxScale 23.02 Release Notes
Review the official release notes for MariaDB MaxScale 23.02. This section details new features, bug fixes, and all functional changes to ensure a smooth upgrade and deployment process.
The MaxScale 23.02 release notes have moved here.
MaxScale 23.02 Tutorials
Get hands-on experience with MariaDB MaxScale 23.02. These tutorials provide step-by-step instructions for common tasks like setting up read-write splitting, failover, and sharding.
MaxScale 23.02 Routers
Routers are the core of a MaxScale service, intelligently directing database traffic. This section details available routers, from read-write splitting to sharding and routing hints. Sources
MariaDB/MySQL Authenticator
The MariaDBAuth-module implements the client and backend authentication for the
server plugin mysql_native_password. This is the default authentication
plugin used by both MariaDB and MySQL.
Authenticator options
The following settings may be given in the authenticator_options of the
listener.
log_password_mismatch
Type:
Mandatory: No
Dynamic: No
Default: false
The service setting log_auth_warnings must
also be enabled for this setting to have effect. When both settings are enabled,
password hashes are logged if a client gives a wrong password. This feature may
be useful when diagnosing authentication issues. It should only be enabled on a
secure system as the logging of password hashes may be a security risk.
cache_dir
Deprecated and ignored.
inject_service_user
Deprecated and ignored.
This page is licensed: CC BY-SA / Gnu FDL
About MariaDB MaxScale
MariaDB MaxScale is a database proxy that forwards database statements to
one or more database servers.
The forwarding is performed using rules based on the semantic understanding of
the database statements and on the roles of the servers within the backend
cluster of databases.
MariaDB MaxScale is designed to provide, transparently to applications, load
balancing and high availability functionality. MariaDB MaxScale has a scalable
and flexible architecture, with plugin components to support different protocols
and routing approaches.
MariaDB MaxScale makes extensive use of the asynchronous I/O capabilities of the
Linux operating system, combined with a fixed number of worker threads. epoll
is used to provide the event driven framework for the input and output via
sockets.
Many of the services provided by MariaDB MaxScale are implemented as external
shared object modules loaded at runtime. These modules support a fixed
interface, communicating the entry points via a structure consisting of a set of
function pointers. This structure is called the "module object". Additional
modules can be created to work with MariaDB MaxScale.
Hint Syntax
Refer to the documentation for the
MaxScale hint syntax.
This page is licensed: CC BY-SA / Gnu FDL
MaxScale 23.02 REST-API
Manage MaxScale programmatically using the REST API. This interface allows for the dynamic administration and monitoring of resources like servers, services, listeners, and filters.
Commonly used module types are protocol, router and filter. Protocol
modules implement the communication between clients and MariaDB MaxScale, and
between MariaDB MaxScale and backend servers. Routers inspect the queries from
clients and decide the target backend. The decisions are usually based on
routing rules and backend server status. Filters work on data as it passes
through MariaDB MaxScale. Filter are often used for logging queries or modifying
server responses.
A Google Group exists for MariaDB MaxScale. The Group is used to discuss ideas,
issues and communicate with the MariaDB MaxScale community. Send email to maxscale@googlegroups.com or use the forum interface.
Information about installing MariaDB MaxScale, either from a repository or by
building from source code, is included in the MariaDB MaxScale Installation
Guide.
The same guide also provides basic information on running MariaDB MaxScale. More
detailed information about configuring MariaDB MaxScale can be found in the Configuration Guide.
GSSAPI is an authentication protocol that is commonly implemented with Kerberos
on Unix or Active Directory on Windows. This document describes GSSAPI
authentication in MaxScale. The authentication module name in MaxScale is_GSSAPIAuth_.
Preparing the GSSAPI system
For Unix systems, the usual GSSAPI implementation is Kerberos. This is a short
guide on how to set up Kerberos for MaxScale.
The first step is to configure MariaDB to use GSSAPI authentication. The MariaDB
documentation for the
is a good example on how to set it up.
The next step is to copy the keytab file from the server where MariaDB is
installed to the server where MaxScale is located. The keytab file must be
placed in the configured default location which almost always is/etc/krb5.keytab. Alternatively, the keytab filepath can be given as an
authenticator option.
The location of the keytab file can be changed with the KRB5_KTNAME environment
variable:
To take GSSAPI authentication into use, add the following to the listener.
The principal name should be the same as on the MariaDB servers.
Authenticator options
principal_name
Type: string
Mandatory: No
Dynamic: No
Default: mariadb/localhost.localdomain
The service principal name to send to the client. This parameter is a string
parameter which is used by the client to request the token.
This parameter must be the same as the principal name that the backend MariaDB
server uses.
gssapi_keytab_path
Type: path
Mandatory: No
Dynamic: No
Default: Kerberos Default
Keytab file location. This should be an absolute path to the file containing the
keytab. If not defined, Kerberos will search from a default location, usually/etc/krb5.keytab. This path is set to an environment variable. This means that
multiple listeners with GSSAPIAuth will override each other. If using multiple
GSSAPI authenticators, either do not set this option or use the same value for
all listeners.
Implementation details
Read the document for more
details on how authentication modules work in MaxScale.
GSSAPI authentication
The GSSAPI plugin authentication starts when the database server sends the
service principal name in the AuthSwitchRequest packet. The principal name will
usually be in the form service@REALM.COM.
The client searches its local cache for a token for the service or may request
it from the GSSAPI server. If found, the client sends the token to the database
server. The database server verifies the authenticity of the token using its
keytab file and sends the final OK packet to the client.
Building the module
The GSSAPI authenticator modules require the GSSAPI development libraries
(krb5-devel on CentOS 7).
This page is licensed: CC BY-SA / Gnu FDL
Change Data Capture (CDC) users
Change Data Capture (CDC) is a new MaxScale protocol that allows compatible
clients to authenticate and register for Change Data Capture events. The new
protocol must be use in conjunction with AVRO router which currently converts
MariaDB binlog events into AVRO records. Clients connect to CDC listener and
authenticate using credentials provided in a format described in the CDC Protocol documentation.
Note: If no users are found in that file or if it doesn't exist, the only
available user will be the service user:
Protocol level parameters are defined in the listeners. They must be defined
using the scoped parameter syntax where the protocol name is used as the prefix.
For the MariaDB protocol module, the prefix is always mariadbprotocol.
allow_replication
Type:
Mandatory: No
Dynamic: Yes
Default: true
Whether the use of the replication protocol is allowed through this listener. If
disabled with mariadbprotocol.allow_replication=false, all attempts to start
replication will be rejected with a ER_FEATURE_DISABLED error (error number
1289).
This page is licensed: CC BY-SA / Gnu FDL
Upgrading MariaDB MaxScale from 2.0 to 2.1
This document describes particular issues to take into account when upgrading
MariaDB MaxScale from version 2.0 to 2.1.
For more information about MariaDB MaxScale 2.1, please refer to the ChangeLog.
Installation
Before starting the upgrade, we strongly recommend you back up your current
configuration file.
IPv6 Support
MaxScale 2.1.2 added support for IPv6 addresses. The default interface that listeners bind to
was changed from the IPv4 address 0.0.0.0 to the IPv6 address ::. To bind to the old IPv4 address,
add address=0.0.0.0 to the listener definition.
Persisted Configuration Files
Starting with MaxScale 2.1, any changes made with the newly added
will be persisted in a configuration file. These files are located in /var/lib/maxscale/maxscale.cnf.d/.
MaxScale Log Files
The name of the log file was changed from maxscaleN.log to maxscale.log. The
default location for the log file is /var/log/maxscale/maxscale.log.
Rotating the log files will cause MaxScale to reopen the file instead of
renaming them. This makes the MaxScale logging facility logrotate compatible.
ReadWriteSplit
The disable_sescmd_history option is now enabled by default. This means that
slaves will not be recovered mid-session even if a replacement slave is
available. To enable the legacy behavior, add the disable_sescmd_history=true
parameter to the service definition.
Persistent Connections
The MariaDB session state is reset in MaxScale 2.1 for persistent
connections. This means that any modifications to the session state (default
database, user variable etc.) will not survive if the connection is put into the
connection pool. For most users, this is the expected behavior.
User Data Cache
The location of the MariaDB user data cache was moved from/var/cache/maxscale/<Service> to /var/cache/maxscale/<Service>/<Listener>.
Galeramon Monitoring Algorithm
Galeramon will assign the master status only to the node which has a_wsrep_local_index_ value of 0. This will guarantee consistent writes with
multiple MaxScales but it also causes slower changes of the master node.
To enable the legacy behavior, add root_node_as_master=false to the Galera
monitor configuration.
MaxAdmin Editing Mode
The default editing mode was changed from vim to emacs mode. To start
maxadmin in the legacy mode, use the -i option.
This page is licensed: CC BY-SA / Gnu FDL
Configuring the MariaDB Monitor
This document describes how to configure a MariaDB primary-replica cluster monitor
to be used with MaxScale.
The mandatory parameters are the object type, the monitor module to use, the
list of servers to monitor and the username and password to use when connecting
to the servers. The monitor_interval parameter controls for how long
the monitor waits between each monitoring loop.
Monitor User
The monitor user requires the REPLICATION CLIENT privileges to do basic
monitoring. To create a user with the proper grants, execute the following SQL.
Note: If the automatic failover of the MariaDB Monitor will used, the user
will require additional grants. Execute the following SQL to grant them.
This page is licensed: CC BY-SA / Gnu FDL
MaxScale 23.02 Configuring Servers
The first step is to define the servers that make up the cluster. These servers
will be used by the services and are monitored by the monitor.
The address and port parameters tell where the server is located.
Enabling TLS
To enable encryption for the MaxScale-to-MariaDB communication, add ssl=true
to the server section. To enable server certificate verification, addssl_verify_peer_certificate=true.
The ssl and ssl_verify_peer_certificate parameters are similar to the--ssl and --ssl-verify-server-cert options of the mysql command line
client.
For more information about TLS, refer to the .
This page is licensed: CC BY-SA / Gnu FDL
MaxScale 23.02 Monitors
Getting-Started
Connection Routing with MariaDB MaxScale
The goal of this tutorial is to configure a system that has two ports available, one for
write connections and another for read connections. The read connections are load-
balanced across replica servers.
Setting up MariaDB MaxScale
This tutorial is a part of the .
Please read it and follow the instructions. Return here once basic setup is complete.
Configuring the Xpand Monitor
This document describes how to configure the Xpand monitor for use
with a Xpand cluster.
Configuring the Monitor
Contrary to the other monitors of MaxScale, the Xpand monitor will
autonomously figure out the cluster configuration and for each Xpand
node create the corresponding MaxScale server object.
In order to do that, a sufficient number of "bootstrap" server instances
must be specified in the MaxScale configuration file for the Xpand
monitor to start with. One server instance is in principle sufficient, but
if the corresponding node happens to be down when MaxScale starts, the
monitor will not be able to function.
Change Data Capture (CDC) Protocol
CDC is a new protocol that allows compatible clients to authenticate and
register for Change Data Capture events. The new protocol must be use in
conjunction with AVRO router which currently converts MariaDB binlog events into
AVRO records. Change Data Capture protocol is used by clients in order to
interact with stored AVRO file and also allows registered clients to be notified
with the new events coming from MariaDB 10.0/10.1 database.
Creating Users
The users and their hashed passwords are stored in /var/cache/maxscale/<service name>/cdcusers where <service name> is the name of the service.
Cat Router
The cat router is a special router that concatenates result sets.
Note: This module is experimental and must be built from source. The
module is deprecated in MaxScale 23.08 and might be removed in a future
release.
Configuration
The router has no special parameters. To use it, define a service withrouter=cat and add the servers you want to use.
Configuring the Galera Monitor
This document describes how to configure a Galera cluster monitor.
Configuring the Monitor
Define the monitor that monitors the servers.
The mandatory parameters are the object type, the monitor module to use, the
list of servers to monitor and the username and password to use when connecting
to the servers. The monitor_interval parameter controls for how long
the monitor waits between each monitoring loop.
MaxScale 23.02 Encrypting Passwords
Note: The password encryption format changed in MaxScale 2.5. All
encrypted passwords created with MaxScale 2.4 or older need to be
re-encrypted.
There are two options for representing the password, either plain text or
encrypted passwords may be used. In order to use encrypted passwords a set of
keys must be generated that will be used by the encryption and decryption
process. To generate the keys, use the maxkeys command.
By default the key file will be generated in /var/lib/maxscale. If a different
directory is required, it can be given as the first argument to the program. For
more information, see maxkeys --help.
Once the keys have been created the maxpasswd command can be used to generate
the encrypted password.
Read-Write Splitting with MariaDB MaxScale
The goal of this tutorial is to configure a system that appears to the client as a single
database. MariaDB MaxScale will split the statements such that write statements are sent
to the primary server and read statements are balanced across the replica servers.
Setting up MariaDB MaxScale
This tutorial is a part of .
Please read it and follow the instructions. Return here once basic setup is complete.
Upgrading MariaDB MaxScale from 1.4 to 2.0
This document describes particular issues to take into account when upgrading
MariaDB MaxScale from version 1.4 to 2.0.
For more information about MariaDB MaxScale 2.0, please refer to .
Installation
Before starting the upgrade, we strongly recommend you back up your current
configuration file.
MaxScale 23.02 Upgrading
Before upgrading to MariaDB MaxScale 23.02, it is critical to review the changes. This guide outlines new features, altered parameters, and deprecated functionality to ensure a smooth transition.
Configuring services
We want two services and ports to which the client application can connect. One service
routes client connections to the primary server, the other load balances between replica
servers. To achieve this, we need to define two services in the configuration file.
Create the following two sections in your configuration file. The section names are the
names of the services and should be meaningful. For this tutorial, we use the names_Write-Service_ and Read-Service.
router defines the routing module used. Here we use readconnroute for
connection-level routing.
A service needs a list of servers to route queries to. The server names must
match the names of server sections in the configuration file and not the hostnames or
addresses of the servers.
The router_options-parameter tells the readconnroute-module which servers it should
route a client connection to. For the write service we use the master-type and for the
read service the slave-type.
The user and password parameters define the credentials the service uses to populate
user authentication data. These users were created at the start of the MaxScale Tutorial.
To allow network connections to a service, a network ports must be associated with it.
This is done by creating a separate listener section in the configuration file. A service
may have multiple listeners but for this tutorial one per service is enough.
The service parameter tells which service the listener connects to. For the_Write-Listener_ we set it to Write-Service and for the Read-Listener we set
it to Read-Service.
A listener must define the network port to listen on.
The optional address-parameter defines the local address the listener should bind to.
This may be required when the host machine has multiple network interfaces. The
default behavior is to listen on all network interfaces (the IPv6 address ::).
The server configuration is identical with that of any other server, but since
these servers are only used for bootstrapping the Xpand monitor it is
adviceable to use names that clearly will identify them as such.
The actual Xpand monitor configuration looks as follows:
The mandatory parameters are the object type, the monitor module to use, the
list of servers to use for bootstrapping and the username and password to use
when connecting to the servers.
The monitor_interval parameter specifies how frequently the monitor should
ping the health check port of each server and the cluster_monitor_interval
specifies how frequently the monitor should do a complete cluster check, that
is, access the system tables of the Cluster for checking the Cluster
configuration. The default values are 2000 and 60000, that is, 2 seconds
and 1 minute, respectively.
For each detected Xpand node a corresponding MaxScale server object will be
created, whose name is @@<Monitor-Name>:node-<id>, where _Monitor-Name_ is the name of the monitor, in this exampleXpand` and id is the node id
of the Xpand node. So, with a cluster of three nodes, the created servers
might be named like.
Note that as these are created at runtime and may disappear at any moment,
depending on changes happening in and made to the Xpand cluster, they
should never be referred to directly from service configurations. Instead,
services should refer to the monitor, as shown in the following:
Instead of listing the servers of the service explicitly using the servers
parameter as usually is the case, the service refers to the Xpand monitor
using the cluster parameter. This will cause the service to use the Xpand
nodes that the Xpand monitor discovers at runtime.
For additional details, please consult the monitor documentation.
For example, the following service entry will look into /var/cache/maxscale/CDC-Service/ for a file called cdcusers. If that file is found, the users in that file will be used for authentication.
If the cdcusers file cannot be found, the service user (maxuser:maxpwd in the example) can be used to connect through the CDC protocol.
Client connects to MaxScale CDC protocol listener.
Send the authentication message which includes the user and the SHA1 of the password
In the future, optional flags could be implemented.
Registration
Sending UUID
Specify the output format (AVRO or JSON) for data retrieval.
Data Request
Send CDC commands to retrieve router statistics or to query for data events
Protocol Details
Authentication
The authentication starts when the client sends the hexadecimal representation
of the username concatenated with a colon (:) and the SHA1 of the password.
bin2hex(username + ':' + SHA1(password))
For example the user foobar with a password of foopasswd should send the
following hexadecimal string
Server returns OK on success and ERR on failure.
Registration
REGISTER
REGISTER UUID=UUID, TYPE={JSON | AVRO}
Register as a client to the service.
Example:
Server returns OK on success and ERR on failure.
Change Data Capture Commands
REQUEST-DATA
REQUEST-DATA DATABASE.TABLE[.VERSION] [GTID]
This command fetches data from specified table in a database and returns the
output in the requested format (AVRO or JSON). Data records are sent to clients
and if new AVRO versions are found (e.g. mydb.mytable.0000002.avro) the new
schema and data will be sent as well.
The data will be streamed until the client closes the connection.
Clients should continue reading from network in order to automatically gets new events.
Example:
Example Client
MaxScale includes an example CDC client application written in Python 3. You can
find the source code for it in the MaxScale repository.
This page is licensed: CC BY-SA / Gnu FDL
Behavior
The order the servers are defined in is the order in which the servers are
queried. This means that the results are ordered based on the servers
parameter of the service. The result will only be completed once all servers
have executed this.
All commands executed via this router will be executed on all servers. This
means that an INSERT through the cat router will send it to all servers. In
the case of commands that do not return resultsets, the response of the last
server is sent to the client. This means that if one of the earlier servers
returns a different result, the client will not see it.
As the intended use-case of the router is to mainly reduce multiple result sets
into one, it has no mechanisms to prevent writes from being executed on slave
servers (which would cause data corruption or replication failure). Take great
care when performing administrative operations though this router.
If a connection to one of the servers is lost, the client connection will also
be closed.
Example
Here is a simple example service definition that uses the servers from the Configuring Servers tutorial and the
credentials from the MaxScale Tutorial.
This page is licensed: CC BY-SA / Gnu FDL
This monitor module will assign one node within the Galera Cluster as the
current primary and other nodes as replica. Only those nodes that are active
members of the cluster are considered when making the choice of primary node. The
primary node will be the node with the lowest value of wsrep_local_index.
Monitor User
The monitor user does not require any special grants to monitor a Galera
cluster. To create a user for the monitor, execute the following SQL.
CREATE USER 'monitor_user'@'%' IDENTIFIED BY 'my_password';
The username and password, either encrypted or plain text, are stored in the
service section using the user and password parameters.
If a custom location was used for the key file, give it as the first argument tomaxpasswd and pass the password to be encrypted as the second argument. For
more information, see maxkeys --help.
Here is an example configuration that uses an encrypted password.
If the key file is not in the default location, the datadir parameter must be
set to the directory that contains it.
After configuring the servers and the monitor, we create a read-write-splitter service
configuration. Create the following section in your configuration file. The section name
is also the name of the service and should be meaningful. For this tutorial, we use the
name Splitter-Service.
router defines the routing module used. Here we use readwritesplit for
query-level read-write-splitting.
A service needs a list of servers where queries will be routed to. The server names must
match the names of server sections in the configuration file and not the hostnames or
addresses of the servers.
The user and password parameters define the credentials the service uses to populate
user authentication data. These users were created at the start of the MaxScale Tutorial.
To allow network connections to a service, a network ports must be associated with it.
This is done by creating a separate listener section in the configuration file. A service
may have multiple listeners but for this tutorial one is enough.
The service parameter tells which service the listener connects to. For the_Splitter-Listener_ we set it to Splitter-Service.
A listener must define the network port to listen on.
The optional address-parameter defines the local address the listener should bind to.
This may be required when the host machine has multiple network interfaces. The
default behavior is to listen on all network interfaces (the IPv6 address ::).
The default way the communication between MaxAdmin and MariaDB MaxScale is
handled has been changed from an internet socket to a Unix domain socket.
The former alternative is still available but has been deprecated.
If no arguments are given to MaxAdmin, it will attempt to connect to
MariaDB MaxScale using a Unix domain socket. After the upgrade you will
need to provide at least one internet socket related flag - -h, -P,-u or -p - to force MaxAdmin to use the internet socket approach.
E.g.
MySQL Monitor
The MySQL Monitor now assigns the stale state to the master server by default.
In addition to this, the slave servers receive the stale slave state when they
lose the connection to the master. This should not cause changes in behavior
but the output of MaxAdmin will show new states when replication is broken.
The Maxrows filter is capable of restricting the amount of rows that a SELECT,
a prepared statement or stored procedure could return to the client application.
If a resultset from a backend server has more rows than the configured limit
or the resultset size exceeds the configured size,
an empty result will be sent to the client.
Configuration
The Maxrows filter is easy to configure and to add to any existing service.
Filter Parameters
The Maxrows filter has no mandatory parameters.
Optional parameters are:
max_resultset_rows
Type: number
Mandatory: No
Dynamic: Yes
Default: (no limit)
Specifies the maximum number of rows a resultset can have in order to be
returned to the user.
If a resultset is larger than this an empty result will be sent instead.
max_resultset_size
Type:
Mandatory: No
Dynamic: Yes
Default: 64Ki
Specifies the maximum size a resultset can have in order
to be sent to the client. A resultset larger than this, will
not be sent: an empty resultset will be sent instead.
max_resultset_return
Type:
Mandatory: No
Dynamic: Yes
Values: empty
Specifies what the filter sends to the client when the
rows or size limit is hit, possible values:
an empty result set
an error packet with input SQL
an OK packet
Example output with ERR packet:
debug
Type: number
Mandatory: No
Dynamic: Yes
Default: 0
An integer value, using which the level of debug logging made by the Maxrows
filter can be controlled. The value is actually a bitfield with different bits
denoting different logging.
0 (0b00000) No logging is made.
1 (0b00001) A decision to handle data form server is logged.
To log everything, give debug a value of 3.
Example Configuration
Here is an example of filter configuration where the maximum number of returned
rows is 10000 and maximum allowed resultset size is 256KB
With the comment filter it is possible to define comments that are
injected before the actual statements. These comments appear as sql
comments when they are received by the server.
Filter Parameters
The Comment filter requires one mandatory parameter to be defined.
inject
Type: string
Mandatory: Yes
Dynamic: Yes
A parameter that contains the comment injected before the statements.
There is also defined variable $IP that can be used to comment the
IP address of the client in the injected comment.
Variables must be written in all caps.
Examples
Example 1 - Inject IP address of the connected client into statements
as comment.
The following configuration adds the IP address of the client to the comment.
In this example when MaxScale receives statement like:
It would look like
when received by server.
This page is licensed: CC BY-SA / Gnu FDL
Building MariaDB MaxScale from Source Code
MariaDB MaxScale can be built on any system that meets the requirements. The main
requirements are as follows:
CMake version 3.16 or later (Packaging requires CMake 3.25.1 or later)
GCC version 4.9 or later
OpenSSL version 1.0.1 or later
MariaDB MaxScale MaxGUI Guide
Simple Sharding with Two Servers
Sharding is the method of splitting a single database server into separate parts. This tutorial describes a very simple way of sharding. Each schema is located on a different database server and MariaDB MaxScale's schemarouter module is used to combine them into a single database server.
MariaDB MaxScale will appear to the client as a database server with the combination of all the schemas in all the configured servers.
Environment & Solution Space
This document is designed as a simple tutorial on schema-based sharding using MariaDB MaxScale in an environment in which you have two servers. The object of this tutorial is to have a system that, to the client side, acts like a single MariaDB database but actually is sharded between the two servers.
The database users should be configured according to the configuration guide. The MaxScale Tutorial contains easy to follow instructions on how to set up MaxScale.
This tutorial will assume the user is using of the binary distributions available and has installed this in the default location. The process of configuring MariaDB MaxScale will be covered within this document. The installation and configuration of the MariaDB servers will not be covered in-depth.
Preparing MaxScale
Follow the MaxScale Tutorial to install and prepare the required database users for MaxScale. You don't need to create the configuration file for MaxScale as it will be covered in the next section.
Creating Your MariaDB MaxScale Configuration
The first step in the creation of your maxscale.cnf file is to define the global maxscale section. This section configures the number of threads MariaDB MaxScale uses. A good rule of thumb is to use at most as may threads as you have CPUs. MariaDB MaxScale uses few threads for internal operations so one or two threads less than the maximum should be enough.
After this we configure two servers we will use to shard our database. The accounts_east server will hold one schema and the accounts_west will hold another schema. We will use these two servers to create our sharded database.
The next step is to configure the service which the users connect to. This section defines which router to use, which servers to connect to and the credentials to use. The router we use in this tutorial is the schemarouter.
After this we configure a listener for the service. The listener is the actual port the user connects to. We will use the port 4000.
The final step is to configure a monitor which will monitor the state of the servers. The monitor will notify MariaDB MaxScale if the servers are down. We add the two servers to the monitor, define the credentials to use and we set the monitoring cycle interval.
After this we have a fully working configuration and we can move on to starting MariaDB MaxScale.
Starting MariaDB MaxScale
Upon completion of the configuration process MariaDB MaxScale is ready to be started . This may either be done manually by running the maxscale command or via the service interface. The service scripts are located in the /etc/init.d/ folder and are accessible through both the service and systemctl commands.
MariaDB MaxScale is now ready to start accepting client connections and routing them. Queries are routed to the right servers based on the database they target and switching between the shards is seamless since MariaDB MaxScale keeps the session state intact between servers.
If MariaDB MaxScale fails to start, check the error log in /var/log/maxscale to see what sort of errors were detected.
Note: As the sharding solution in MaxScale is relatively simple, cross-database queries between two or more shards are not supported.
Node.js 14 or newer for building MaxCtrl and the GUI (webpack), Node.js 10 or newer for running MaxCtrl
PAM
SASL2 (cyrus-sasl)
SQLite3 version 3.3 or later
Tcl
git
jansson
libatomic
libcurl
libmicrohttpd
libuuid
libxml2
libssh
pcre2
This is the minimum set of requirements that must be met to build the MaxScale
core package. Some modules in MaxScale require optional extra dependencies.
libuuid (binlogrouter)
boost (binlogrouter)
Bison 2.7 or later (dbfwfilter)
Flex 2.5.35 or later (dbfwfilter)
librdkafka (kafkacdc, kafkaimporter and mirror)
memcached (storage_memcached for the cache filter)
hiredis (storage_redis for the cache filter)
Some of these dependencies are not available on all operating systems and are
downloaded automatically during the build step. To skip the building of modules
that need automatic downloading of the dependencies, use -DBUNDLE=N when
configuring CMake.
Quickstart
This installs MaxScale as if it was installed from a package. Install git before running the following commands.
The tests and other parts of the build can be controlled via CMake arguments.
Here is a small table with the names of the most common parameters and what
they control. These should all be given as parameters to the -D switch inNAME=VALUE format (e.g. -DBUILD_TESTS=Y).
Argument Name
Explanation
CMAKE_INSTALL_PREFIX
Location where MariaDB MaxScale will be installed to. Set this to /usr if you want MariaDB MaxScale installed into the same place the packages are installed.
BUILD_TESTS
Build unit tests
WITH_SCRIPTS
Install systemd and init.d scripts
PACKAGE
Note: You can look into defaults.cmake for a
list of the CMake variables.
Running unit tests
To run the MaxScale unit test suite, configure the build with -DBUILD_TESTS=Y,
compile and then run the make test command.
Building MariaDB MaxScale packages
If you wish to build packages, just add -DPACKAGE=Y to the CMake invocation
and build the package with make package instead of installing MaxScale withmake install. This process will create a RPM/DEB package depending on your
system.
To build a tarball, add -DTARBALL=Y to the cmake invokation. This will create
a maxscale-x.y.z.tar.gz file where x.y.z is the version number.
Some Debian and Ubuntu systems suffer from a bug where make package fails
with errors from dpkg-shlibdeps. This can be fixed by running make beforemake package and adding the path to the libmaxscale-common.so library to
the LD_LIBRARY_PATH environment variable.
Installing optional components
The MaxScale build system is split into multiple components. The main component
is the core MaxScale package which contains MaxScale and all the modules. This
is the default component that is build, installed and packaged. There is also
the experimental component that contains all experimental modules which are
not considered as part of the core MaxScale package and are either alpha or beta
quality modules.
To build the experimental modules along with the MaxScale core components,
invoke CMake with -DTARGET_COMPONENT=core,experimental.
MaxGUI is a browser-based interface for MaxScale REST-API and query execution.
Enabling MaxGUI
To enable MaxGUI in a testing mode, add admin_host=0.0.0.0 andadmin_secure_gui=false under the [maxscale] section of the MaxScale
configuration file. Once enabled, MaxGUI will be available on port 8989:http://127.0.0.1:8989/
Securing the GUI
To make MaxGUI secure, set admin_secure_gui=true and configure both theadmin_ssl_key and admin_ssl_cert parameters.
MaxGUI uses the same credentials as maxctrl. The default username is admin
with mariadb as the password.
Internally, MaxGUI uses JSON Web Tokens as the
authentication method for persisting the user's session. If the Remember me
checkbox is ticked, the session will persist for 24 hours. Otherwise, the
session will expire as soon as MaxGUI is closed.
To log out, simply click the username section in the top right corner of the
page header to access the logout menu.
Pages
Dashboard
This page provides an overview of MaxScale configuration which includes
Monitors, Servers, Services, Sessions, Listeners, and Filters.
By default, the refresh interval is 10 seconds.
Detail
This page shows information on each MaxScale object and allow to edit its
parameter, relationships and perform other manipulation operations.
Access this page by clicking on the MaxScale object name on the dashboard page
Visualization
This page visualizes MaxScale configuration and clusters.
Cluster: Visualizing a replication cluster into a tree graph and provides
manual cluster manipulation operations such asswitchover, reset-replication, release-locks, failover, rejoin . At the
moment, it supports only servers monitored by Monitor using mariadbmon module.
Access this page by clicking the graph icon on the sidebar navigation.
Settings
This page shows and allows editing of MaxScale parameters.
Access this page by clicking the gear icon on the sidebar navigation.
Logs Archive
Realtime MaxScale logs can be accessed by clicking the logs icon on the sidebar
navigation.
Workspace
The "Workspace" page offers a versatile set of tools for effectively managing
data and database interactions. It includes the following key tasks:
1. Run Queries
Execute queries on various servers, services, or listeners to retrieve data and
perform database operations. Visualize query results using different graph
types such as line, bar, or scatter graphs. Export query results in formats
like CSV or JSON for further analysis and sharing.
2. Data Migration
The "Data Migration" feature facilitates seamless transitions from PostgreSQL
to MariaDB. Transfer data and database structures between the two systems while
ensuring data integrity and consistency throughout the process.
The Consistent Critical Read (CCR) filter allows consistent critical reads to be
done through MaxScale while still allowing scaleout of non-critical reads.
When the filter detects a statement that would modify the database, it attaches
a routing hint to all following statements done by that connection. This routing
hint guides the routing module to route the statement to the primary server where
data is guaranteed to be in an up-to-date state. Writes from one session do not,
by default, propagate to other sessions.
Note: This filter does not work with prepared statements. Only text protocol
queries are handled by this filter.
Controlling the Filter with SQL Comments
The triggering of the filter can be limited further by adding MaxScale supported
comments to queries and/or by using regular expressions. The query comments take
precedence: if a comment is found it is obeyed even if a regular expression
parameter might give a different result. Even a comment cannot cause a
SELECT-query to trigger the filter. Such a comment is considered an error and
ignored.
The comments must follow the
and the HintFilter needs to be in the filter chain before the CCR-filter. If a
query has a MaxScale supported comment line which defines the parameter ccr,
that comment is caught by the CCR-filter. Parameter values match and ignore
are supported, causing the filter to trigger (match) or not trigger (ignore)
on receiving the write query. For example, the query
would normally cause the filter to trigger, but does not because of the
comment. The match-comment typically has no effect, since write queries by
default trigger the filter anyway. It can be used to override an ignore-type
regular expression that would otherwise prevent triggering.
Filter Parameters
The CCR filter has no mandatory parameters.
time
Type:
Mandatory: No
Dynamic: Yes
Default: 60s
The time window during which queries are routed to the primary. The duration
can be specified as documented
but the value will always be rounded to the nearest second.
If no explicit unit has been specified, the value is interpreted as seconds
in MaxScale 2.4. In subsequent versions a value without a unit may be rejected.
The default value for this parameter is 60 seconds.
When a data modifying SQL statement is processed, a timer is set to the value of_time_. Once the timer has elapsed, all statements are routed normally. If a new
data modifying SQL statement is processed within the time window, the timer is
reset to the value of time.
Enabling this parameter in combination with the count parameter causes both
the time window and number of queries to be inspected. If either of the two
conditions are met, the query is re-routed to the primary.
count
Type: count
Mandatory: No
Dynamic: Yes
Default: 0
The number of SQL statements to route to primary after detecting a data modifying
SQL statement. This feature is disabled by default.
After processing a data modifying SQL statement, a counter is set to the value
of count and all statements are routed to the primary. Each executed statement
after a data modifying SQL statement cause the counter to be decremented. Once
the counter reaches zero, the statements are routed normally. If a new data
modifying SQL statement is processed, the counter is reset to the value of_count_.
match, ignore
Type:
Mandatory: No
Dynamic: No
Default: ""
These
control which statements trigger statement re-routing. Only non-SELECT statements are
inspected. For CCRFilter, the exclude-parameter is instead named ignore, yet works
similarly.
options
Type:
Mandatory: No
Dynamic: No
Values: ignorecase
Regular expression options for match and ignore.
global
Type:
Mandatory: No
Dynamic: Yes
Default: false
global is a boolean parameter that when enabled causes writes from one
connection to propagate to all other connections. This can be used to work
around cases where one connection writes data and another reads it, expecting
the write done by the other connection to be visible.
This parameter only works with the time parameter. The use of global andcount at the same time is not allowed and will be treated as an error.
Example Configuration
Here is a minimal filter configuration for the CCRFilter which should solve most
problems with critical reads after writes.
With this configuration, whenever a connection does a write, all subsequent
reads done by that connection will be forced to the primary for 5 seconds.
This prevents read scaling until the modifications have been replicated to the
replicas. For best performance, the value of time should be slightly greater
than the actual replication lag between the primary and its replicas. If the number
of critical read statements is known, the count parameter could be used to
control the number reads that are sent to the primary.
This page is licensed: CC BY-SA / Gnu FDL
MariaDB MaxScale Installation Guide
We recommend to install MaxScale on a separate server, to ensure that there
can be no competition of resources between MaxScale and a MariaDB Server that
it manages.
Install MariaDB MaxScale From MariaDB Repositories
The recommended approach is to use the MariaDB package
repository
to install MaxScale. After enabling the repository by following the
instructions, MaxScale can be installed with the following commands.
For RHEL/Rocky Linux/Alma Linux, use dnf install maxscale.
For Debian and Ubuntu, run apt update followed by apt install maxscale.
For SLES, use zypper install maxscale.
Install MariaDB MaxScale From a RPM/DEB Package
Download the correct MaxScale package for your CPU architecture and operating
system from . MaxScale can be
installed with the following commands.
For RHEL/Rocky Linux/Alma Linux, use dnf install /path/to/maxscale-*.rpm
For Debian and Ubuntu, use apt install /path/to/maxscale-*.deb.
For SLES, use zypper install /path/to/maxscale-*.rpm.
Install MariaDB MaxScale Using a Tarball
MaxScale can also be installed using a tarball.
That may be required if you are using a Linux distribution for which there
exist no installation package or if you want to install many different
MaxScale versions side by side. For instructions on how to do that, please refer to .
Building MariaDB MaxScale From Source Code
Alternatively you may download the MariaDB MaxScale source and build your own binaries.
To do this, refer to the separate document
Assumptions
Memory allocation behavior
MaxScale assumes that memory allocations always succeed and in general does
not check for memory allocation failures. This assumption is compatible with
the Linux kernel parameter
having the value 0, which is also the default on most systems.
With vm.overcommit_memory being 0, memory allocations made by an
application never fail, but instead the application may be killed by the
so-called OOM (out-of-memory) killer if, by the time the application
actually attempts to use the allocated memory, there is not available
free memory on the system.
If the value is 2, then a memory allocation made by an application may
fail and unless the application is prepared for that possiblity, it will
likely crash with a SIGSEGV. As MaxScale is not prepared to handle memory
allocation failures, it will crash in this situation.
The current value of vm.overcommit_memory can be checked with
or
Configuring MariaDB MaxScale
covers the first
steps in configuring your MariaDB MaxScale installation. Follow this tutorial
to learn how to configure and start using MaxScale.
For a detailed list of all configuration parameters, refer to the and the module specific documents
listed in the .
Encrypting Passwords
Read the
section of the configuration guide to set up password encryption for the
configuration file.
Administration Of MariaDB MaxScale
There are various administration tasks that may be done with MariaDB MaxScale.
A command line tools is available, , that will
interact with a running MariaDB MaxScale and allow the status of MariaDB
MaxScale to be monitored and give some control of the MariaDB MaxScale
functionality.
covers the common administration tasks that need to be done with MariaDB MaxScale.
Copying or Backing Up MaxScale
The main configuration file for MaxScale is in /etc/maxscale.cnf and
additional user-created configuration files are in/etc/maxscale.cnf.d/. Objects created or modified at runtime are stored in/var/lib/maxscale/maxscale.cnf.d/. Some modules also store internal data in/var/lib/maxscale/ named after the module or the configuration object.
The simplest way to back up the configuration and runtime data of a MaxScale
installation is to create an archive from the following files and directories:
/etc/maxscale.cnf
/etc/maxscale.cnf.d/
/var/lib/maxscale/
This can be done with the following command:
If MaxScale is configured to store data in custom locations, these should be
included in the backup as well.
A CDC connection object is prepared by instantiating the CDC::Connection
class. To create the actual connection, call the CDC::Connection::connect
method of the class.
After the connection has been created, call the CDC::Connection::read method
to get a row of data. The CDC::Row::length method tells how many values a row
has and CDC::Row::value is used to access that value. The field name of a
value can be extracted with the CDC::Row::key method and the current GTID of a
row of data is retrieved with the CDC::Row::gtid method.
To close the connection, destroy the instantiated object.
Examples
The source code
that demonstrates basic usage of the MaxScale CDC Connector.
Dependencies
The CDC connector depends on:
OpenSSL
RHEL/CentOS 7
Debian Stretch and Ubuntu Xenial
Debian Jessie
openSUSE Leap 42.3
Building and Packaging
To build and package the connector as a library, follow MaxScale build
instructions with the exception of adding -DTARGET_COMPONENT=devel to the
CMake call.
This page is licensed: CC BY-SA / Gnu FDL
MaxScale 23.02 Authentication Modules
This document describes general MySQL protocol authentication in MaxScale. For
REST-api authentication, see the and the .
Similar to the MariaDB Server, MaxScale uses authentication plugins to implement
different authentication schemes for incoming clients. The same plugins also
handle authenticating the clients to backend servers. The authentication plugins
available in MaxScale are , and .
Most of the authentication processing is performed on the protocol level, before
handing it over to one of the plugins. This shared part is described in this
document. For information on an individual plugin, see its documentation.
Named Server Filter
Lua Filter
The luafilter is a filter that calls a set of functions in a Lua script.
Read the for
information on how to write Lua scripts.
Note: This module is experimental and must be built from source. The
module is deprecated in MaxScale 23.08 and might be removed in a future
release.
Filters
What Are Filters?
The filter mechanism in MariaDB MaxScale is a means by which processing can be inserted into the flow of requests and responses between the client connection to MariaDB MaxScale and the MariaDB MaxScale connection to the backend database servers. The path from the client side of MariaDB MaxScale out to the actual database servers can be considered a pipeline, filters can then be placed in that pipeline to monitor, modify, copy or block the content that flows through that pipeline.
Setting up MariaDB MaxScale
This document is designed as a quick introduction to setting up MariaDB MaxScale.
The installation and configuration of the MariaDB Server is not covered in this document.
See the following MariaDB documentation articles for more information on setting up a
primary-replica-cluster or a Galera-cluster:
and
.
This tutorial assumes that one of the standard MaxScale binary distributions is used and
that MaxScale is installed using default options.
Building from source code in GitHub is covered in .
MaxScale and Xpand Tutorial
Since version 2.4, MaxScale has built-in support for Xpand. This
tutorial explains how to setup MaxScale in front of a Xpand
cluster.
There is no Xpand specific router, but both the and
the routers can be
used.
Xpand and Readconnroute
With readconnroute you get simple connection based routing, where
each new connection is created (by default) to the Xpand node with
the least amount of existing connections. That is, with readconnroute
the behaviour will be very similar to the behaviour when is used as the Xpand load
balancer.
Avrorouter Tutorial
This tutorial is a short introduction to the , how to set it up and how it interacts
with the binlogrouter.
The first part configures the services and sets them up for the binary log to Avro
file conversion. The second part of this tutorial uses the client listener
interface for the avrorouter and shows how to communicate with the service
over the network.
Configuration
Ed25519 Authenticator
Throttle
This filter was added in MariaDB MaxScale 2.3
Installing MariaDB MaxScale using a tarball
MariaDB MaxScale is also made available as a tarball, which is named likemaxscale-x.y.z.OS.tar.gz where x.y.z is the same as the corresponding version and OS
identifies the operating system, e.g. maxscale-2.5.6.centos.7.tar.gz.
In order to use the tarball, the following libraries are required:
libcurl
git clone https://github.com/mariadb-corporation/MaxScale
mkdir build
cd build
../MaxScale/BUILD/install_build_deps.sh
cmake ../MaxScale -DCMAKE_INSTALL_PREFIX=/usr
make
sudo make install
sudo ./postinst
make
LD_LIBRARY_PATH=$PWD/server/core/ make package
Enable building of packages
TARGET_COMPONENT
Which component to install, default is the 'core' package. Other targets are 'experimental', which installs experimental packages and 'all' which installs all components.
The luafilter has two parameters. They control which scripts will be called by
the filter. Both parameters are optional but at least one should be defined. If
both global_script and session_script are defined, the entry points in both
scripts will be called.
global_script
The global Lua script. The parameter value is a path to a readable Lua script
which will be executed.
This script will always be called with the same global Lua state and it can be
used to build a global view of the whole service.
session_script
The session level Lua script. The parameter value is a path to a readable Lua
script which will be executed once for each session.
Each session will have its own Lua state meaning that each session can have a
unique Lua environment. Use this script to do session specific tasks.
Lua Script Calling Convention
The entry points for the Lua script expect the following signatures:
nil createInstance(name) - global script only, called when the script is first loaded
When the global script is loaded, it first executes on a global level
before the luafilter calls the createInstance function in the Lua script
with the filter's name as its argument.
nil newSession(string, string) - new session is created
After the session script is loaded, the newSession function in the Lua
scripts is called. The first parameter is the username of the client and
the second parameter is the client's network address.
nil closeSession() - session is closed
The closeSession function in the Lua scripts will be called.
(nil | bool | string) routeQuery(string) - query is being routed
The Luafilter calls the routeQuery functions of both the session and the
global script. The query is passed as a string parameter to the
routeQuery Lua function and the return values of the session specific
function, if any were returned, are interpreted. If the first value is
bool, it is interpreted as a decision whether to route the query or to
send an error packet to the client. If it is a string, the current query
is replaced with the return value and the query will be routed. If nil is
returned, the query is routed normally.
nil clientReply(string) - reply to a query is being routed
This function is called with the name of the server that returned the response.
string diagnostic() - global script only, print diagnostic information
If the Lua function returns a string that is valid JSON, it will be
decoded as JSON and displayed as such in the REST API. If the object does
not decode into JSON, it will be stored as a JSON string.
These functions, if found in the script, will be called whenever a call to the
matching entry point is made.
Script Template
Here is a script template that can be used to try out the luafilter. Copy it
into a file and add global_script=<path to script> into the filter
configuration. Make sure the file is readable by the maxscale user.
Functions Exposed by the Luafilter
The luafilter exposes the following functions that can be called inside the Lua
script API endpoints.
string mxs_get_type_mask()
Returns the type of the current query being executed as a string. The values
are the string versions of the query types defined in query_classifier.h
are separated by vertical bars (|).
This function can only be called from the routeQuery entry point.
string mxs_get_operation()
Returns the current operation type as a string. The values are defined in
query_classifier.h.
This function can only be called from the routeQuery entry point.
string mxs_get_canonical()
Returns the canonical version of a query by replacing all user-defined constant values with question marks.
This function can only be called from the routeQuery entry point.
number mxs_get_session_id()
This function returns the session ID of the current session. Inside thecreateInstance and diagnostic endpoints this function will always return
the value 0.
string mxs_get_db()
Returns the current default database used by the connection.
string mxs_get_user()
Returns the username of the client connection.
string mxs_get_host()
Returns the address of the client connection.
Example Configuration and Script
Here is a minimal configuration entry for a luafilter definition.
And here is a script that opens a file in /tmp/ and logs output to it.
Filters can be divided into a number of categories
Logging filters
Logging filters do not in any way alter the statement or results of the statements that are passed through MariaDB MaxScale. They merely log some information about some or all of the statements and/or result sets.
Two examples of logging filters are contained within the MariaDB MaxScale, a filter that will log all statements and another that will log only a number of statements, based on the duration of the execution of the query.
Statement rewriting filters
Statement rewriting filters modify the statements that are passed through the filter. This allows a filter to be used as a mechanism to alter the statements that are seen by the database, an example of the use of this might be to allow an application to remain unchanged when the underlying database changes or to compensate for the migration from one database schema to another.
Result set manipulation filters
A result set manipulation filter is very similar to a statement rewriting but applies to the result set returned rather than the statement executed. An example of this may be obfuscating the values in a column.
Routing hint filters
Routing hint filters are filters that embed hints in the request that can be used by the router onto which the query is passed. These hints include suggested destinations as well as metric that may be used by the routing process.
Firewall filters
A firewall filter is a mechanism that allows queries to be blocked within MariaDB MaxScale before they are sent on to the database server for execution. They allow constructs or individual queries to be intercepted and give a level of access control that is more flexible than the traditional database grant mechanism.
Pipeline control filters
A pipeline filter is one that has an affect on how the requests are routed within the internal MariaDB MaxScale components. The most obvious version of this is the ability to add a "tee" connector in the pipeline, duplicating the request and sending it to a second MariaDB MaxScale service for processing.
Filter Definition
Filters are defined in the configuration file, typically maxscale.cnf, using a section for each filter instance. The content of the filter sections in the configuration file various from filter to filter, however there are always to entries present for every filter, the type and module.
The type is used by the configuration manager within MariaDB MaxScale to determine what this section is defining and the module is the name of the plugin that implements the filter.
When a filter is used within a service in MariaDB MaxScale the entry filters= is added to the service definition in the ini file section for the service. Multiple filters can be defined using a syntax akin to the Linux shell pipe syntax.
The names used in the filters= parameter are the names of the filter definition sections in the ini file. The same filter definition can be used in multiple services and the same filter module can have multiple instances, each with its own section in the ini file.
Filter Examples
The filters that are bundled with the MariaDB MaxScale are documented separately, in this section a short overview of how these might be used for some simple tasks will be discussed. These are just examples of how these filters might be used, other filters may also be easily added that will enhance the MariaDB MaxScale functionality still further.
Log The 30 Longest Running Queries
The top filter can be used to measure the execution time of every statement within a connection and log the details of the longest running statements.
The first thing to do is to define a filter entry in the ini file for the top filter. In this case we will call it "top30". The type is filter and the module that implements the filter is called topfilter.
In the definition above we have defined two filter specific parameters, the count of the number of statement to be logged and a filebase that is used to define where to log the information. This filename is a stem to which a session id is added for each new connection that uses the filter.
The filter keeps track of every statement that is executed, monitors the time it takes for a response to come back and uses this as the measure of execution time for the statement. If the time is longer than the other statements that have been recorded, then this is added to the ordered list within the filter. Once 30 statements have been recorded those statements that have been recorded with the least time are discarded from the list. The result is that at any time the filter has a list of the 30 longest running statements in each session.
When the session ends a report will be written for the session into the logfile defined. That report will include the top 30 longest running statements, plus summary data for the session;
The time the connection was opened.
The host the connection was from.
The username used in the connection.
The duration of the connection.
The total number of statements executed in the connection.
The average execution time for a statement in this connection.
Duplicate Data From Your Application Into Cassandra
The scenario we are using in this example is one in which you have an online gaming application that is designed to work with a MariaDB database. The database schema includes a high score table which you would like to have access to in a Cassandra cluster. The application is already using MariaDB MaxScale to connect to a MariaDB Galera cluster, using a service names BubbleGame. The definition of that service is as follows
The table you wish to store in Cassandra in called HighScore and will contain the same columns in both the MariaDB table and the Cassandra table. The first step is to install a MariaDB instance with the Cassandra storage engine to act as a bridge server between the relational database and Cassandra. In this bridge server add a table definition for the HighScore table with the engine type set to Cassandra.
See Cassandra Storage Engine Overview for details.
Add this server into the MariaDB MaxScale configuration and create a service that will connect to this server.
Next add a filter definition for the tee filter that will duplication insert statements that are destined for the HighScore table to this new service.
The above filter definition will cause all statements that match the regular expression inset.*HighScore.*values to be duplication and sent not just to the original destination, via the router but also to the service named Cassandra.
The final step is to add the filter to the BubbleGame service to enable the use of the filter.
This page is licensed: CC BY-SA / Gnu FDL
Bootstrap servers
The Xpand monitor is capable of autonomously figuring out the cluster
configuration, but in order to get going there must be at least one_server_-section referring to a node in the Xpand cluster.
That server defintion will be used by the monitor in order to connect
to the Xpand cluster. There can be more than one such "bootstrap"
definition to cater for the case that the node used as a bootstrap
server is down when MaxScale starts.
NOTE These bootstrap servers should only be referred to from the
Xpand monitor configuration, but never from a service.
Monitor
In the Xpand monitor section, the bootstrap servers are referred to
in the same way as "ordinary" servers are referred to in other monitors.
The user defined by the user parameter needs the following grants:
In case the same user is used both for the monitor and the service (see below),
then the user must be given the grants required by the service as well.
The bootstrap servers are only used for connecting to the Xpand
cluster; thereafter the Xpand monitor will dynamically find out the
cluster configuration.
The discovered cluster configuration will be stored (the ips and ports
of the Xpand nodes) and upon subsequent restarts the Xpand
monitor will use that information if the bootstrap servers happen to
be unavailable.
With the configuration above maxctrl list servers might output
the following:
All servers whose name start with @@ have been detected dynamically.
Note that the address 10.2.224.101 appears twice; once forBootstrap-1 and another time for @@Xpand:node-6. The Xpand
monitor will create a dynamic server instance for all nodes in the
Xpand cluster; also for the ones used in bootstrap server sections.
Service
The service is specified as follows:
The user defined by the user parameter needs the following grants:
In case the same user is used both for the monitor (see above) and the service,
then the user must be given the grants required by the monitor as well.
Note that the service does not list any specific servers, but
instead refers, using the argument cluster, to the Xpand monitor.
In practice this means that the service will use the servers of the
monitor named Xpand and in the case of a Xpand monitor those
servers will be the ones that the monitor has detected
dynamically. That is, when setup like this, the service will
automatically adjust to any changes taking place in the Xpand
cluster.
NOTE There is no need to specify any router_options, but the
default router_options=running provides the desired behaviour.
In particular do not specify router_options=master as that will
cause only a single node to be used.
Listener
To complete the configuration, a listener must be specified.
Xpand and Readwritesplit
The primary purpose of the router readwritesplit is to split
statements between one primary and multiple replicas. In the case of
Xpand, all servers will be primaries, but readwritesplit may still
be the right choise.
Namely, as readwritesplit is transaction aware and capable of
replaying transactions, it can be used for hiding certain events
taking place in Xpand from the clients that use it.
For instance, whenever a node is removed from or added to a Xpand
cluster there will be a group change, which is visible to a client
as a transaction rollback. However, if readwritesplit is used and
transaction replay is enabled, then MaxScale may be able to hide the
group change so that the client only detects a slight delay.
Apart from the service section, the configuration when using_readwritesplit_ is identical to the readconnroute configuration
described above.
Service
The service is specified as follows:
With this configuration, subject to the boundary conditions of
transaction replaying, a client will neither notice group change
events nor the disappearance of the very node the client is connected
to. In that latter case, MaxScale will simply connect to another node
and replay the current transaction (if one is active). For detailed
information about the transaction replay functionality, please refer
to the readwritesplitdocumentation.
NOTE It is vital to haveslave_selection_criteria=LEAST_GLOBAL_CONNECTIONS, as otherwise
connections will not be distributed evenly across all Xpand
nodes.
As a rule of thumb, use readwritesplit if it is important that
changes taking place in the cluster configuration are hidden from the
applications, otherwise use readconnroute.
The tarball has been built with the assumption that it will be installed in /usr/local.
However, it is possible to install it in any directory, but in that case MariaDB MaxScale
must be invoked with a flag.
Installing as root in /usr/local
If you have root access to the system you probably want to install MariaDB MaxScale under
the user and group maxscale.
The required steps are as follows:
Creating the symbolic link is necessary, since MariaDB MaxScale has been built
with the assumption that the plugin directory is /usr/local/maxscale/lib/maxscale.
The symbolic link also makes it easy to switch between different versions of
MariaDB MaxScale that have been installed side by side in /usr/local;
just make the symbolic link point to another installation.
In addition, the first time you install MariaDB MaxScale from a tarball
you need to create the following directories:
and make maxscale the owner of them:
The following step is to create the MariaDB MaxScale configuration file /etc/maxscale.cnf.
The file etc/maxscale.cnf.template can be used as a base.
Please refer to Configuration Guide for details.
When the configuration file has been created, MariaDB MaxScale can be started.
The -d flag causes maxscale not to turn itself into a daemon,
which is adviseable the first time MariaDB MaxScale is started, as it makes it easier to spot problems.
If you want to place the configuration file somewhere else but in /etc
you can invoke MariaDB MaxScale with the --config flag,
for instance, --config=/usr/local/maxscale/etc/maxscale.cnf.
Note also that if you want to keep everything under /usr/local/maxscale
you can invoke MariaDB MaxScale using the flag --basedir.
That will cause MariaDB MaxScale to look for its configuration file in/usr/local/maxscale/etc and to store all runtime files under /usr/local/maxscale/var.
Installing in any Directory
Enter a directory where you have the right to create a subdirectory. Then do as follows.
The next step is to create the MaxScale configuration file maxscale-x.y.z/etc/maxscale.cnf.
The file maxscale-x.y.z/etc/maxscale.cnf.template can be used as a base.
Please refer to Configuration Guide for details.
When the configuration file has been created, MariaDB MaxScale can be started.
With the flag --basedir, MariaDB MaxScale is told where the lib, etc and var
directories are found. Unless it is specified, MariaDB MaxScale assumes
the lib directory is found in /usr/local/maxscale,
and the var and etc directories in /.
It is also possible to specify the directories and the location of
the configuration file individually. Invoke MaxScale like
to find out the appropriate flags.
This page is licensed: CC BY-SA / Gnu FDL
INSERT INTO departments VALUES ('d1234', 'NewDepartment'); -- maxscale ccr=ignore
sudo zypper install -y libjansson-devel openssl-devel cmake make gcc-c++ git
function createInstance(name)
end
function newSession(user, host)
end
function closeSession()
end
function routeQuery(query)
end
function clientReply(server)
end
function diagnostic()
end
f = io.open("/tmp/test.log", "a+")
function createInstance(name)
f:write("createInstance for " .. name .. "\n")
end
function newSession(user, host)
f:write("newSession for: " .. user .. "@" .. host .. "\n")
end
function closeSession()
f:write("closeSession\n")
end
function routeQuery(query)
f:write("routeQuery: " .. query .. " -- type: " .. mxs_qc_get_type_mask() .. " operation: " .. mxs_qc_get_operation() .. "\n")
end
function clientReply(server)
f:write("clientReply: " .. server .. "\n")
end
function diagnostic()
f:write("diagnostics\n")
return "Hello from Lua!"
end
CREATE USER 'maxscale-monitor'@'maxscalehost' IDENTIFIED BY 'maxscale-monitor-password';
GRANT SELECT ON system.membership TO 'maxscale-monitor'@'maxscalehost';
GRANT SELECT ON system.nodeinfo TO 'maxscale-monitor'@'maxscalehost';
GRANT SELECT ON system.softfailed_nodes TO 'maxscale-monitor'@'maxscalehost';
CREATE USER 'maxscale-service'@'maxscalehost' IDENTIFIED BY 'maxscale-service-password';
GRANT SELECT ON system.users TO 'maxscale-service'@'maxscalehost';
GRANT SELECT ON system.user_acl TO 'maxscale-service'@'maxscalehost';
$ cd maxscale-x.y.z.OS
$ bin/maxscale -d --basedir=.
$ bin/maxscale --help
User account management
Every MaxScale service with a MariaDB protocol listener requires knowledge of
the user accounts defined on the backend databases. The service maintains this
information in an internal component called the user account manager (UAM).
The UAM queries relevant data from the mysql-database of the backends and
stores it. Typically, only the current primary server is queried, as all servers
are assumed to have the same users. The service settings user and password
define the credentials used when fetching user accounts.
The service uses the stored data when authenticating clients, checking their
passwords and database access rights. This results in an authentication process
very similar to the MariaDB Server itself. Unauthorized users are generally
detected already at the MaxScale level instead of the backend servers. This may
not apply in some cases, for example if MaxScale is using old user account data.
If authentication fails, the UAM updates its data from a backend. MaxScale may
attempt authenticating the client again with the refreshed data without
communicating the first failure to the client. This transparent user data update
does not always work, in which case the client should try to log in again.
As the UAM is shared between all listeners of a service, its settings are
defined in the service configuration. For more information, search the configuration guide
for users_refresh_time, users_refresh_interval and_auth_all_servers_. Other settings which affect how the UAM connects to backends
are the global settings auth_connect_timeout and local_address, and
the various server-level ssl-settings.
Required grants
To properly fetch user account information, the MaxScale service user must be
able to read from various tables in the mysql-database: user, db,tables_priv, columns_priv, procs_priv, proxies_priv and roles_mapping.
The user should also have the SHOW DATABASES-grant.
If using MariaDB ColumnStore, the following grant is required:
Limitations and troubleshooting
When a client logs in to MaxScale, MaxScale sees the client's IP address. When
MaxScale then connects the client to backends (using the client's username and
password), the backends see the connection coming from the IP address of
MaxScale. If the client user account is to a wildcard host ('alice'@'%'), this
is not an issue. If the host is restricted ('alice'@'123.123.123.123'),
authentication to backends will fail.
There are two primary ways to deal with this:
Duplicate user accounts. For every user account with a restricted hostname an
equivalent user account for MaxScale is added ('alice'@'maxscale-ip').
Option 1 limits the passwords for user accounts with shared usernames. Such
accounts must use the same password since they will effectively share the
MaxScale-to-backend user account. Option 2 requires server support.
MaxScale supports wildcards _ and % for database-level grants. As with
MariaDB Server, grant select on test_.* to 'alice'@'%'; gives access totest_ as well as test1, test2 and so on. If the GRANT command escapes the
wildcard (grant select on test_.* to 'alice'@'%';) both MaxScale and the
MariaDB Server interpret it as only allowing access to test_. _ and %
are only interpreted as wildcards when the grant is to a database:grant select on test_.t1 to 'alice'@'%'; only grants access to the_test_.t1_-table, not to test1.t1.
Authenticator options
The listener configuration defines authentication options which only affect the
listener. authenticator defines the authentication plugins to use.authenticator_options sets various options. These options may affect an
individual authentication plugin or the authentication as a whole. The latter
are explained below. Multiple options can be given as a comma-separated list.
If enabled, MaxScale will not check the
passwords of incoming clients and just assumes that they are correct.
Wrong passwords are instead detected when MaxScale tries to authenticate to the
backend servers.
This setting is mainly meant for failure tolerance in situations where the
password check is performed outside of MaxScale. If, for example, MaxScale
cannot use an LDAP-server but the backend databases can, enabling this setting
allows clients to log in. Even with this setting enabled, a user account
matching the incoming client username and IP must exist on the backends for
MaxScale to accept the client.
This setting is incompatible with standard MariaDB/MySQL authentication plugin
(MariaDBAuth in MaxScale). If enabled, MaxScale cannot authenticate clients to
backend servers using standard authentication.
If disabled, MaxScale does not require that a
valid user account entry for incoming clients exists on the backends.
Specifically, only the client username needs to match a user account,
hostname/IP is ignored.
This setting may be used to force clients to connect through MaxScale. Normally,
creating the user jdoe@% will allow the user jdoe to connect from any
IP-address. By disabling match_host and replacing the user with_jdoe@maxscale-IP_, the user can still connect from any client IP but will be
forced to go through MaxScale.
lower_case_table_names
Type: number
Mandatory: No
Dynamic: No
Default: 0
Controls database name matching for authentication
when an incoming client logs in to a non-empty database. The setting functions
similar to the MariaDB Server setting
and should be set to the value used by the backends.
The setting accepts the values 0, 1 or 2:
0: case-sensitive matching (default)
1: convert the requested database name to lower case before using case-insensitive
matching. Assumes that database names on the server are stored in lower case.
2: use case-insensitive matching.
true and false are also accepted for backwards compatibility. These map to 1
and 0, respectively.
The identifier names are converted using an ASCII-only function. This means that
non-ASCII characters will retain their case-sensitivity.
Starting with MaxScale versions 2.5.25, 6.4.6, 22.08.5 and 23.02.2, the behavior
of lower_case_table_names=1 is identical with how the MariaDB server
behaves. In older releases the comparisons were done in a case-sensitive manner
after the requested database name was converted into lowercase. Usinglower_case_table_names=2 will behave identically in all versions which makes
it a safe alternative to use when a mix of older and newer MaxScale versions is
being used.
The namedserverfilter is a MariaDB MaxScale filter module able to route
queries to servers based on regular expression (regex) matches. Since it is a
filter instead of a router, the NamedServerFilter only sets routing suggestions.
It requires a compatible router to be effective. Currently, bothreadwritesplit and hintrouter take advantage of routing hints in the
data packets. This filter uses the PCRE2 library for regular expression
matching.
Configuration
The filter accepts settings in two modes: legacy and indexed. Only one of
the modes may be used for a given filter instance. The legacy mode is meant for
backwards compatibility and allows only one regular expression and one server
name in the configuration. In indexed mode, up to 25 regex-server pairs are
allowed in the form match01 - target01, match02 - target02 and so on.
Also, in indexed mode, the server names (targets) may contain a list of names or
special tags ->master or ->slave.
All parameters except the deprecated match and target parameters can
be modified at runtime. Any modifications to the filter configuration will
only affect sessions created after the change has completed.
Below is a configuration example for the filter in indexed-mode. The legacy mode
is not recommended and may be removed in a future release. In the example, a
SELECT on TableOne (match01) results in routing hints to two named servers,
while a SELECT on TableTwo is suggested to be routed to the primary server of the
service. Whether a list of server names is interpreted as a route-to-any or
route-to-all is up to the attached router. The HintRouter sees a list as a
suggestion to route-to-any. For additional information on hints and how they can
also be embedded into SQL-queries, see Hint-Syntax.
Filter Parameters
NamedServerFilter requires at least one matchXY - targetXY pair.
matchXY defines a PCRE2 regular expression
against which the incoming SQL query is matched. XY must be a number in the range
01 - 25. Each match-setting pairs with a similarly indexed target-setting. If one is
defined, the other must be defined as well. If a query matches the pattern, the filter
attaches a routing hint defined by the target-setting to the query. The_options_-parameter affects how the patterns are compiled.
The hint which is attached to the queries matching the regular expression defined by_matchXY_. If a compatible router is used in the service the query will be routed
accordingly. The target can be one of the following:
a server or service name (adds a HINT_ROUTE_TO_NAMED_SERVER hint)
a list of server names, comma-separated (adds severalHINT_ROUTE_TO_NAMED_SERVER hints)
->master (adds a HINT_ROUTE_TO_MASTER hint)
->slave (adds a HINT_ROUTE_TO_SLAVE hint)
->all (adds a HINT_ROUTE_TO_ALL hint)
The support for service names was added in MaxScale 6.3.2. Older
versions of MaxScale did not accept service names in the target
parameters.
source
Type: string
Mandatory: No
Dynamic: Yes
Default: None
This optional parameter defines an IP address or mask which a connecting
client's IP address is matched against. Only sessions whose address matches this
setting will have this filter active and performing the regex matching. Traffic
from other client IPs is simply left as is and routed straight through.
Since MaxScale 2.1 it's also possible to use % wildcards:
Note that using source=% to match any IP is not allowed.
Since MaxScale 2.3 it's also possible to specify multiple addresses separated
by comma. Incoming client connections are subsequently checked against each.
user
Type: string
Mandatory: No
Dynamic: Yes
Default: None
This optional parameter defines a username the connecting client username is
matched against. Only sessions that are connected using this username will have
the match and routing hints applied to them. Traffic from other users is simply
left as is and routed straight through.
Additional remarks
The maximum number of accepted match - target pairs is 25.
In the configuration file, the indexed match and target settings may be in any order
and may skip numbers. During SQL-query matching, however, the regexes are tested
in ascending order: match01, match02, match03 and so on. As soon as a match is
found for a given query, the routing hints are written and the packet is
forwarded to the next filter or router. Any remaining match regexes are
ignored. This means the match - target pairs should be indexed in priority
order, or, if priority is not a factor, in order of decreasing match
probability.
Binary-mode prepared statements (COM_STMT_PREPARE) are handled by matching
the prepared sql against the match-parameters. If a match is found, the
routing hints are attached to any execution of that prepared statement. Text-
mode prepared statements are not supported in this way. To divert them, use
regular expressions which match the specific "EXECUTE"-query.
Examples
Example 1 - Route queries targeting a specific table to a server
This will route all queries matching the regular expression *from *users to
the server named server2. The filter will ignore character case in queries.
A query like SELECT * FROM users would be routed to server2 where as a query
like SELECT * FROM accounts would be routed according to the normal rules of
the router.
The precise installation process varies from one distribution to another. Details on
package installation can be found in the Installation Guide.
Creating a user account for MaxScale
MaxScale checks that incoming clients are valid. To do this, MaxScale needs to retrieve
user authentication information from the backend databases. Create a special user
account for this purpose by executing the following SQL commands on the primary server of
your database cluster. The following tutorials will use these credentials.
MariaDB versions 10.2.2 to 10.2.10 also require GRANT SELECT ON mysql.* TO 'maxscale'@'%';
Creating client user accounts
Because MariaDB MaxScale sits between the clients and the backend databases, the backend
databases will see all clients as if they were connecting from MaxScale's address. This
usually means that two sets of grants for each user are required.
For example, assume that the user 'jdoe'@'client-host' exists and MaxScale is located at_maxscale-host_. If 'jdoe'@'client-host' needs to be able to connect through MaxScale,
another user, 'jdoe'@'maxscale-host', must be created. The second user must have the
same password and similar grants as 'jdoe'@'client-host'.
The quickest way to do this is to first create the new user:
Then do a SHOW GRANTS query:
Then copy the same grants to the 'jdoe'@'maxscale-host' user.
An alternative to generating two separate accounts is to use one account with a wildcard
host ('jdoe'@'%') which covers both hosts. This is more convenient but less secure than
having specific user accounts as it allows access from all hosts.
Creating the configuration file
MaxScale reads its configuration from /etc/maxscale.cnf. A template configuration is
provided with the MaxScale installation.
A global maxscale section is included in every MaxScale configuration file. This section
sets the values of various global parameters, such as the number of threads MaxScale uses
to handle client requests. To set thread count to the number of available cpu cores, set
the following.
Configuring the servers
Read the Configuring Servers mini-tutorial for server
configuration instructions.
After configuration is complete, MariaDB MaxScale is ready to start. For systems that
use systemd, use the systemctl command.
For older SysV systems, use the service command.
If MaxScale fails to start, check the error log in /var/log/maxscale/maxscale.log to see
if any errors are detected in the configuration file.
Checking MaxScale status with MaxCtrl
The maxctrl-command can be used to confirm that MaxScale is running and the services,
listeners and servers have been correctly configured. The following shows expected output
when using a read-write-splitting configuration.
MariaDB MaxScale is now ready to start accepting client connections and route queries to
the backend cluster.
The primary server where we will be replicating from needs to have binary logging
enabled, binlog_format set to row and binlog_row_image set tofull. These can be enabled by adding the two following lines to the my.cnf
file of the primary.
You can find out more about replication formats from the
Configuring MaxScale
We start by adding two new services into the configuration file. The first
service is the binlogrouter service which will read the binary logs from the
primary server. The second service will read the binlogs as they are streamed
from the primary and convert them into Avro format files.
The source parameter in the avro-service points to the replication-service
we defined before. This service will be the data source for the avrorouter. The_filestem_ is the prefix in the binlog files and start_index is the binlog
number to start from. With these parameters, the avrorouter will start reading
events from binlog binlog.000015.
Note that the filestem and start_index must point to the file that is the
first binlog that the binlogrouter will replicate. For example, if the first
file you are replicating is my-binlog-file.001234, set the parameters tofilestem=my-binlog-file and start_index=1234.
Before starting the MaxScale process, we need to make sure that the binary logs
of the primary server contain the DDL statements that define the table
layouts. What this means is that the CREATE TABLE statements need to be in the
binary logs before the conversion process is started.
If the binary logs contain data modification events for tables that aren't
created in the binary logs, the Avro schema of the table needs to be manually
created. There are multiple ways to do this:
Dump the database to a replica, configure it to replicate from the primary and
point MaxScale to this replica (this is the recommended method as it requires no
extra steps)
If you used the schema generator scripts, all Avro schema files for tables that
are not created in the binary logs need to be in the location pointed to by the_avrodir_ parameter. The files use the following naming:<database>.<table>.<schema_version>.avsc. For example, the schema file name of
the test.t1 table would be test.t1.0000001.avsc.
Starting MariaDB MaxScale
The next step is to start MariaDB MaxScale and set up the binlogrouter. We do
that by connecting to the MySQL listener of the replication_router service and
executing a few commands.
NOTE: GTID replication is not currently supported and file-and-position
replication must be used.
This will start the replication of binary logs from the primary server at
172.18.0.1 listening on port 3000. The first file that the binlogrouter
replicates is binlog.000015. This is the same file that was configured as the
starting file in the avrorouter.
For more details about the SQL commands, refer to the Binlogrouter documentation.
After the binary log streaming has started, the avrorouter will automatically
start processing the binlogs.
Creating and Processing Data
Next, create a simple test table and populated it with some data by executing
the following statements.
To use the cdc.py command line client to connect to the CDC service, we must first
create a user. This can be done via maxctrl by executing the following command.
This will create the maxuser:maxpwd credentials which can then be used to
request a JSON data stream of the test.t1 table that was created earlier.
The output is a stream of JSON events describing the changes done to the
database.
The first record is always the JSON format schema for the table describing the
types and names of the fields. All records that follow it represent the changes
that have happened on the database.
Ed25519 is a highly secure authentication method based on public key
cryptography. It is used with the auth_ed25519-plugin of MariaDB Server.
When a client authenticates via ed25519, MaxScale first sends them a random
message. The client signs the message using their password as private key and
sends the signature back. MaxScale then checks the signature using the public
key fetched from the mysql.user-table. The client password or an equivalent
token is never exposed. For more information, see .
The security of this authentication scheme presents a problem for a proxy such
as MaxScale since MaxScale needs to log in to backend servers on behalf of the
client. Since each server will generate their own random messages, MaxScale
cannot simply forward the original signature. Either the real password is
required, or a different authentication scheme must be used between MaxScale
and backends. The MaxScale ed25519auth-plugin supports both alternatives.
Configuration
To begin, add "ed25519auth" to the list of authenticators for a listener.
MaxScale will now authenticate incoming clients with ed25519 if their user
account has plugin set to "ed25519" in the mysql.user-table. However,
routing queries will fail since MaxScale cannot authenticate to backends. To
continue, either use a mapping file or enable sha256-mode. Sha256-mode is
enabled with the following settings.
ed_mode
This setting defines the authentication mode used. Two values are supported:
ed25519 (default) Digital signature based authentication. Requires mapping
for backend support.
sha256 Authenticate client with caching_sha2_password-plugin instead.
Requires either SSL or configured RSA-keys.
ed_rsa_privkey_path and ed_rsa_pubkey_path
Defines the RSA-keys used for encrypting the client password if SSL is not in
use. Should point to files with the private and public keys.
Using a mapping file
To enable MaxScale to authenticate to backends,user mapping
can be used. The mapping and backend passwords are given in a json-file.
The client can map to an identical username or to another user, and the backend
authentication scheme can be something else than ed25519.
The following example maps user "alpha" to "beta" and MaxScale then uses
standard authentication to log into backends as "beta". User "alpha"
authenticates to MaxScale using whatever method configured in the server.
User "gamma" does not map to another user, just the password is given.
MaxScale configuration:
/home/joe/mapping.json:
Using sha256-authentication
The mapping-based solution requires the DBA to maintain a file with user
passwords, which has security and upkeep implications. To avoid this,
MaxScale can instead use the caching_sha2_password-plugin to authenticate
the client. This authentication scheme transmits the client password to MaxScale
in full, allowing MaxScale to log into backends using ed25519. MaxScale
effectively lies to the client about its authentication plugin and then uses
the correct plugin with the backends. Enable sha256-authentication by setting
authentication option ed_mode to "sha256".
sha256-authentication is best used with encrypted connections. The example
below shows a listener configured for sha256-mode and SSL.
If SSL is not in use, caching_sha2_password transmits the password using
RSA-encryption. In this case, MaxScale needs the public and private RSA-keys.
MaxScale sends the public key to the client if they don't already have it and
the client uses it to encrypt the password. MaxScale then uses the private key
to decrypt the password. The example below shows a listener configured for
sha256-mode without SSL.
The keyfiles can be generated with OpenSSL using the following commands.
The throttle filter is used to limit the maximum query frequency (QPS - queries
per second) of a database session to a configurable value. The main use cases
are to prevent a rogue session (client side error) and a DoS attack from
overloading the system.
The throttling is dynamic. The query frequency is not limited to an absolute
value. Depending on the configuration the throttle will allow some amount of
high frequency queries, or especially short bursts with no frequency limitation.
Configuration
Basic Configuration
This configuration states that the query frequency will be throttled to around
500 qps, and that the time limit a query is allowed to stay at the maximum
frequency is 60 seconds. All values involving time are configured in
milliseconds. With the basic configuration the throttling will be nearly
immediate, i.e. a session will only be allowed very short bursts of high
frequency querying.
When a session has been continuously throttled for throttling_duration
milliseconds, or 60 seconds in this example, MaxScale will disconnect the
session.
Allowing high frequency bursts
The two parameters max_qps and sampling_duration together define how a
session is throttled.
Suppose max qps is 400 qps and sampling duration is 10 seconds. Since QPS is not
an instantaneous measure, but one could say it has a granularity of 10 seconds,
we see that over the 10 seconds 10*400 = 4000 queries are allowed before
throttling kicks in.
With these values, a fresh session can start off with a speed of 2000 qps, and
maintain that speed for 2 seconds before throttling starts.
If the client continues to query at high speed and throttling duration is set to
10 seconds, Maxscale will disconnect the session 12 seconds after it started.
Filter Parameters
max_qps
Type: number
Mandatory: Yes
Dynamic: Yes
Maximum queries per second.
This is the frequency to which a session will be limited over a given time
period. QPS is not measured as an instantaneous value but over a configurable
sampling duration (see sampling_duration).
Sampling duration defines the window of time over which QPS is measured. This
parameter directly affects the amount of time that high frequency queries are
allowed before throttling kicks in.
The lower this value is, the more strict throttling becomes. Conversely, the
longer this time is, the longer bursts of high frequency querying is allowed.
This value defines what continuous throttling means. Continuous throttling
starts as soon as the filter throttles the frequency. Continuous throttling ends
when no throttling has been performed in the past continuous_duration time.
SmartRouter is the query router of the SmartQuery framework. Based on the type
of the query, each query is routed to the server or cluster that can best
handle it.
For workloads where both transactional and analytical queries are needed,
SmartRouter unites the Transactional (OLTP) and Analytical (OLAP) workloads into
a single entry point in MaxScale. This allows a MaxScale client to freely mix
transactional and analytical queries using the same connection. This is known
as Hybrid Transactional and Analytical Processing, HTAP.
Configuration
SmartRouter is configured as a service that either routes to other MaxScale
routers or plain servers. Although one can configure SmartRouter to use a plain
server directly, we refer to the configured "servers" as clusters.
For details about the standard service parameters, refer to the .
master
Type: target
Mandatory: Yes
Dynamic: No
One of the clusters must be designated as the master. All writes go to the
primary cluster, which for all practical purposes should be a primary-replica
ReadWriteSplit. This document does not go into details about setting up
primary-replica clusters, but suffice to say, that when setting up the ColumnStore
servers they should be configured to be replicas of a MariaDB server running an
InnoDB engine.
The ReadWriteSplit has more on primary-replica setup.
Example
Suppose we have a Transactional service like
for which we have defined the listener
That is, that service can be accessed using the socket /tmp/rws-row.sock.
The Analytical service could look like this
Then we can define the SmartQuery service as follows
Note that the SmartQuery listener listens on a port, while the Row and Column
service listeners listen on Unix domain sockets. The reason is that there is a
significant performance benefit when SmartRouter accesses the services over a
Unix domain socket compared to accessing them over a TCP/IP socket.
A complete configuration example can be found at the end of this document.
Cluster selection - how queries are routed
SmartRouter keeps track of the performance, or the execution time, of queries to
the clusters. Measurements are stored with the canonical of a query as the key.
The canonical of a query is the sql with all user-defined constants replaced with
question marks. When SmartRouter sees a read-query whose canonical has not been
seen before, it will send the query to all clusters. The first response from a
cluster will designate that cluster as the best one for that canonical. Also,
when the first response is received, the other queries are cancelled. The
response is sent to the client once all clusters have responded to the query
or the cancel.
There is obviously overhead when a new canonical is seen. This means that
queries after a MaxScale start will be slightly slower than normal. The
execution time of a query depends on the database engine, and on the contents
of the tables being queried. As a result, MaxScale will periodically re-measure
queries.
The performance behavior of queries under dynamic conditions, and their effect
on different storage engines is being studied at MariaDB. As we learn more, we
will be able to better categorize queries and move that knowledge into
SmartRouter.
Limitations
LOAD DATA LOCAL INFILE is not supported.
The performance data is not persisted. The measurements will be performed
anew after each startup.
The Regex filter is a filter module for MariaDB MaxScale that is able to rewrite
query content using regular expression matches and text substitution. The
regular expressions use the .
PCRE2 library uses a different syntax than POSIX to refer to capture
groups in the replacement string. The main difference is the usage of the dollar
character instead of the backslash character for references e.g. $1 instead of\1. For more details about the replacement string differences, please read the
chapter in the PCRE2 manual.
Configuration
The following demonstrates a minimal configuration.
Filter Parameters
The Regex filter has two mandatory parameters: match and replace.
match
Type:
Mandatory: Yes
Dynamic: Yes
Defines the text in the SQL statements that is replaced.
options
Type:
Mandatory: No
Dynamic: Yes
Values: ignorecase
The options-parameter affects how the patterns are compiled as .
replace
Type: string
Mandatory: Yes
Dynamic: Yes
This is the text that should replace the part of the SQL-query matching the
pattern defined in match.
source
Type: string
Mandatory: No
Dynamic: Yes
Default: None
The optional source parameter defines an address that is used to match against
the address from which the client connection to MariaDB MaxScale
originates. Only sessions that originate from this address will have the match
and replacement applied to them.
user
Type: string
Mandatory: No
Dynamic: Yes
Default: None
The optional user parameter defines a username that is used to match against
the user from which the client connection to MariaDB MaxScale originates. Only
sessions that are connected using this username will have the match and
replacement applied to them.
log_file
Type: string
Mandatory: No
Dynamic: Yes
Default: None
The optional log_file parameter defines a log file in which the filter writes
all queries that are not matched and matching queries with their replacement
queries. All sessions will log to this file so this should only be used for
diagnostic purposes.
log_trace
Type: string
Mandatory: No
Dynamic: Yes
Default: None
The optional log_trace parameter toggles the logging of non-matching and
matching queries with their replacements into the log file on the info level.
This is the preferred method of diagnosing the matching of queries since the log
level can be changed at runtime. For more details about logging levels and
session specific logging, please read the .
Examples
Example 1 - Replace MySQL 5.1 create table syntax with that for later versions
MySQL 5.1 used the parameter TYPE = to set the storage engine that should be
used for a table. In later versions this changed to be ENGINE =. Imagine you
have an application that you can not change for some reason, but you wish to
migrate to a newer version of MySQL. The regexfilter can be used to transform
the create table statements into the form that could be used by MySQL 5.5
This page is licensed: CC BY-SA / Gnu FDL
Xpand Monitor
Overview
The Xpand Monitor is a monitor that monitors a Xpand cluster. It is
capable of detecting the cluster setup and creating corresponding server
instances within MaxScale.
Required Grants
The monitor user must have the following grants:
Further, if you want be able to softfail and unsoftfail a node via MaxScale,
then the monitor user must have SUPER privileges:
Configuration
A minimal configuration for a monitor requires one server in the Xpand
cluster, and a username and a password to connect to the server. Note that
by default the Xpand monitor will only use that server in order to
dynamically find out the configuration of the cluster; after startup it
will completely rely upon information obtained at runtime. To change the
default behaviour, please see the parameter .
To ensure that the Xpand monitor will be able to start, it is adviseable
to provide more than one server to cater for the case that not all nodes
are always up when MaxScale starts.
Note: All services that use servers monitored by xpandmon should use
the cluster parameter to define the set of servers they use. This will
guarantee that the services use servers that are valid members of the
XPand cluster.
Dynamic Servers
The server objects the Xpand monitor creates for each detected
Xpand node will be named like
where <name-of-xpand-monitor> is the name of the Xpand monitor
instance, as defined in the MaxScale configuration file, and <id> is the
id of the Xpand node.
For instance, with the Xpand monitor defined as above and a Xpand
cluster consisting of 3 nodes whose ids are 1, 2 and 3 respectively,
the names of the created server objects will be:
When dynamic servers are created, the values for the configuraton settingsmax_routing_connections, persistmaxtime, persistpoolmax andproxy_protocol are copied from the settings of the bootstrap servers.
Note that the values of these settings must be identical on every
bootstrap server.
Common Monitor Parameters
For a list of optional parameters that all monitors support, read the document.
Xpand Monitor optional parameters
These are optional parameters specific to the Xpand Monitor.
cluster_monitor_interval
Defines, in milliseconds, how often the monitor checks the state of the
entire cluster. The default value is 60000 (1 minute), which should not
be lowered as that may have an adverse effect on the Cluster itself.
The interval is specified as documented . If no explicit unit
is provided, the value is interpreted as milliseconds in MaxScale 2.4. In subsequent
versions a value without a unit may be rejected.
health_check_threshold
Defines how many times the health check may fail before the monitor
considers a particular node to be down. The default value is 2.
dynamic_node_detection
By default, the Xpand monitor will only use the bootstrap nodes
in order to connect to the Xpand cluster and then find out the
cluster configuration dynamically at runtime.
That behaviour can be turned off with this optional parameter, in
which case all Xpand nodes must manually be defined as shown below.
The default value of dynamic_node_detection is true.
See also .
health_check_port
With this optional parameter it can be specified what health check
port to use, if dynamic_node_detection has been disabled.
The default value is 3581.
Note that this parameter is ignored unless dynamic_node_detection
is false. Note also that the port must be the same for all nodes.
Commands
The Xpand monitor supports the following module commands.
softfail
With the softfail module command, a node can be softfailed via
MaxScale. The command requires as argument the name of the Xpand
monitor instance (as defined in the configuration file) and the name
of the node to be softfailed.
For instance, with a configuration file like
then the node whose server name is @@TheXpandMonitor:node-1 can
be softfailed like
If the softfailing of a node is successfully initiated, then the status
of the corresponding MaxScale server object will be set to Draining,
which will prevent new connections from being created to the node.
When the number of connections through MaxScale to the node has dropped
to 0, its state will change to Drained. Note that the state Drained
only tells that there are no connections to the node, not what the state
of the softfailing operation is.
unsoftfail
With the unsoftfail module command, a node can be unsoftfailed via
MaxScale. The command requires as argument the name of the Xpand
monitor instance (as defined in the configuration file) and the name
of the node to be unsoftfailed.
With a setup similar to the softfail case, a node can be unsoftfailed
like:
If a node is successfully softfailed, then a Draining status of
the corresponding MaxScale server object will be cleared.
SOFTFAILed nodes
During the cluster check, which is performed once percluster_monitor_interval, the monitor will also check whether any
nodes are being softfailed. The status of the corresponding server
object of a node being softfailed will be set to Draining,
which will prevent new connections from being created to that node.
When the number of connections through MaxScale to the node has dropped
to 0, its state will change to Drained. Note that the state Drained
only tells that there are no connections to the node, not what the state
of the softfailing operation is.
If a node that was softfailed is UNSOFTFAILed then the Draining
status will be cleared.
If the softfailing and unsoftfailing is initiated using the softfail
and unsoftfail commands of the Xpand monitor, then there will be
no delay between the softfailing or unsoftfailing being initiated and theDraining status being turned on/off.
This page is licensed: CC BY-SA / Gnu FDL
Transaction Performance Monitoring Filter
Note: This module is experimental and must be built from source. The
module is deprecated in MaxScale 23.08 and might be removed in a future
release.
The Transaction Performance Monitoring (TPM) filter is a filter module for MaxScale
that monitors every SQL statement that passes through the filter.
The filter groups a series of SQL statements into a transaction by detecting
'commit' or 'rollback' statements. It logs all committed transactions with necessary
information, such as timestamp, client, SQL statements, latency, etc., which
can be used later for transaction performance analysis.
Configuration
The configuration block for the TPM filter requires the minimal filter
options in it's section within the maxscale.cnf file, stored in /etc/maxscale.cnf.
Filter Options
The TPM filter does not support any filter options currently.
Filter Parameters
The TPM filter accepts a number of optional parameters.
Filename
The name of the output file created for performance logging.
The default filename is tpm.log.
Source
The optional source parameter defines an address that is used
to match against the address from which the client connection
to MaxScale originates. Only sessions that originate from this
address will be logged.
User
The optional user parameter defines a user name that is used
to match against the user from which the client connection to
MaxScale originates. Only sessions that are connected using
this username are logged.
Delimiter
The optional delimiter parameter defines a delimiter that is used to
distinguish columns in the log. The default delimiter is :::.
Query_delimiter
The optional query_delimiter defines a delimiter that is used to
distinguish different SQL statements in a transaction.
The default query delimiter is @@@.
Named_pipe
named_pipe is the path to a named pipe, which TPM filter uses to
communicate with 3rd-party applications (e.g., ).
Logging is enabled when the router receives the character '1' and logging is
disabled when the router receives the character '0' from this named pipe.
The default named pipe is /tmp/tpmfilter and logging is disabled by default.
For example, the following command enables the logging:
Similarly, the following command disables the logging:
Log Output Format
For each transaction, the TPM filter prints its log in the following format:
<timestamp> | <server_name> | <user_name> | <latency of the transaction> | <latencies of individual statements in the transaction> (delimited by 'query_delimiter') | <actual SQL statements>
Examples
Example 1 - Log Transactions for Performance Analysis
You want to log every transaction with its SQL statements and latency
for future transaction performance analysis.
Add a filter with the following definition:
After the filter reads the character '1' from its named pipe, the following
is an example log that is generated from the above TPM filter with the above configuration:
Note that 3 and 6 are latencies of each transaction in milliseconds, while 0.165 and 0.123 are latencies of the first statement of each transaction in milliseconds.
This page is licensed: CC BY-SA / Gnu FDL
Tee Filter
Top Filter
Hintfilter
This filter adds routing hints to a service. The filter has no parameters.
Binlog Filter
This filter was introduced in MariaDB MaxScale 2.3.0.
CREATE USER 'maxscale'@'maxscalehost' IDENTIFIED BY 'maxscale-password';
GRANT SELECT ON mysql.user TO 'maxscale'@'maxscalehost';
GRANT SELECT ON mysql.db TO 'maxscale'@'maxscalehost';
GRANT SELECT ON mysql.tables_priv TO 'maxscale'@'maxscalehost';
GRANT SELECT ON mysql.columns_priv TO 'maxscale'@'maxscalehost';
GRANT SELECT ON mysql.procs_priv TO 'maxscale'@'maxscalehost';
GRANT SELECT ON mysql.proxies_priv TO 'maxscale'@'maxscalehost';
GRANT SELECT ON mysql.roles_mapping TO 'maxscale'@'maxscalehost';
GRANT SHOW DATABASES ON *.* TO 'maxscale'@'maxscalehost';
GRANT ALL ON infinidb_vtable.* TO 'maxscale'@'maxscalehost';
CREATE USER 'maxscale'@'%' IDENTIFIED BY 'maxscale_pw';
GRANT SELECT ON mysql.user TO 'maxscale'@'%';
GRANT SELECT ON mysql.db TO 'maxscale'@'%';
GRANT SELECT ON mysql.tables_priv TO 'maxscale'@'%';
GRANT SELECT ON mysql.columns_priv TO 'maxscale'@'%';
GRANT SELECT ON mysql.procs_priv TO 'maxscale'@'%';
GRANT SELECT ON mysql.proxies_priv TO 'maxscale'@'%';
GRANT SELECT ON mysql.roles_mapping TO 'maxscale'@'%';
GRANT SHOW DATABASES ON *.* TO 'maxscale'@'%';
CREATE USER 'jdoe'@'maxscale-host' IDENTIFIED BY 'my_secret_password';
MariaDB [(none)]> SHOW GRANTS FOR 'jdoe'@'client-host';
+-----------------------------------------------------------------------+
| Grants for jdoe@client-host |
+-----------------------------------------------------------------------+
| GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'jdoe'@'client-host' |
+-----------------------------------------------------------------------+
1 row in set (0.01 sec)
GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'jdoe'@'maxscale-host';
# The Replication Proxy service
[replication-service]
type=service
router=binlogrouter
server_id=4000
master_id=3000
filestem=binlog
user=maxuser
password=maxpwd
# The Avro conversion service
[avro-service]
type=service
router=avrorouter
source=replication-service
filestem=binlog
start_index=15
# The listener for the replication-service
[replication-listener]
type=listener
service=replication-service
port=3306
# The client listener for the avro-service
[avro-listener]
type=listener
service=avro-service
protocol=CDC
port=4001
[RWS-Column]
type = service
router = readwritesplit
servers = column_server_1, column_server_2, ...
[RWS-Column-Listener]
type = listener
service = RWS-Column
socket = /tmp/rws-col.sock
[SmartQuery]
type = service
router = smartrouter
targets = RWS-Row, RWS-Column
master = RWS-Row
[SmartQuery-Listener]
type = listener
service = SmartQuery
port = <port>
[maxscale]
[row_server_1]
type = server
address = <ip>
port = <port>
[row_server_2]
type = server
address = <ip>
port = <port>
[Row-Monitor]
type = monitor
module = mariadbmon
servers = row_server_1, row_server_2
user = <user>
password = <password>
monitor_interval = 2000ms
[column_server_1]
type = server
address = <ip>
port = <port>
[Column-Monitor]
type = monitor
module = csmon
servers = column_server_1
user = <user>
password = <password>
monitor_interval = 2000ms
# Row Read write split
[RWS-Row]
type = service
router = readwritesplit
servers = row_server_1, row_server_2
user = <user>
password = <password>
[RWS-Row-Listener]
type = listener
service = RWS-Row
socket = /tmp/rws-row.sock
# Columnstore Read write split
[RWS-Column]
type = service
router = readwritesplit
servers = column_server_1
user = <user>
password = <password>
[RWS-Column-Listener]
type = listener
service = RWS-Column
socket = /tmp/rws-col.sock
# Smart Query router
[SmartQuery]
type = service
router = smartrouter
targets = RWS-Row, RWS-Column
master = RWS-Row
user = <user>
password = <password>
[SmartQuery-Listener]
type = listener
service = SmartQuery
port = <port>
CREATE USER 'maxscale'@'maxscalehost' IDENTIFIED BY 'maxscale-password';
GRANT SELECT ON system.membership TO 'maxscale'@'maxscalehost';
GRANT SELECT ON system.nodeinfo TO 'maxscale'@'maxscalehost';
GRANT SELECT ON system.softfailed_nodes TO 'maxscale'@'maxscalehost';
The tee filter is a "plumbing" fitting in the MariaDB MaxScale filter toolkit.
It can be used in a filter pipeline of a service to make copies of requests from
the client and send the copies to another service within MariaDB MaxScale.
Please Note: Starting with MaxScale 2.2.0, any client that connects to a
service which uses a tee filter will require a grant for the loopback address,
i.e. 127.0.0.1.
Configuration
The configuration block for the TEE filter requires the minimal filter
parameters in its section within the MaxScale configuration file. The service to
send the duplicates to must be defined.
Filter Parameters
The tee filter requires a mandatory parameter to define the service to replicate
statements to and accepts a number of optional parameters.
target
Type: target
Mandatory: No
Dynamic: Yes
Default: none
The target where the filter will duplicate all queries. The target can be either
a service or a server. The duplicate connection that is created to this target
will be referred to as the "branch target" in this document.
service
Type: service
Mandatory: No
Dynamic: Yes
Default: none
The service where the filter will duplicate all queries. This parameter is
deprecated in favor of the target parameter and will be removed in a future
release. Both target and service cannot be defined.
The optional source parameter defines an address that is used to match against
the address from which the client connection to MariaDB MaxScale originates.
Only sessions that originate from this address will be replicated.
user
Type: string
Mandatory: No
Dynamic: Yes
Default: None
The optional user parameter defines a user name that is used to match against
the user from which the client connection to MariaDB MaxScale originates. Only
sessions that are connected using this username are replicated.
Enable synchronous routing mode. When configured with sync=true, the filter
will queue new queries until the response from both the main and the branch
target has been received. This means that for n executed queries, n - 1
queries are guaranteed to be synchronized. Adding one extra statement
(e.g. SELECT 1) to a batch of statements guarantees that all previous SQL
statements have been successfully executed on both targets.
In the synchronous routing mode, a failure of the branch target will cause the
client session to be closed.
Limitations
All statements that are executed on the branch target are done in an
asynchronous manner. This means that when the client receives the response
there is no guarantee that the statement has completed on the branch
target. The sync feature provides some synchronization guarantees that can
be used to verify successful execution on both targets.
Any errors on the branch target will cause the connection to it to be
closed. If target is a service, it is up to the router to decide whether the
connection is closed. For direct connections to servers, any network errors
cause the connection to be closed. When the connection is closed, no new
queries will be routed to the branch target.
With sync=true, a failure of the branch target will cause the whole session
to be closed.
Module commands
Read Module Commands documentation for
details about module commands.
The tee filter supports the following module commands.
tee disable [FILTER]
This command disables a tee filter instance. A disabled tee filter will not send
any queries to the target service.
tee enable [FILTER]
Enable a disabled tee filter. This resumes the sending of queries to the target
service.
Examples
Example 1 - Replicate all inserts into the orders table
Assume an order processing system that has a table called orders. You also have
another database server, the datamart server, that requires all inserts into
orders to be replicated to it. Deletes and updates are not, however, required.
Set up a service in MariaDB MaxScale, called Orders, to communicate with the
order processing system with the tee filter applied to it. Also set up a service
to talk to the datamart server, using the DataMart service. The tee filter would
have as its service entry the DataMart service, by adding a match parameter of
"insert into orders" would then result in all requests being sent to the order
processing system, and insert statements that include the orders table being
additionally sent to the datamart server.
The top filter is a filter module for MariaDB MaxScale that monitors every SQL
statement that passes through the filter. It measures the duration of that
statement, the time between the statement being sent and the first result being
returned. The top N times are kept, along with the SQL text itself and a list
sorted on the execution times of the query is written to a file upon closure of
the client session.
Configuration
Example minimal configuration:
Filter Parameters
The top filter has one mandatory parameter, filebase, and a number of optional
parameters.
filebase
Type: string
Mandatory: Yes
Dynamic: Yes
The basename of the output file created for each session. The session ID is
added to the filename for each file written. This is a mandatory parameter.
The filebase may also be set as the filter, the mechanism to set the filebase
via the filter option is superseded by the parameter. If both are set the
parameter setting will be used and the filter option ignored.
count
Type: number
Mandatory: No
Dynamic: Yes
Default: 10
The number of SQL statements to store and report upon.
Defines an address that is used to match against
the address from which the client connection to MariaDB MaxScale originates.
Only sessions that originate from this address will be logged.
user
Type: string
Mandatory: No
Dynamic: Yes
Default: None
Defines a username that is used to match against
the user from which the client connection to MariaDB MaxScale originates. Only
sessions that are connected using this username will result in results being
generated.
Examples
Example 1 - Heavily Contended Table
You have an order system and believe the updates of the PRODUCTS table is
causing some performance issues for the rest of your application. You would like
to know which of the many updates in your application is causing the issue.
Add a filter with the following definition:
Note the exclude entry, this is to prevent updates to the PRODUCTS_STOCK table
from being included in the report.
Example 2 - One Application Server is Slow
One of your applications servers is slower than the rest, you believe it is
related to database access but you are not sure what is taking the time.
Add a filter with the following definition:
In order to produce a comparison with an unaffected application server you can
also add a second filter as a control.
In the service definition add both filters
You will then have two sets of logs files written, one which profiles the top 20
queries of the slow application server and another that gives you the top 20
queries of your control application server. These two sets of files can then be
compared to determine what if anything is different between the two.
Output Report
The following is an example report for a number of fictitious queries executed
against the employees example database available for MySQL.
Note: If a query has more than one comment only the first comment is
processed. Always place any MaxScale related comments first before any other
comments that might appear in the query.
Comments and comment types
The client connection will need to have comments enabled. For example themariadb and mysql command line clients have comments disabled by default and
they need to be enabled by passing the --comments or -c option to it. Most,
if not all, connectors keep all comments intact in executed queries.
For comment types, use either -- (notice the whitespace after the double
hyphen) or # after the semicolon or /* ... */ before the semicolon.
Inline comment blocks, i.e. /* .. */, do not require a whitespace character
after the start tag or before the end tag but adding the whitespace is advised.
Hint body
All hints must start with the maxscale tag.
The hints have two types, ones that define a server type and others that contain
name-value pairs.
Routing destination hints
These hints will instruct the router to route a query to a certain type of a
server.
Route to primary
A master value in a routing hint will route the query to a primary server. This
can be used to direct read queries to a primary server for a up-to-date result
with no replication lag.
Route to replica
A slave value will route the query to a replica server. Please note that the
hints will override any decisions taken by the routers which means that it is
possible to force writes to a replica server.
Route to named server
A server value will route the query to a named server. The value of<server name> needs to be the same as the server section name in
maxscale.cnf. If the server is not used by the service, the hint is ignored.
Route to last used server
A last value will route the query to the server that processed the last
query. This hint can be used to force certain queries to be grouped to the same
server.
Name-value hints
These control the behavior and affect the routing decisions made by the
router. Currently the only accepted parameter is the readwritesplit parametermax_slave_replication_lag. This will route the query to a server with a lower
replication lag than this parameter's value.
Hint stack
Hints can be either single-use hints, which makes them affect only one query, or
named hints, which can be pushed on and off a stack of active hints.
Defining named hints:
Pushing a hint onto the stack:
Popping the topmost hint off the stack:
You can define and activate a hint in a single command using the following:
You can also push anonymous hints onto the stack which are only used as long as
they are on the stack:
Prepared Statements
The hintfilter supports routing hints in prepared statements for both thePREPARE and EXECUTE SQL commands as well as the binary protocol prepared
statements.
Binary Protocol
With binary protocol prepared statements, a routing hint in the prepared
statement is applied to the execution of the statement but not the preparation
of it. The preparation of the statement is routed normally and is sent to all
servers.
For example, when the following prepared statement is prepared with the MariaDB
Connector-C function mariadb_stmt_prepare and then executed withmariadb_stmt_execute the result is always returned from the primary:
Support for binary protocol prepared statements was added in MaxScale 6.0
(MXS-2838).
The protocol commands that the routing hints are applied to are:
COM_STMT_EXECUTE
COM_STMT_BULK_EXECUTE
COM_STMT_SEND_LONG_DATA
COM_STMT_FETCH
COM_STMT_RESET
Support for direct execution of prepared statements was added in MaxScale
6.2.0. For example the MariaDB Connector-C uses direct execution whenmariadb_stmt_execute_direct is used.
Text Protocol
Text protocol prepared statements (i.e. the PREPARE and EXECUTE SQL
commands) behave differently. If a PREPARE command has a routing hint, it will
be routed according to the routing hint. Any subsequent EXECUTE command will
not be affected by the routing hint in the PREPARE statement. This means they
must have their own routing hints.
The following example is the recommended method of executing text protocol
prepared statements with hints:
The PREPARE is routed normally and will be routed to all servers. TheEXECUTE will be routed to the primary as a result of it having the route to master hint.
Examples
Routing SELECT queries to primary
In this example, MariaDB MaxScale is configured with the readwritesplit router
and the hint filter.
Behind MariaDB MaxScale is a primary server and a replica server. If there is
replication lag between the primary and the replica, read queries sent to the replica
might return old data. To guarantee up-to-date data, we can add a routing hint
to the query.
The first INSERT query will be routed to the primary. The following SELECT query
would normally be routed to the replica but with the added routing hint it will be
routed to the primary. This way we can do an INSERT and a SELECT right after it
and still get up-to-date data.
The binlogfilter can be combined with a binlogrouter service to selectively
replicate the binary log events to replica servers.
The filter uses two settings, match and exclude, to determine which events
are replicated. If a binlog event does not match or is excluded, the event is
replaced with an empty data event. The empty event is always 35 bytes which
translates to a space reduction in most cases.
When statement-based replication is used, any query events that are filtered out
are replaced with a SQL comment. This causes the query event to do nothing and
thus the event will not modify the contents of the database. The GTID position
of the replicating database will still advance which means that downstream
servers replicating from it keep functioning correctly.
The filter works with both row based and statement based replication but we
recommend using row based replication with the binlogfilter. This guarantees
that there are no ambiguities in the event filtering.