In OceanBase Database, the Leader handles read and write requests in transactions. Therefore, the distribution of Leaders across partitions determines the traffic distribution across nodes.
Overview
A database system stores and queries data in an application architecture. The read and write requests of an application are referred to as database traffic. Database traffic is divided into write traffic, strongly consistent read traffic, and weakly consistent read traffic. Write traffic and strongly consistent read traffic are provided by the Leader replicas of OceanBase Database, while weakly consistent read traffic is provided by both Leader and Follower replicas. ODP provides the capability to route database traffic. ODP implements a simple SQL parser module that extracts the database name, table name, and hint from the SQL statement. Based on the business SQL, routing rules, and the status of OBServer nodes, ODP selects the most suitable OBServer node to forward the request.
Overview of Primary Zone
Traffic distribution is described by the Primary Zone. The Primary Zone indicates the preferred location for Leader replicas. Since Leader replicas handle strongly consistent read and write traffic, the Primary Zone determines the traffic distribution in OceanBase Database. For example, if the primary_zone of a table t1 is set to Zone1, the RootService will try to schedule the Leader of t1 to Zone1.
Note
A replica is an object for data, while a Primary Zone is an object for the container that stores data. Therefore, the data in the container inherits the Leader preference location described by the container's Primary Zone attribute. OceanBase Database currently only supports tenant-level Primary Zones, while OceanBase Database V3.x also supports setting Primary Zones at the table, database, and table group levels.
A Primary Zone is essentially a list of zones, where multiple zones are included. The priority of each zone in the list is configured as follows:
When the Primary Zone list contains multiple zones, the zones separated by ';' have priorities from high to low, while those separated by ',' have the same priority, indicating that traffic is distributed across multiple zones, and these zones provide services simultaneously.
For example, 'hz1,hz2;sh1,sh2;sz1' indicates that hz1 and hz2 have the same priority and higher priority than sh1/sh2 and sz1; sh1 and sh2 have the same priority and higher priority than sz1.
OceanBase Database currently only supports tenant-level Primary Zones and no longer supports setting Primary Zones at the table, database, or table group levels. If you do not specify primary_zone when creating a tenant, the default value is RANDOM, indicating that all zones have the same priority.
The Primary Zone attribute of a tenant can be viewed in the PRIMARY_ZONE column of the oceanbase.DBA_OB_TENANTS view under the sys tenant. Example:
obclient(root@sys)[oceanbase]> SELECT TENANT_ID, TENANT_NAME, TENANT_TYPE, CREATE_TIME, PRIMARY_ZONE, LOCALITY, COMPATIBILITY_MODE, STATUS FROM oceanbase.DBA_OB_TENANTS;
The query result is as follows:
+-----------+-------------+-------------+----------------------------+--------------+----------------------------------------------+--------------------+--------+
| TENANT_ID | TENANT_NAME | TENANT_TYPE | CREATE_TIME | PRIMARY_ZONE | LOCALITY | COMPATIBILITY_MODE | STATUS |
+-----------+-------------+-------------+----------------------------+--------------+----------------------------------------------+--------------------+--------+
| 1 | sys | SYS | 2025-12-29 15:43:42.930290 | RANDOM | FULL{1}@zone1 | MYSQL | NORMAL |
| 1001 | META$1002 | META | 2025-12-29 15:44:48.700796 | zone1;zone2 | FULL{1}@zone1, FULL{1}@zone2, FULL{1}@zone3 | MYSQL | NORMAL |
| 1002 | mysql001 | USER | 2025-12-29 15:44:48.704354 | zone1;zone2 | FULL{1}@zone1, FULL{1}@zone2, FULL{1}@zone3 | MYSQL | NORMAL |
| 1003 | META$1004 | META | 2025-12-29 15:50:35.033311 | zone1 | FULL{1}@zone1 | MYSQL | NORMAL |
| 1004 | oracle001 | USER | 2025-12-29 15:50:35.034367 | zone1 | FULL{1}@zone1 | ORACLE | NORMAL |
+-----------+-------------+-------------+----------------------------+--------------+----------------------------------------------+--------------------+--------+
5 rows in set
Region attribute
In OceanBase Database, each zone has a Region attribute (the REGION column in the DBA_OB_ZONES view), indicating the region where the zone is located. Each zone can only be configured with one region, but a region can contain multiple zones. The setting of the Primary Zone implicitly includes the preferred region for the Leader. Specifically, when you set the Primary Zone, it has two semantic layers:
The specified Primary Zone is the preferred region for the Leader.
The region where the specified Primary Zone is located is the preferred region for the Leader.
Specifically, the Leader will be prioritized to be scheduled to the zone with the highest priority. If the Leader cannot be scheduled to the highest-priority zone, it will be prioritized to be scheduled to another zone within the same region, ensuring that business access to OceanBase Database does not cross cities.
