Connections
ODP provides users with database access and routing capabilities. By connecting to ODP, you can use OceanBase AI Database normally. When you use database features, ODP interacts with OBServer nodes, and this interaction process is transparent to users. Connection management is one of the key points in this interaction. Database connections include physical connections and logical connections. A physical connection mainly refers to the network connection part, while a logical connection mainly refers to the session part between ODP and OceanBase AI Database.
Characteristics
ODP's connection management has the following characteristics:
- Proxy: ODP acts as both a client and a server and ensures that its interaction behavior complies with the MySQL protocol.
- Features: ODP implements many connection features, such as accessing different clusters and tenants, supporting physical standby databases and the PREPARE statement feature in distributed mode, and being compatible with commands such as
killandshow processlist. - High availability: ODP can handle issues such as timeouts, node status changes, and network status changes, shielding backend exceptions from users.
Note
ODP supports connecting to user tenants of OceanBase AI Database.
Connection mapping
OceanBase AI Database is different from a standalone database. When you connect a client to a standalone database, only one physical connection exists between the client and the database, as shown in the following figure.
When you establish a connection with an OBServer node through ODP, there is one physical connection between your client and ODP, and there may be multiple physical connections between ODP and the OBServer nodes, as shown in the following figure. The connection between the client and ODP is called a client-side connection, and the connection between ODP and the OBServer node is called a server-side connection.
When the data accessed by your client resides on different OBServer nodes, ODP establishes multiple physical connections to these OBServer nodes and manages and reuses them. From the client's perspective, there appears to be only one logical connection. Based on this, ODP can provide many features, such as read/write splitting, data routing for partitioned tables, distributed prepared statements, and backend exception shielding.
Connection features
Unlike a standalone database, ODP changes the connection mapping relationship to M:N. Therefore, some connection features require additional processing. For example, when a user runs the show processlist command to view the number of connections, they expect to see the number of connections between clients and ODP, not the number of connections between ODP and OBServer nodes.
The following section provides detailed information about common connection features:
- Connection stickiness: ODP has not yet implemented state synchronization for all features, such as transaction status, temporary table status, and cursor status. For these features, ODP simply routes all subsequent requests to the node where the state was last known. This eliminates the need for state synchronization but prevents full leverage of distributed system advantages. Therefore, ODP will gradually support the distribution of related features based on their importance.
- Combined use of
show processlistandkillcommands: Theshow processlistcommand displays connections between clients and servers. For ODP, it shows only connections between clients and ODP, not connections between ODP and OBServer nodes. Thekillcommand terminates a client connection. After a client connection closes, ODP also closes the corresponding server-side connection. To use thekillcommand on ODP, you must first obtain the corresponding ID (which can be obtained using theshow processlistcommand). - Impact of load balancing: Because ODP processes the
show processlistandkillcommands, these commands work properly only when both are sent to the same ODP. In environments like public clouds, where a load balancer sits in front of ODP and multiple ODP nodes are attached behind it, if theshow processlistandkillcommands are executed from two different connections, the load balancing component may route the requests to different ODP nodes. In this case, it is recommended not to use these commands.
Routing
Routing is an important feature of OceanBase AI Database and a powerful tool for fast data access in a distributed architecture.
A partition is the basic unit of data storage in OceanBase AI Database. When you create a table, a mapping between tables and partitions is established. In a non-partitioned table, one table corresponds to one partition if the primary/standby mode is not considered. In a partitioned table, one table corresponds to multiple partitions.
Routing enables precise access to the OBServer node where the data resides based on the data distribution across OBServer nodes. It also allows read requests with lower consistency requirements to be routed to the OBServer nodes where replicas reside according to specific policies, thereby fully utilizing server resources. The routing input consists of user SQL statements, configured rules, and OBServer status, while the output is an available OBServer address. The routing logic is illustrated below:
The SQL parsing module uses a custom parser developed by ODP. It only needs to parse the database name, table name, and hints from DML statements, without requiring complex expression deduction.
In the routing rule determination module, ODP must identify the optimal routing rule based on different scenarios. For example, DML requests for strong-consistency reads are routed to the OBServer node where the leader of the partition log stream resides, whereas DML requests for weak-consistency reads and other requests are evenly distributed to the OBServer nodes where the leader and followers reside. If the OceanBase AI Database cluster is deployed across regions, ODP provides LDC routing, preferentially routing requests to an OBServer node in the same IDC, then to an OBServer node in the same city, and finally to an OBServer node in a different city. If the OceanBase AI Database cluster is deployed with read/write splitting, ODP provides rules such as read zone first, read zone only, and non-major-compaction first for you to configure based on your business needs. These rules are combined during route selection to produce a definite routing rule.
Obtaining the routing table means that ODP determines the locations of the replicas involved in a user request based on the SQL statement. ODP first attempts to retrieve the routing table from its local thread cache, then from the global cache, and only if neither is available does it initiate an asynchronous task to query the OBServer for the routing table. ODP uses a trigger-based mechanism to update routing tables. Whenever ODP forwards a request to an OBServer node and the node cannot execute it locally, the node reports this in the response packet. Based on this feedback, ODP decides whether to forcibly update the routing table in the local cache next time. Generally, the routing table changes only when an OBServer node performs a major compaction or when a leader switchover is caused by load balancing.
Selecting the target OBServer involves choosing the optimal OBServer from the routing table obtained in the previous step according to the determined routing rule. After passing the blocklist and allowlist checks, this selected OBServer serves as the final target for request forwarding.