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
The database system stores and queries data in the application architecture. The read and write requests from the application are referred to as database traffic. Database traffic is divided into write traffic, strong-consistency read traffic, and weak-consistency read traffic. Write traffic and strong-consistency read traffic are provided by the Leader replicas of OceanBase Database, while weak-consistency 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 the 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 strong-consistency 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
The replica describes the data, while the Primary Zone describes the container that holds the 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. OceanBase Database V3.x also supports setting Primary Zones at the table, database, and table group levels.
The Primary Zone is essentially a list of Zones, where each Zone has a priority. The priority is configured as follows:
When the Primary Zone list contains multiple Zones, they are separated by semicolons (;) to indicate a priority from high to low. Zones separated by commas (,) 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 a higher priority than sh1/sh2 and sz1; sh1 and sh2 have the same priority and a higher priority than sz1.
OceanBase Database currently only supports tenant-level Primary Zones. It no longer supports setting Primary Zones at the table, database, and table group levels. If you do not specify the primary_zone when creating a tenant, the default value is RANDOM, indicating that all Zones have the same priority.
You can view the Primary Zone attribute of a tenant in the PRIMARY_ZONE column of the oceanbase.DBA_OB_TENANTS view in the sys tenant. Here is an example:
obclient> SELECT * FROM oceanbase.DBA_OB_TENANTS limit 10;
The query result is as follows:
+-----------+-------------+-------------+----------------------------+----------------------------+--------------+---------------+-------------------+--------------------+--------+---------------+--------+-------------+-------------------+------------------+---------------------+---------------------+---------------------+---------------------+--------------+----------------------------+
| TENANT_ID | TENANT_NAME | TENANT_TYPE | CREATE_TIME | MODIFY_TIME | PRIMARY_ZONE | LOCALITY | PREVIOUS_LOCALITY | COMPATIBILITY_MODE | STATUS | IN_RECYCLEBIN | LOCKED | TENANT_ROLE | SWITCHOVER_STATUS | SWITCHOVER_EPOCH | SYNC_SCN | REPLAYABLE_SCN | READABLE_SCN | RECOVERY_UNTIL_SCN | LOG_MODE | ARBITRATION_SERVICE_STATUS |
+-----------+-------------+-------------+----------------------------+----------------------------+--------------+---------------+-------------------+--------------------+--------+---------------+--------+-------------+-------------------+------------------+---------------------+---------------------+---------------------+---------------------+--------------+----------------------------+
| 1 | sys | SYS | 2023-05-17 18:10:19.940353 | 2023-05-17 18:10:19.940353 | RANDOM | FULL{1}@zone1 | NULL | MYSQL | NORMAL | NO | NO | PRIMARY | NORMAL | 0 | NULL | NULL | NULL | NULL | NOARCHIVELOG | DISABLED |
| 1001 | META$1002 | META | 2023-05-17 18:15:21.455549 | 2023-05-17 18:15:36.639479 | zone1 | FULL{1}@zone1 | NULL | MYSQL | NORMAL | NO | NO | PRIMARY | NORMAL | 0 | NULL | NULL | NULL | NULL | NOARCHIVELOG | DISABLED |
| 1002 | mysql001 | USER | 2023-05-17 18:15:21.461276 | 2023-05-17 18:15:36.669988 | zone1 | FULL{1}@zone1 | NULL | MYSQL | NORMAL | NO | NO | PRIMARY | NORMAL | 0 | 1684398681521302749 | 1684398681521302749 | 1684398681345969089 | 4611686018427387903 | NOARCHIVELOG | DISABLED |
| 1003 | META$1004 | META | 2023-05-17 18:18:19.927859 | 2023-05-17 18:18:36.443233 | zone1 | FULL{1}@zone1 | NULL | MYSQL | NORMAL | NO | NO | PRIMARY | NORMAL | 0 | NULL | NULL | NULL | NULL | NOARCHIVELOG | DISABLED |
| 1004 | oracle001 | USER | 2023-05-17 18:18:19.928914 | 2023-05-17 18:18:36.471606 | zone1 | FULL{1}@zone1 | NULL | ORACLE | NORMAL | NO | NO | PRIMARY | NORMAL | 0 | 1684398681335427475 | 1684398681335427475 | 1684398681144712832 | 4611686018427387903 | NOARCHIVELOG | DISABLED |
| 1005 | META$1006 | META | 2023-05-18 15:48:57.441320 | 2023-05-18 15:49:12.820051 | zone1 | FULL{1}@zone1 | NULL | MYSQL | NORMAL | NO | NO | PRIMARY | NORMAL | 0 | NULL | NULL | NULL | NULL | NOARCHIVELOG | DISABLED |
| 1006 | mq_t1 | USER | 2023-05-18 15:48:57.447657 | 2023-05-18 15:49:12.857944 | zone1 | FULL{1}@zone1 | NULL | MYSQL | NORMAL | NO | NO | PRIMARY | NORMAL | 0 | 1684398680916392609 | 1684398680916392609 | 1684398680742451346 | 4611686018427387903 | NOARCHIVELOG | DISABLED |
+-----------+-------------+-------------+----------------------------+----------------------------+--------------+---------------+-------------------+--------------------+--------+---------------+--------+-------------+-------------------+------------------+---------------------+---------------------+---------------------+---------------------+--------------+----------------------------+
7 rows in set
In the current version, you can also configure the Leader of the log stream to be distributed across secondary Primary Zones. That is, when the first-priority Zone fails, the Leader of the log stream is evenly distributed across the Zones with the next priority level in the PRIMARY_ZONE attribute.
Notice
If the number of Zones in the second-priority PRIMARY_ZONE is different from that in the first-priority PRIMARY_ZONE, the Leader of the log stream may not be evenly distributed across the Zones in the second-priority PRIMARY_ZONE.
Region attribute
In OceanBase Database, each Zone has a Region attribute (the REGION column in the DBA_OB_ZONES view), which indicates the region where the Zone is located. Each Zone can be configured with only 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 layers of semantics:
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 is prioritized to be scheduled to the highest-priority Zone. 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 regions.
