Data partitioning is a logical object created based on the table creation statement, and it is a mechanism for dividing and managing table data. Each tenant consists of several Units, and log streams are distributed across these Units according to specific rules, which determines the distribution of data partitions belonging to the log streams on the Units. This section introduces the distribution rules for data and its traffic.
OceanBase Database supports normal tables and partitioned tables. Partitioned tables are further divided into subpartitioned tables and non-subpartitioned partitions. A partitioned table consists of one or more partitions. A normal table is a special case of a partitioned table. OceanBase Database uses range partitioning, list partitioning, hash partitioning, and key partitioning as basic partitioning strategies.
Unit Group overview
Starting from OceanBase Database V4.0, the system imposes a restriction on tenant management, requiring that all zones of a tenant have the same number of units. The system numbers the units in each zone. Units of the same zone that have the same number (UNIT_GROUP_ID) belong to the same unit group. Unit groups have the following characteristics:
Each unit group is assigned a unique ID. You can query the
oceanbase.DBA_OB_UNITSview in the sys tenant for the ID of a unit group.A log stream belongs to only one unit group and is distributed to units in the unit group. Therefore, units in a unit group distribute the same data partitions by log stream. This partitions data into a group. In addition, it requires that the service capabilities of all zones be on par.
Starting from OceanBase Database V4.0, you cannot customize the number of units in each zone for a tenant. Instead, you can only adjust the number of units for the entire unit group. For example, if you want to scale up resources for a tenant, you can increase the number of units. In this case, all zones must be scaled up uniformly; correspondingly, if you want to scale down the resources of a tenant, you can only delete units in the unit group. The unit group mechanism ensures that the data distributed across different zones is homogeneous.
In the sys tenant, you can query the oceanbase.DBA_OB_UNITS view for all units in the cluster and the unit groups to which the units belong. For example:
obclient> select UNIT_ID,TENANT_ID,UNIT_GROUP_ID,ZONE,SVR_IP,SVR_PORT from oceanbase.DBA_OB_UNITS where TENANT_ID = 1004;
+---------+-----------+---------------+--------------+-------------+----------+
| 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 overview
A log stream group is introduced to adapt to a primary zone that is distributed across multiple zones. If the primary zone contains only one zone, you need to create only one log stream in the unit group. If the primary zone contains multiple zones, you need to create multiple log streams in the unit group to implement horizontal scaling of the service capability. These log streams have the same distribution attribute and together 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, a log stream belongs to one and only one log stream group, which cannot be changed; a log stream group corresponds to one and only one unit group; all log streams in a log stream group are distributed to the units in the corresponding unit group, with the leaders of the log streams distributed across the primary zones.
The number of log streams in a log stream group dynamically changes based on the configuration of the primary zone. The life span of a log stream group is the same as that of the unit group.
In the sys tenant, you can query the oceanbase.CDB_OB_LS view for all log streams and log stream groups of tenants in the cluster. For example:
obclient> select TENANT_ID,LS_ID,STATUS,PRIMARY_ZONE,UNIT_GROUP_ID,LS_GROUP_ID from oceanbase.CDB_OB_LS where TENANT_ID=1004;
+-----------+-------+--------+----------------------------------------+---------------+-------------+
| TENANT_ID | LS_ID | STATUS | PRIMARY_ZONE | UNIT_GROUP_ID | LS_GROUP_ID |
+-----------+-------+--------+----------------------------------------+---------------+-------------+
| 1004 | 1 | NORMAL | sa128_obv4_1;sa128_obv4_2,sa128_obv4_3 | 0 | 0 |
| 1004 | 1001 | NORMAL | sa128_obv4_1;sa128_obv4_2,sa128_obv4_3 | 1003 | 1001 |
+-----------+-------+--------+----------------------------------------+---------------+-------------+
2 rows in set
Summary
In summary, the following points are worth noting about the fine-grained concepts introduced in this topic:
A unit is an abstraction of physical resources. Each unit occupies CPU, memory, storage space, and other resources on a node. A unit is the basic unit of resource scheduling. You can adjust the distribution of units across nodes within the same zone to balance the load and improve disaster recovery capabilities of the nodes.
A tenant is composed of multiple units. By specifying the unit number and primary zone of a tenant, a set of units that will handle business traffic is defined. Each unit is placed on a separate node to facilitate horizontal scaling of the tenant's capacity.
A log stream is a sequence of data, including multiple data partitions and ordered redo logs. Paxos is used to synchronize logs across multiple replicas to ensure data consistency and thus high availability of data. A log stream is also the commit unit for transactions. If a transaction is modified within a single log stream, it can be committed through one-stage atomicity. If a transaction is modified across multiple log streams, the OceanBase database-optimized two-stage commit protocol is used to commit the transaction atomically. Log streams participate in distributed transactions. Each log stream has position and role attributes, and the data partitions in a log stream inherit the attributes of the log stream.
The system numbers the units for each zone. Units with the same number form a unit group. A unit group frames the log streams that are distributed only on the units in the unit group.
The number of log stream groups is equal to the number of primary zones, and each log stream group contains the same number of log streams as the number of zones in the primary zone. As a result, each zone in the primary zone list can host the leader of one log stream from the log stream group.
For example, if the tenant configuration is
unit_num =2andprimary_zone ='Z1,Z2,Z3', the tenant will have two unit groups, two log stream groups, and six log streams, as shown in the following figure.
OceanBase Database flexibly distributes data and traffic across multiple nodes at multiple levels. Units can be migrated between nodes within a zone to balance the load and improve disaster recovery capabilities of the nodes.
