Re: Client-server protocol improvement proposal: Connection redirection
Hi Otto, thanks for bringing this to my attention. Happy to add redirect support to mysql2, looks like its relatively straightforward and sits on top of the existing protocol Andrey On Wed, 19 Jul 2023 at 15:44, Otto Kekäläinen <otto@kekalainen.net> wrote:
Hi Andrey!
I am reaching out to you because you maintain https://github.com/sidorares/node-mysql2
Have you heard about this proposal on the MariaDB developers list?
It suggests adding a new feature to the MariaDB/MySQL protocol where the server would be able to tell clients "No accepting connections - connect to this server instead". The implementation would be work by sending a new error type ERR_REDIRECT along with a client the IP/hostname of a new server, similar to how HTTP 301 redirect works-
Full thread visible at
https://lists.mariadb.org/hyperkitty/list/developers@lists.mariadb.org/threa...
If you want to participate in discussion, just reply to this message and change recipient to developers@lists.mariadb.org.
Thanks!
---------- Forwarded message --------- From: Lenski, Daniel via developers <developers@lists.mariadb.org> Date: Wed, 28 Jun 2023 at 15:24 Subject: [MariaDB developers] Client-server protocol improvement proposal: Connection redirection To: developers@lists.mariadb.org <developers@lists.mariadb.org>
Hi!
I would like to propose a new feature in the MariaDB client-server protocol: application-layer redirection of client connections.
We want the MariaDB server to be able to tell clients connecting to it, “Sorry, this server is unavailable. Connect to an alternate server instead.” This mechanism is inspired by HTTP 302 (“temporary redirect”) mechanism familiar to all developers of web applications, and is intended to have similar semantics and security properties, since these have now been widely deployed and tested for decades.
I have submitted a minimal but viable implementation of this at: https://github.com/MariaDB/server/pull/2681, server-side implementation https://github.com/mariadb-corporation/mariadb-connector-c/pull/226, MariaDB Connector/C implementation
I am seeking advice and opinions on these, and will proceed to finalize this in the following 1-2 months.
In its current form, this implementation allows the MariaDB server administrator to set two variables:
SET GLOBAL SERVER_REDIRECT_MODE={ON,OFF} (the default is OFF) SET GLOBAL SERVER_REDIRECT_TARGET='my-new-server.example.com' (or 192.168.0.123:3307, or new-server.com:3308, etc)
When SERVER_REDIRECT_MODE is set to on, the server will stop accepting new TCP-based connections (unless they are to the extra port, which is intended for emergency administrative use), and it will instead respond to all clients with an error packet:
$ mariadb --host my-server.example.com ERROR 4189 (HY000): |Server is redirecting clients to 'my-new-server.example.com:3307'|my-new-server.example.com:3307
When an appropriately-updated client receives this error packet (error code 4196, message formatted as |Human readable message|<value of SERVER_REDIRECT_TARGET>), it will parse the redirection target out from the error message and attempt a new connection:
$ updated-mariadb --host my-server.example.com -e 'select @@hostname' Got server redirect to 'my-new-server.example.com' (port 3307) +---------------------------+ | @@hostname | +---------------------------+ | my-new-server.example.com | +---------------------------+
The feature is gracefully backwards-compatible. Old clients that do not support redirection will fail and show the message in a form from which humans can deduce what happened. New clients that do support it will follow it to the new server.
[...]
participants (1)
-
Andrey Sidorov