A data partition is a logical object created based on the CREATE TABLE statement. It is a mechanism for dividing and managing table data. Each tenant consists of several units. Log streams are distributed to these units based on specific rules, thereby determining the distribution of data partitions belonging to the log streams across the units. This section describes the rules for data and traffic distribution.
OceanBase Database supports regular tables and partitioned tables. Partitioned tables are further divided into primary partitioned tables and subpartitioned tables. A partitioned table consists of one or more partitions. A regular table consists of a single partition and can be considered a special case of a partitioned table. The basic partitioning strategies in OceanBase Database include range partitioning, list partitioning, hash partitioning, and key partitioning.
Homogeneous and heterogeneous zone modes
OceanBase Database V4.x versions earlier than V4.2.5 (excluding V4.2.5 BP5 and later BP versions, and V4.4.2 and later versions) introduced a restriction in tenant management, requiring that the number of units in each zone of the same tenant must be the same, which is known as the homogeneous zone mode.
In the current version, this restriction has been lifted, and the number of units in each zone of the same tenant is no longer required to be the same, which supports the heterogeneous zone mode.
Notice
By default, existing tenants and upgraded tenants are in the homogeneous zone mode. If you want to enable the heterogeneous zone mode, you need to modify the value of the zone_deploy_mode tenant-level parameter to hetero (heterogeneous zone mode). After modification, you cannot change it back to homo (homogeneous zone mode).
Compared with the homogeneous zone mode, the heterogeneous zone mode has the following differences:
The distribution of log streams is no longer bound to unit groups. The replicas of each zone are no longer restricted to symmetric units. The balancing algorithm controls the distribution of each log stream at the unit level:
In each zone of the tenant, the number of log streams on each unit is the same (the number of log streams on each unit may be different between different zones).
In zones with the same
UNIT_NUM, the log streams are aggregated in a homogeneous manner.
The
UNIT_NUMvalues of resource pools under the tenant can be different, but there can be at most two differentUNIT_NUMvalues.You can use the
ALTER RESOURCE POOLstatement to modify theUNIT_NUMvalue of a specific resource pool under the tenant to achieve resource scaling at the resource pool level.When you use the
ALTER RESOURCE TENANTstatement to reduce theUNIT_NUMvalue to scale down the tenant, you cannot specify theUNIT_GROUPparameter to delete units.When you use the log stream maintenance commands
ALTER SYSTEM CREATE LSandALTER SYSTEM MODIFY LS, you cannot specify theUNIT_GROUPparameter.
Unit groups
In the homogeneous zone mode of a tenant, the number of units in each zone of the tenant must be the same. The system assigns a unique ID to each unit in a zone. Units with the same ID (UNIT_GROUP_ID) in different zones form a unit group. Unit groups have the following characteristics:
Each unit group is assigned a unique ID. The system tenant can view this ID by querying the
UNIT_GROUP_IDcolumn of theoceanbase.DBA_OB_UNITSview.A log stream belongs to only one unit group and is distributed only on the units in that unit group. Therefore, all units in a unit group are distributed with the same data partitions, thereby forming a group of data. This also requires that the service capabilities of each zone are equal.
You cannot configure the number of units in a tenant per zone. You can only adjust the number of units in a unit group as a whole. For example, if you want to horizontally scale out resources for the tenant by increasing the number of units, you must uniformly scale out all zones. Similarly, when you want to scale down the tenant, you can only delete units in a unit group as a whole. This mechanism ensures that the data distribution is homogeneous across different zones.
In the sys tenant, you can query all units and their corresponding unit groups by querying the oceanbase.DBA_OB_UNITS view. For example:
obclient(root@sys)[oceanbase]> SELECT UNIT_ID, TENANT_ID, UNIT_GROUP_ID, ZONE, SVR_IP, SVR_PORT FROM oceanbase.DBA_OB_UNITS WHERE TENANT_ID = 1004;
The query result is as follows:
+---------+-----------+---------------+--------------+-------------+----------+
| UNIT_ID | TENANT_ID | UNIT_GROUP_ID | ZONE | SVR_IP | SVR_PORT |
+---------+-----------+---------------+--------------+-------------+----------+
| 1004 | 1004 | 1003 | sa128_obv4_1 | xx.xx.xx.47 | 2882 |
| 1005 | 1004 | 1003 | sa128_obv4_2 | xx.xx.xx.81 | 2882 |
| 1006 | 1004 | 1003 | sa128_obv4_3 | xx.xx.xx.19 | 2882 |
+---------+-----------+---------------+--------------+-------------+----------+
3 rows in set
Log stream groups
The concept of log stream groups was introduced to adapt to the scenario where the primary zone is distributed across multiple zones. When the primary zone is a single zone, you only need to create one log stream in the UNIT_LIST of the tenant. When the primary zone is multiple zones, you need to create multiple log streams in the UNIT_LIST of the tenant to achieve horizontal scaling of service capabilities. These log streams have the same distribution attributes and collectively form a log stream group. The number of log streams in a log stream group is equal to the number of primary zones.
Therefore, a log stream belongs to one log stream group and cannot be changed. All log streams in a log stream group are distributed on the corresponding units in the UNIT_LIST. The leaders of the log streams are distributed across the primary zones.
The number of log streams in a log stream group dynamically changes with the changes in the primary zone configuration of the tenant.
In the sys tenant, you can query all log streams and their corresponding log stream groups by querying the oceanbase.CDB_OB_LS view. For example:
obclient(root@sys)[oceanbase]> SELECT TENANT_ID, LS_ID, STATUS, PRIMARY_ZONE, LS_GROUP_ID, UNIT_LIST FROM oceanbase.CDB_OB_LS where TENANT_ID=1004;
The query result is as follows:
+-----------+-------+--------+--------------+-------------+-----------+
| TENANT_ID | LS_ID | STATUS | PRIMARY_ZONE | LS_GROUP_ID | UNIT_LIST |
+-----------+-------+--------+--------------+-------------+-----------+
| 1004 | 1 | NORMAL | z1;z2 | 0 | |
| 1004 | 1001 | NORMAL | z1;z2 | 1001 | 1013,1014 |
| 1004 | 1008 | NORMAL | z1;z2 | 1007 | 1025,1026 |
| 1004 | 1013 | NORMAL | z2;z1 | 1001 | 1013,1014 |
| 1004 | 1014 | NORMAL | z2;z1 | 1007 | 1025,1026 |
+-----------+-------+--------+--------------+-------------+-----------+
5 rows in set
Summary
In summary, this section introduces the following fine-grained concepts:
A unit is an abstract representation of physical resources. Each unit occupies a certain amount of physical resources, such as CPU, memory, and storage space, on a node. A unit is the basic unit for resource scheduling. You can adjust the distribution of units on different nodes in the same zone to achieve node load balancing and node disaster recovery.
A tenant consists of multiple units. You can specify the number of units and the primary zone for a tenant to define a set of units that carry business traffic. Each unit is located on a node, which allows you to easily horizontally scale the capacity of a tenant.
A log stream is a set of data partitions and an ordered redo log stream. Multi-replica log synchronization is implemented by using the Paxos protocol to ensure data consistency among replicas and achieve high data availability. A log stream is also the unit of transaction submission. If a transaction modifies data in a single log stream, it can be committed in one atomic phase. If a transaction modifies data in multiple log streams, it can be committed in two atomic phases by using the optimized two-phase commit protocol of OceanBase Database. A log stream is a participant in a distributed transaction. All data partitions in a log stream inherit the location attribute and role attribute of the log stream.
A tenant can be configured in homogeneous zone mode or heterogeneous zone mode.
In homogeneous zone mode:
The system assigns a unique number to each unit in a zone. Units with the same number are grouped into a unit group. A unit group is a set of log streams. These log streams are distributed only on the units in the unit group.
Each log stream group corresponds to a unit group. The number of log streams in a log stream group is determined by the number of zones in the primary zone. Therefore, each zone in the primary zone list can be the leader zone of a log stream in the log stream group.
Assume that the tenant is configured as
unit_num =2andprimary_zone ='Z1,Z2,Z3'. Then, the tenant defines two unit groups, two log stream groups, and six log streams. The following figure shows the distribution of log streams in homogeneous zone mode.
In heterogeneous zone mode:
The system controls the distribution of log streams in units. In each zone of a tenant, the number of log streams on each unit is the same. However, the number of log streams on each unit may vary between zones.
All log streams in a log stream group are distributed on the corresponding units. The leaders of log streams are scattered across the primary zone.
Assume that the tenant has two zones and is configured as
unit_num =1andunit_num =2, andprimary_zone ='zone1'. In a balanced state, the total number of user log streams is 2. TheUNIT_LISTofLS1is(UNIT1, UNIT2), and theUNIT_LISTofLS2is(UNIT1, UNIT3).From the preceding figure, you can see that
LS1andLS2are distributed on the same unit inzone1, but on different units inzone2. This indicates that in heterogeneous zone mode, the distribution of log stream replicas can vary across zones.
OceanBase Database flexibly distributes data and traffic across multiple nodes at multiple levels. Units can be migrated between nodes in a zone to achieve node load balancing and node disaster recovery.
