OceanBase Database allows you to set a primary zone to specify a preferred location for scheduling the leader.
Basic concept
The primary zone indicates a preferred location for scheduling the leader. If a primary zone is specified, RootService tends to schedule the leader to the primary zone. Assume that primary_zone="zone1" is specified for table t1. RootService schedules the leader of table t1 to zone1 if possible.
Extended concept
The primary zone is essentially a list of zones. The list specifies zone priorities in the following way:
In the primary zone list, zones separated by semicolons (;) are arranged in descending order of priorities, and zones separated by commas (,) have the same priority. For example, 'hz1,hz2;sh1,sh2;sz1' indicates that hz1 and hz2 have the same priority and have higher priorities than sh1, sh2, and sz1, and that sh1 and sh2 have the same priority and have a higher priority than sz1.
Region information
In OceanBase Database, each zone has a region attribute, which indicates the region to which the zone belongs. You can configure only one region for each zone. Multiple zones can belong to the same region. The primary zone indicates a preferred region for scheduling the leader. The primary zone indicates two meanings:
The primary zone is a preferred zone to which the leader is to be scheduled.
The region to which the primary zone belongs is a preferred region to which the leader is to be scheduled.
Specifically, the leader is preferentially scheduled to the zone with the highest priority. If the replica in the zone with the highest priority cannot become the leader, another zone in the same region is preferentially selected for scheduling the leader.
Rewrite the primary zone
OceanBase Database rewrites the primary zone based on the region to which each zone belongs. Rewriting rules:
List the regions corresponding to all zones in the primary zone list. For example, the primary zone list is
'hz1,hz2;sh1,sh2;sz1', and the corresponding primary region list is'hz,hz;sh,sh;sz'.Remove duplicate regions from the primary region list. Specifically, retain the region that appears for the first time, and remove subsequent duplicate regions. The primary region list is converted into
'hz;sh;sz'.Supplement the primary zone list based on the priorities of regions in the primary region list. Specifically, take out the zones corresponding to the regions from the primary zone list, and re-sort the zones. Zones in a region with a higher priority have higher priorities than those in a region with a lower priority. Priorities of zones in the same region follow the zone priorities in the original primary zone list.
Inheritance
OceanBase Database supports table-level, table group-level, database-level (in MySQL mode), schema-level (in Oracle mode), and tenant-level primary zones.
You can choose whether to specify the zone distribution for the primary zone at each level. If no primary zone is specified at a level, the primary zone of the upper level is inherited. However, you must specify a primary zone for each tenant. If you specify no primary zone when you create a tenant, the primary zone is set to RANDOM by default, which indicates that all zones have the same priority.
Table-level primary zone
Check whether a primary zone is specified for the table. If yes, use the primary zone of the table.
If no primary zone is specified for the table, check whether the table belongs to a table group. If the table belongs to a table group, check whether a primary zone is specified for the table group. If yes, use the primary zone of the table group.
If the table does not belong to a table group or no primary zone is specified for the table group, check whether a primary zone is specified for the database (in MySQL mode) or schema (in Oracle mode). If yes, use the primary zone of the database or schema.
If no primary zone is specified for the database or schema, use the primary zone of the tenant.
Table group-level primary zone
Check whether a primary zone is specified for the table group. If yes, use the primary zone of the table group.
If no primary zone is specified for the table group, use the primary zone of the tenant.
Database-level (in MySQL mode) or schema-level (in Oracle mode) primary zone
Check whether a primary zone is specified for the database or schema. If yes, use the primary zone of the database or schema.
If no primary zone is specified for the database or schema, use the primary zone of the tenant.
Examples
Assume that nine zones are available in total. Zones sh1, sh2, and sh3 belong to region SH. Zones hz1, hz2, and hz3 belong to region HZ. Zones sz1, sz2, and sz3 belong to region SZ.
Example 1
The original primary zone list is 'sh1;hz1;hz2;sz1';. It is rewritten based on rule 1 to obtain a primary region list: 'SH;HZ;HZ;SZ'. The primary region list is rewritten based on rule 2 to obtain a new primary zone list: 'SH;HZ;SZ'. The new primary zone list is rewritten based on rule 3 to obtain the final primary zone list: 'sh1;sh2,sh3;hz1;hz2;hz3;sz1;sz2,sz3'.
Descriptions:
Region priorities: SH > HZ > SZ. Zones in region SH have higher priorities than those in regions HZ and SZ. Zones in region HZ have higher priorities than those in region SZ. Zone priorities in region SH: sh1 > sh2 = sh3. Zone priorities in region HZ: hz1 > hz2 > hz3. Zone priorities in region SZ: sz1 > sz2 = sz3. The final primary zone list is 'sh1;sh2,sh3;hz1;hz2;hz3;sz1;sz2,sz3'. Leaders are preferentially scheduled to sh1. When sh1 fails, leaders are sequentially scheduled to sh2 and sh3 based on the preceding priorities.
Example 2
The original primary zone list is 'sh1,sh2;hz1;hz2;sz1';. It is rewritten based on rule 1 to obtain a primary region list: 'SH,SH;HZ;HZ;SZ'. The primary region list is rewritten based on rule 2 to obtain a new primary zone list: 'SH;HZ;SZ'. The new primary zone list is rewritten based on rule 3 to obtain the final primary zone list: 'sh1,sh2;sh3;hz1;hz2;hz3;sz1;sz2,sz3'.
Descriptions:
Region priorities: SH > HZ > SZ. Zones in region SH have higher priorities than those in regions HZ and SZ. Zones in region HZ have higher priorities than those in region SZ. Zone priorities in region SH: sh1 = sh2 > sh3. Zone priorities in region HZ: hz1 > hz2 > hz3. Zone priorities in region SZ: sz1 > sz2 = sz3. The final primary zone list is 'sh1,sh2;sh3;hz1;hz2;hz3;sz1;sz2,sz3'. Leaders are preferentially evenly distributed in sh1 and sh2. When sh1 and sh2 fail, leaders are preferentially scheduled to sh3 based on the preceding priorities.
Example 3
The original primary zone list is 'sh1,hz1;hz2;sz1';. It is rewritten based on rule 1 to obtain a primary region list: 'SH,HZ;HZ;SZ'. The primary region list is rewritten based on rule 2 to obtain a new primary zone list: 'SH,HZ;SZ'. The new primary zone list is rewritten based on rule 3 to obtain the final primary zone list: 'sh1,hz1;hz2;sh2,sh3,hz3;sz1;sz2,sz3'.
Descriptions:
Region priorities: SH = HZ > SZ. Zones in regions SH and HZ have higher priorities than those in region SZ. Zone priorities: sh1 = hz1 > hz2 > sh2 = sh3 = hz3 > sz1 > sz2 = sz3. The final primary zone list is 'sh1,hz1;hz2;sh2,sh3,hz3;sz1;sz2,sz3'. Leaders are preferentially evenly distributed in sh1 and hz1. When sh1 and hz1 fail, leaders are preferentially scheduled to hz2 based on the preceding priorities.