How to Implement MySQL X Protocol on TiDB
Some Documents on MySQL Client Usage Guide MySQL Shell User Guide Server Configuration Guide Using MySQL as a Document Store Application Development API Guide X DevAPI User Guide Introduction to Server Internal Implementation X Protocol. Implementation Principle Communication between client and server is over TCP and the protocol uses protobuf. After the server receives a message, it decodes and analyzes it. The protocol includes a concept called namespace, which specifically refers to whether the namespace is empty or “sql”, in which case the message content is executed as a SQL statement; if it is “xplugin” or “mysqlx,” the message is handled in another way. The other ways can be divided into: Administrative commands CRUD operations “xplugin” and “mysqlx” have the same function, with the latter being the new name for the former, retained temporarily for compatibility. The content of “mysqlx” messages, apart from explicit command content like kill_client, are mostly transformed into SQL statements which the server processes, essentially turning most into a form where the namespace is “sql”. Implementation Steps Start a new server for TiDB. The relevant configuration parameters such as IP, port, and socket need to be set. Implement the reading and writing functionality for message communication. Write a process for this new server to establish connections, including authentication, that follows the protocol. Use tcpdump to capture messages between MySQL and the client to derive protocol content, implementing the process by understanding MySQL source code. The server should include contents like the Query Context from the original TiDB server, as it primarily translates into SQL for execution. Implement the decoding and handling of messages. Although only a sentence, the workload included is substantial. In mysqlx_all_msgs.h, all messages are initialized ...