Connection Redirection Mechanism in the MariaDB Client/Server Protocol

Want to improve your MariaDB database performance? Let us help!

  Contact Us
MariaDB starting with 11.3

A connection redirection mechanism was added in MariaDB 11.3.0 (MDEV-15935)

Redirection mechanisms are widely used in proxy-based scenarios.

Previously, when multiple servers shared one proxy, the proxy forwarded all packets between servers and clients. Thus, the proxy added latency, consuming computing resources and impacting overall performance. For scenarios with many short connections, such as WordPress, latency can be a critical issue.

With a redirection mechanism, much like HTTP redirects or Oracle redirected connections, clients get the servers’ address from proxies and connect to servers transparently, without latency and without wasting resources.

Usage

Redirection is handled through a new system variable, redirect_url. The value defaults to an empty string, but can also contain a connection string in the conventional format (in the style of a Connector/C etc. connection url).

This variable is appended to the default value of the session_track_system_variables system variable. If not empty, clients will be redirected to the specified server.

Possible Use Cases

  • Always redirect all clients to a new location:
    • set @@global.redirect_url, start the server with --redirect-url=, or put it in my.cnf
  • redirect to a group of servers randomly
    • create a table with connection urls, one per row.
    • use an sql script that selects a random row from it and sets @@redirect_url to this value
    • specify this script in the --init-connect server parameter
  • dynamically redirect from the primary to one of the replicas

Example

set global redirect_url="mysql://mariadb.org:12345";

Invalid formats are not permitted:

set global redirect_url="mysql://mariadb.org:"; 
ERROR 1231 (42000): Variable 'redirect_url' can't be set to the value of 'mysql://mariadb.org:'

Comments

Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.