Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-15935

Connection Redirection Mechanism in MariaDB Client/Server Protocol

    Details

      Description

      Why

      Redirection mechanism is widely used in proxy-based scenario.
      Currently when multiple servers share one proxy, proxy forwards all the packets between servers and clients. Thus, the proxy adds latency, take many computing resources and impacts the overall performance. Especially for short connections scenarios like WordPress, the latency can be a critical issue.
      Supporting redirection mechanism is helpful for proxy-based scenario. It is more like HTTP redirects [1] or Oracle redirected connections [2]. Clients get the servers’ address from proxies and connect to servers transparently without latency and computing resource wasted.

      What to Do

      Client/Server Protocol change needs both client and server support. The routine is

      1. Server sets the capability flag [3] in Initial Handshake Packet, indicating server supports MARIADB_SERVER_REDIRECTION.
        MARIADB_SERVER_REDIRECTION 1 <<31 Server support redirection
      2. Client sets the capability flag [3] in Client Handshake Response Packet, indicating client supports MARIADB_SERVER_REDIRECTION.
      3. If client sets MARIADB_SERVER_REDIRECTION in Client Handshake Response Packet [3], server can send Redirection Information Packet other than OK_Packet / ERR_Packet / Authentication Switch Packet.
      4. Client receives Redirection Information Packet, close the connection, and then use its information to connect the new host.
      5. Client will use the redirection information to set up new connections until information expires or login parse error happens. The redirection information packet contains TTL of the information.

      The Redirection Information Packet schema is

      Field Type Field Name Notes
      int<1> Packet Header Packet header sets 0xFC to indicate it is a Redirection Information Packet.
      int<1> Protocol Version Currently protocol version is 0, specifying TCP-IPv4 protocol.
      int<2> Protocol Property For TCP-IPv4 protocol, it is the port number.
      int<2> Time to Live TTL is the life time of the validity of this redirected information with unit ‘second’.
      string<NUL> Redirected Host Redirected host is a valid IPv4 address, an A name pointing to this address, or a CNAME record.
      string<NUL> Redirected User Default will be the original user in connection string, but can used for proxy user.

      For recursion of redirection, in the scenario, the recursion is not useful. Should not recommend client side implement recursion of redirection.

      [1] https://developer.mozilla.org/en-US/docs/Web/HTTP/Redirections
      [2] https://docs.oracle.com/cd/B10501_01/network.920/a96580/concepts.htm
      [3] https://mariadb.com/kb/en/library/1-connecting-connecting/

        Attachments

        1. redirection.pcapng
          1.62 MB
        2. redirection.png
          redirection.png
          229 kB
        3. screenshot-1.png
          screenshot-1.png
          11 kB
        4. screenshot-2.png
          screenshot-2.png
          12 kB
        5. screenshot-3.png
          screenshot-3.png
          12 kB
        6. screenshot-4.png
          screenshot-4.png
          5 kB

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                elemount Alex Lee
              • Votes:
                0 Vote for this issue
                Watchers:
                13 Start watching this issue

                Dates

                • Created:
                  Updated: