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.
Traffic overview
In the application architecture, the database system provides data storage and query capabilities. Application read and write requests are called 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 served by Leader replicas of OceanBase Database, and weakly consistent read traffic is served by both Leader replicas and Follower replicas. ODP provides database traffic routing capabilities. ODP implements a simple SQL parser module that parses the database name, table name, and hints in SQL statements. Based on the business SQL, routing rules, and the status of OBServer nodes, ODP selects the most suitable OBServer node to forward the request.
Introduction to primary zone
Traffic distribution is described by the primary zone, which specifies the preferred location for Leader replicas. Leader replicas handle strongly consistent read and write traffic for the business. Therefore, the primary zone determines the traffic distribution of OceanBase Database. For example, if the primary_zone of a table t1 is set to Zone1, RootService will try to schedule the Leader of table t1 to Zone1.
Note
Replicas describe data, whereas a primary zone describes the container that holds data. Therefore, the data in the container inherits the Leader preference specified by the container's primary zone attribute. OceanBase Database currently supports only tenant-level primary zones. OceanBase Database V3.x also supports primary zone configurations at the table, database, and table group levels.
A primary zone is essentially a list of zones, with multiple zones in the list. The priority of each zone in the list is configured as follows:
When a primary zone list contains multiple zones, the zones separated by semicolons (;) have priorities from high to low, and the zones separated by commas (,) have the same priority. This means that traffic is distributed across multiple zones, and all these zones provide services.
For example, 'hz1,hz2;sh1,sh2;sz1' indicates that hz1 and hz2 have the same priority, which is higher than that of sh1 and sh2, which in turn is higher than that of sz1. sh1 and sh2 have the same priority, which is higher than that of sz1.
OceanBase Database currently only supports tenant-level primary zones and does not support primary zone configurations at the table, database, or table group levels. If the primary_zone is not specified when creating a tenant, it is set to RANDOM by default, indicating that all zones have the same priority.
You can view the primary zone attribute of a tenant by querying the PRIMARY_ZONE column in the oceanbase.DBA_OB_TENANTS view under the sys tenant. Here is an example:
obclient> SELECT * FROM oceanbase.DBA_OB_TENANTS limit 10;
+-----------+-------------+-------------+----------------------------+----------------------------+--------------+---------------+-------------------+--------------------+--------+---------------+--------+-------------+-------------------+------------------+---------------------+---------------------+---------------------+---------------------+--------------+----------------------------+
| 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 addition, in OceanBase Database V4.2.5, starting from V4.2.5 BP7, log stream Leaders can be evenly distributed based on secondary primary zones. That is, when the first-priority zone fails, log stream Leaders are evenly distributed across the zones at the next lower priority level in PRIMARY_ZONE.
Notice
If the number of zones at the second priority level in `PRIMARY_ZONE` differs from that at the first priority level, log stream Leaders may not be evenly distributed across the zones at the second priority level.
Region attribute
In OceanBase Database, a zone has a Region attribute (the REGION field 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 primary zone setting implicitly includes the preferred region for the Leader. Specifically, setting a primary zone has two layers of semantics:
The zones specified in the primary zone are the leader's preferred zones.
The region where the specified primary zone is located is the leader's preferred region.
Specifically, the Leader is preferentially scheduled to the zone with the highest priority. If the replicas in the highest-priority zone cannot become the Leader, a zone in the same region is preferentially selected as the Leader location, ensuring that business access to OceanBase Database avoids cross-city routing when possible.
