A data partition is a logical object created based on a table creation statement. It is a mechanism for dividing and managing table data. Each tenant contains several units, and log streams are distributed on the units based on specific rules. This determines how data partitions belonging to the log streams are distributed on the units. This topic describes the distribution rules for data and traffic.
OceanBase Database supports non-partitioned tables and partitioned tables. Partitioned tables are divided into tables with partitions and tables with subpartitions. A partitioned table contains one or more partitions. A non-partitioned table contains only one partition and can be considered a special case of a partitioned table. The basic partitioning strategies of OceanBase Database include RANGE, LIST, HASH, and KEY partitioning.
Homogeneous zone and heterogeneous zone modes
OceanBase Database versions before V4.x (excluding V4.2.5 and V4.2.5 BP5 and later BP versions) impose a tenant management restriction: all zones of the same tenant must have the same number of units, which is the homogeneous zone mode.
In the current version, this restriction is relaxed. The number of units per zone no longer needs to be the same for all zones of a tenant, and tenants can use heterogeneous zone mode.
Notice
By default, existing tenants and upgraded tenants use homogeneous zone mode. To enable heterogeneous zone mode, set the tenant-level parameter zone_deploy_mode to hetero. After the change, you cannot switch back to homo (homogeneous zone mode).
Compared with homogeneous zone mode, heterogeneous zone mode has the following main differences:
Log stream distribution is no longer bound to unit groups. Replicas in each zone no longer need to be limited to symmetric units. The balance algorithm controls log stream distribution at the unit granularity:
Within each zone of the tenant, the number of log streams per unit is equal (the number of log streams per unit may differ across zones).
Within zones that have the same
UNIT_NUM, log streams are aggregated in a homogeneous manner.
The
UNIT_NUMof resource pools in a tenant can differ, but at most two differentUNIT_NUMvalues are allowed.You can use the
ALTER RESOURCE POOLstatement to modify theUNIT_NUMof a single resource pool in a tenant for resource-pool-level scaling.When scaling in with the
ALTER RESOURCE TENANTstatement by reducingUNIT_NUM, you cannot specifyUNIT_GROUPfor deletion.When using the log stream O&M commands
ALTER SYSTEM CREATE LSandALTER SYSTEM MODIFY LS, theUNIT_GROUPparameter is not supported.
Unit group
In homogeneous zone mode, all zones of the same tenant must have the same number of units. The system assigns an ID to each unit in each zone. Units with the same ID (UNIT_GROUP_ID) across different zones form a unit group. Unit groups have the following characteristics:
Each unit group is assigned a unique ID, which can be queried from the
UNIT_GROUP_IDcolumn in theoceanbase.DBA_OB_UNITSview in the sys tenant.One log stream belongs only to one unit group and is distributed only on units in that unit group. Therefore, the same data partitions are distributed on all units in a unit group at the log stream level, thus defining a group of data. This requires equivalent service capabilities across all zones.
You cannot customize the number of units per zone for a tenant. You can only adjust at the unit group level. For example, to horizontally scale out a tenant by increasing the number of units, you must scale out all zones uniformly. Similarly, when scaling in a tenant, you can only delete units by unit group. The unit group mechanism ensures homogeneous data distribution across zones.
In the sys tenant, you can query all units and corresponding unit groups from the oceanbase.DBA_OB_UNITS view. Here is an 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 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 group
The concept of log stream group is introduced to support the distribution of the primary zone across zones. When the primary zone contains a single zone, you need to create only one log stream in the tenant's UNIT_LIST. When the primary zone contains multiple zones, you must create multiple log streams for horizontal scaling of service capabilities. These log streams share the same distribution attributes and form a log stream group. The number of log streams in a log stream group is equal to the number of zones in the primary zone.
Therefore, one log stream belongs to one log stream group, which cannot be modified. All log streams in a log stream group are distributed on the corresponding UNIT_LIST. Log stream Leaders are distributed across the primary zone.
The number of log streams in a log stream group dynamically changes with the tenant's primary zone configuration.
In the sys tenant, you can query log streams of all tenants in the cluster and their log stream groups from 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 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
The following summarizes the concepts described in this section:
Units are abstracted from physical resources. Each unit occupies specific physical resources on a node, including CPU, memory, and storage. Units are the basic unit for resource scheduling. You can adjust the distribution of units across nodes in a zone to achieve load balancing and disaster recovery.
Each tenant contains several units. By setting the tenant's unit number and primary zone, you define a set of units that carry business traffic. Each unit is placed on a node, enabling horizontal scaling of tenant capacity.
A log stream defines a group of data, including several data partitions and ordered RedoLog streams. The Paxos protocol synchronizes logs across replicas to ensure data consistency and high availability. A log stream is also the unit of transaction commit. Modifications within a single log stream can be atomically committed in one phase; modifications across multiple log streams use OceanBase Database's optimized two-phase commit protocol. Log streams are participants in distributed transactions. A log stream has location and role attributes, and all data partitions in the log stream inherit these attributes.
Tenants support homogeneous zone mode and heterogeneous zone mode.
In homogeneous zone mode:
The system assigns an ID to each unit in each zone. Units with the same ID form a unit group. A unit group defines a set of log streams that are distributed only on units in that unit group.
A log stream group corresponds one-to-one with a unit group. In each log stream group, the number of log streams is determined by the number of zones in the primary zone. Therefore, each zone in the primary zone's zone list can host the Leader of one log stream in the log stream group.
For example, if a tenant is configured with
unit_num = 2andprimary_zone = 'Z1,Z2,Z3', the tenant has 2 unit groups, 2 log stream groups, and 6 log streams, as shown in the following figure:
In heterogeneous zone mode:
The system controls log stream distribution at the unit granularity. Within each zone of the tenant, the number of log streams per unit is equal (the number may differ across zones).
All log streams in a log stream group are distributed on the corresponding UNIT_LIST. Log stream Leaders are distributed across the primary zone.
As shown in the following figure, assume a tenant has 2 zones configured with
unit_num = 1andunit_num = 2, andprimary_zone = 'zone1'. In a balanced state, the total number of user log streams is 2.LS1has UNIT_LIST(UNIT1, UNIT2), andLS2has UNIT_LIST(UNIT1, UNIT3).As shown in the figure,
LS1andLS2are distributed on the same unit in zone1, but on different units in zone2. In heterogeneous zone mode, the distribution and aggregation of log stream replicas across zones can differ.
OceanBase Database flexibly distributes data and traffic across multiple nodes at multiple levels. Units can be migrated between nodes within a zone to achieve load balancing and disaster recovery.