When automatic load balancing cannot meet the user's requirements for aggregating or dispersing specific partitions, you can manually initiate a Transfer Partition operation.
Limitations and considerations
The user who executes the
TRANSFER PARTITIONstatement must have theALTER SYSTEMprivilege. For more information about privileges, see Overview of users and privileges.You can execute the
TRANSFER PARTITIONstatement only on the primary tenant and transfer partitions from a user tenant.After you disable the Transfer feature for a tenant by setting the
enable_transferparameter tofalse, executing theTRANSFER PARTITIONstatement on the tenant will return an error. If you have already executed theTRANSFER PARTITIONstatement, the corresponding Transfer Partition task may be canceled.You cannot execute the
TRANSFER PARTITIONstatement on system tables.You cannot execute the
TRANSFER PARTITIONstatement on user tables in a system tenant.You cannot transfer a regular table to a broadcast log stream or a replicated table to a regular log stream.
You cannot transfer non-independent partitions, such as partitions of a local index table or a LOB table.
You cannot initiate another
TRANSFER PARTITIONstatement for the same partition before the currentTRANSFER PARTITIONstatement is completed.If a balance job is running in the current cluster, a manually triggered
TRANSFER PARTITIONstatement will not be scheduled immediately. To schedule theTRANSFER PARTITIONstatement as soon as possible, you can cancel the running balance job. For more information about how to cancel a balance job, see Cancel a Balance Job.
Prerequisites
The Transfer feature must be enabled before you execute the
TRANSFER PARTITIONstatement. Theenable_transferparameter at the tenant level controls whether the Transfer feature is enabled. By default, the value of this parameter istrue, indicating that the Transfer feature is enabled. For more information about theenable_transferparameter, see enable_transfer.To ensure that the partition location remains fixed, we recommend that you disable the automatic rebalance strategy before you execute the
TRANSFER PARTITIONstatement. This means that you need to set theenable_rebalanceparameter tofalsefor the corresponding tenant. For more information about theenable_rebalanceparameter, see enable_rebalance.The
TRANSFER PARTITIONstatement is not affected by theenable_rebalanceparameter. However, if both theenable_rebalanceandenable_transferparameters are set totrue, the system may automatically migrate a partition to another log stream after you migrate it to the corresponding log stream.
Transfer a partition of a tenant
Log in to the
systenant of the cluster as therootuser.Here is an example of the connection command. Replace the parameters with those in your actual environment.
obclient -h10.xx.xx.xx -P2883 -uroot@sys#obdemo -p***** -AQuery the
DBA_OB_TENANTSview to obtain theTENANT_IDof the target tenant.obclient(root@sys)[oceanbase]> SELECT TENANT_ID FROM oceanbase.DBA_OB_TENANTS WHERE TENANT_NAME = 'oracle_tenant';The query result is as follows:
+-----------+ | TENANT_ID | +-----------+ | 1006 | +-----------+ 1 row in setConfirm the partition information.
You can query the
CDB_OB_TABLE_LOCATIONSview to obtain theTABLE_ID,OBJECT_ID, andLS_IDof the specified partition in the table.Obtain the
TABLE_ID,OBJECT_ID, andLS_IDof the specified partition in a non-partitioned table.Assume that a non-partitioned table named
T1exists in theoracle_tenanttenant. Here is an example of the query:obclient(root@sys)[oceanbase]> SELECT TABLE_ID AS TABLE_ID, OBJECT_ID, TABLET_ID, LS_ID FROM oceanbase.CDB_OB_TABLE_LOCATIONS WHERE TENANT_ID = 1006 AND DATABASE_NAME = 'SYS' AND TABLE_NAME= 'T1' LIMIT 1;The query result is as follows:
+----------+-----------+-----------+-------+ | TABLE_ID | OBJECT_ID | TABLET_ID | LS_ID | +----------+-----------+-----------+-------+ | 500002 | 500002 | 200001 | 1001 | +----------+-----------+-----------+-------+ 1 row in setObtain the
TABLE_ID,OBJECT_ID, andLS_IDof the specified partition in a partitioned table.For a partitioned table, you need to specify the name of the partition.
Assume that a partitioned table named
TBL1_LOG_Rexists in theoracle_tenanttenant.obclient(SYS@oracle_tenant)[SYS]> CREATE TABLE tbl1_log_r(log_id INT,log_date DATE NOT NULL DEFAULT SYSDATE) PARTITION BY RANGE(log_date) (PARTITION M202001 VALUES LESS THAN(TO_DATE('2020/02/01','YYYY/MM/DD')) , PARTITION M202002 VALUES LESS THAN(TO_DATE('2020/03/01','YYYY/MM/DD')) , PARTITION M202003 VALUES LESS THAN(TO_DATE('2020/04/01','YYYY/MM/DD')) , PARTITION M202004 VALUES LESS THAN(TO_DATE('2020/05/01','YYYY/MM/DD')) , PARTITION M202005 VALUES LESS THAN(TO_DATE('2020/06/01','YYYY/MM/DD')) , PARTITION M202006 VALUES LESS THAN(TO_DATE('2020/07/01','YYYY/MM/DD')) , PARTITION M202007 VALUES LESS THAN(TO_DATE('2020/08/01','YYYY/MM/DD')) , PARTITION M202008 VALUES LESS THAN(TO_DATE('2020/09/01','YYYY/MM/DD')) , PARTITION M202009 VALUES LESS THAN(TO_DATE('2020/10/01','YYYY/MM/DD')) , PARTITION M202010 VALUES LESS THAN(TO_DATE('2020/11/01','YYYY/MM/DD')) , PARTITION M202011 VALUES LESS THAN(TO_DATE('2020/12/01','YYYY/MM/DD')) , PARTITION M202012 VALUES LESS THAN(TO_DATE('2021/01/01','YYYY/MM/DD')) , PARTITION MMAX VALUES LESS THAN (MAXVALUE) );Here is an example of the query for the partition
M202005in the partitioned tableTBL1_LOG_R:obclient(root@sys)[oceanbase]> SELECT TABLE_ID AS TABLE_ID, OBJECT_ID, TABLET_ID, LS_ID FROM oceanbase.CDB_OB_TABLE_LOCATIONS WHERE TENANT_ID = 1006 AND DATABASE_NAME = 'SYS' AND TABLE_NAME= 'TBL1_LOG_R' AND PARTITION_NAME = 'M202005' LIMIT 1;The query result is as follows:
+----------+-----------+-----------+-------+ | TABLE_ID | OBJECT_ID | TABLET_ID | LS_ID | +----------+-----------+-----------+-------+ | 500003 | 500009 | 200006 | 1002 | +----------+-----------+-----------+-------+ 1 row in setObtain the
TABLE_ID,OBJECT_ID, andLS_IDof the specified subpartition in a subpartitioned table.For a subpartitioned table, you need to specify the names of the partition and subpartition.
Assume that a subpartitioned table named
T2_F_RLexists in theoracle_tenanttenant.obclient(SYS@oracle_tenant)[SYS]> CREATE TABLE t2_f_rl(col1 INT,col2 VARCHAR2(50)) PARTITION BY RANGE(col1) SUBPARTITION BY LIST(col2) (PARTITION p0 VALUES LESS THAN(100) (SUBPARTITION sp0 VALUES('01'), SUBPARTITION sp1 VALUES('02') ), PARTITION p1 VALUES LESS THAN(200) (SUBPARTITION sp2 VALUES('01'), SUBPARTITION sp3 VALUES('02'), SUBPARTITION sp4 VALUES('03') ) );Here is an example of the query for the subpartition
SP2in the subpartitioned tableT2_F_RL:obclient(root@sys)[oceanbase]> SELECT TABLE_ID AS TABLE_ID, OBJECT_ID, TABLET_ID, LS_ID FROM oceanbase.CDB_OB_TABLE_LOCATIONS WHERE TENANT_ID = 1006 AND DATABASE_NAME = 'SYS' AND TABLE_NAME= 'T2_F_RL' AND PARTITION_NAME = 'P1' AND SUBPARTITION_NAME = 'SP2' LIMIT 1;The query result is as follows:
+----------+-----------+-----------+-------+ | TABLE_ID | OBJECT_ID | TABLET_ID | LS_ID | +----------+-----------+-----------+-------+ | 500018 | 500023 | 200017 | 1003 | +----------+-----------+-----------+-------+ 1 row in set
Select the destination log stream for the transfer.
Query the
CDB_OB_LSview to obtain the log stream status and information of the tenant.obclient(root@sys)[oceanbase]> SELECT * FROM oceanbase.CDB_OB_LS WHERE TENANT_ID = 1006;The query result is as follows:
+-----------+-------+--------+--------------+---------------+-------------+---------------------+----------+---------------------+---------------------+------+-----------+ | TENANT_ID | LS_ID | STATUS | PRIMARY_ZONE | UNIT_GROUP_ID | LS_GROUP_ID | CREATE_SCN | DROP_SCN | SYNC_SCN | READABLE_SCN | FLAG | UNIT_LIST | +-----------+-------+--------+--------------+---------------+-------------+---------------------+----------+---------------------+---------------------+------+-----------+ | 1006 | 1 | NORMAL | zone1 | 0 | 0 | NULL | NULL | 1701244663685197789 | 1701244663685197789 | | | | 1006 | 1001 | NORMAL | zone1 | 0 | 1001 | 1701239786827662637 | NULL | 1701244663685197789 | 1701244663685197789 | | 1001 | | 1006 | 1002 | NORMAL | zone1 | 0 | 1002 | 1701239786831568305 | NULL | 1701244664066906860 | 1701244664066906859 | | 1002 | | 1006 | 1003 | NORMAL | zone1 | 0 | 1003 | 1701239786834300282 | NULL | 1701244664175263949 | 1701244664175263948 | | 1003 | +-----------+-------+--------+--------------+---------------+-------------+---------------------+----------+---------------------+---------------------+------+-----------+ 4 rows in setQuery the
CDB_OB_TABLET_TO_LSview to obtain the Tablet distribution information on the log stream.obclient(root@sys)[oceanbase]> SELECT LS_ID, COUNT(*) AS C FROM oceanbase.CDB_OB_TABLET_TO_LS WHERE TENANT_ID = 1006 GROUP BY LS_ID;The query result is as follows:
+-------+------+ | LS_ID | C | +-------+------+ | 1 | 578 | | 1001 | 7 | | 1002 | 5 | | 1003 | 7 | +-------+------+ 4 rows in setBased on the information shown above, select a suitable log stream as the destination for the transfer.
Execute the following command to transfer a partition.
ALTER SYSTEM TRANSFER PARTITION TABLE_ID [=] table_id, OBJECT_ID [=] object_id TO LS ls_id TENANT = 'tenant_name';where:
table_id: the ID of the table.object_id: the unique identifier of the partition.ls_id: the ID of the destination log stream.tenant_name: the name of the tenant to which the partition belongs.
For example, transfer the
M202005partition of theTBL1_LOG_Rtable in theSYSschema of theoracle_tenanttenant from the current log stream1002to the log stream1003.obclient(root@sys)[oceanbase]> ALTER SYSTEM TRANSFER PARTITION TABLE_ID = 500003, OBJECT_ID = 500009 TO LS 1003 TENANT = 'oracle_tenant';After the Transfer Partition command is executed, you can query the following views to view the task status.
Query the
CDB_OB_TRANSFER_PARTITION_TASKSview to obtain theTASK_ID,TRANSFER_TASK_ID, andBALANCE_JOB_IDof the task.The
CDB_OB_TRANSFER_PARTITION_TASKSview displays all the partition transfer tasks currently being processed by all tenants. Here is an example of the query:obclient(root@sys)[oceanbase]> SELECT TASK_ID, BALANCE_JOB_ID, TRANSFER_TASK_ID, STATUS FROM oceanbase.CDB_OB_TRANSFER_PARTITION_TASKS WHERE TENANT_ID = 1006 AND TABLE_ID = 500003 AND OBJECT_ID = 500009;The query result is as follows:
+---------+----------------+------------------+--------+ | TASK_ID | BALANCE_JOB_ID | TRANSFER_TASK_ID | STATUS | +---------+----------------+------------------+--------+ | 1 | 17304 | 1 | DOING | +---------+----------------+------------------+--------+ 1 row in setYou can view the task status based on the value of the
STATUScolumn in the query result. You can further view the task execution progress as follows:WAITING: indicates that the task is waiting for scheduling to start.INIT: indicates that theBALANCE_JOBhas been built. You can view the execution progress of the associatedBALANCE_JOBbased on theBALANCE_JOB_ID.DOING: indicates that the task has started to transfer the partition. You can view the execution progress of the associated Transfer Partition task based on theTRANSFER_TASK_ID. TheTRANSFER_TASK_IDchanges frequently. A Transfer Partition task involves multiple transfers.
If the query result of the
CDB_OB_TRANSFER_PARTITION_TASKSview is empty, you can query theCDB_OB_TRANSFER_PARTITION_TASK_HISTORYview to view the task result.Query the
CDB_OB_BALANCE_JOBSorCDB_OB_BALANCE_JOB_HISTORYview based on the obtainedBALANCE_JOB_IDto view the execution status of the associated BALANCE_JOB.The
CDB_OB_BALANCE_JOBSview displays all the load balancing tasks currently being executed by all tenants. Each tenant has only one load balancing task (BALANCE_JOB) at a time. Each task generates multiple load balancing subtasks (TRANSFER_TASK). TheCDB_OB_BALANCE_JOB_HISTORYview displays the history of all load balancing tasks executed by all tenants. Here are examples of the queries:obclient(root@sys)[oceanbase]> SELECT * FROM oceanbase.CDB_OB_BALANCE_JOBS WHERE JOB_ID = 17304;obclient(root@sys)[oceanbase]> SELECT * FROM oceanbase.CDB_OB_BALANCE_JOB_HISTORY WHERE JOB_ID = 17304;where
17304is replaced with theBALANCE_JOB_IDobtained in the previous step.The
STATUScolumn in the query result displays the execution status of theBALANCE_JOB:DOING: indicates that the load balancing task is being executed.COMPLETED: indicates that the load balancing task has been successfully executed.CANCELING: indicates that the load balancing task is being canceled.CANCELED: indicates that the load balancing task has been canceled.
Query the
CDB_OB_TRANSFER_TASKSorCDB_OB_TRANSFER_TASK_HISTORYview based on the obtainedTRANSFER_TASK_IDto view the execution status of the associated TRANSFER_TASK.The
CDB_OB_TRANSFER_TASKSview displays the load balancing tasks that are currently being executed for all tenants. At the same time, multiple load balancing tasks (TRANSFER_TASK) can be executed, and these tasks belong to the same load balancing job (BALANCE_JOB). TheCDB_OB_TRANSFER_TASK_HISTORYview displays the history of load balancing tasks executed for all tenants. Here are some query examples:obclient(root@sys)[oceanbase]> SELECT * FROM oceanbase.CDB_OB_TRANSFER_TASKS WHERE TASK_ID = 1;obclient(root@sys)[oceanbase]> SELECT * FROM oceanbase.CDB_OB_TRANSFER_TASK_HISTORY WHERE TASK_ID = 1;In the query,
1needs to be replaced with theTRANSFER_TASK_IDobtained in the previous step.The
STATUScolumn in the query result displays the execution status of theTRANSFER_TASK:INIT: Indicates that the task is being created.START: Indicates that the transfer is starting.DOING: Indicates that the transfer is in progress.ABORTED: Indicates that the transfer task has failed and has been terminated.COMPLETED: Indicates that the transfer task has been completed.FAILED: Indicates that the transfer task has failed.CANCELED: Indicates that the transfer task has been canceled.
Query the
CDB_OB_TRANSFER_PARTITION_TASK_HISTORYview using the obtainedTASK_IDto confirm the result of the transfer partition task.The
CDB_OB_TRANSFER_PARTITION_TASK_HISTORYview displays the history of transfer partition tasks executed for all tenants.obclient(root@sys)[oceanbase]> SELECT * FROM oceanbase.CDB_OB_TRANSFER_PARTITION_TASK_HISTORY WHERE TASK_ID = 1;In the query,
1needs to be replaced with theTASK_IDobtained in the previous step.The
STATUScolumn in the query result displays the result of the transfer partition task:COMPLETED: Indicates that the transfer partition task has been completed.FAILED: Indicates that the transfer partition task has failed. You can check theCOMMENTcolumn to determine the cause of the failure. The following are some common messages in theCOMMENTcolumn:LS not exist or may be in DROPPING/WAIT_OFFLINE status: The log stream at the destination may not exist or may be in theDROPPINGorWAIT_OFFLINEstate.LS status is not NORMAL or is in BLOCK_TABLET_IN state: The log stream at the destination may not be in theNORMALstate, for example, it may be in theCREATINGorCREATEDstate, or it may be in theBLOCK_TABLET_INstate, which means that the log stream cannot receive tablets.Table has beed dropped: The table to which the partition belongs has been dropped.Partition has beed dropped: The partition has been dropped.Partition is already in dest LS: The partition already exists at the destination.Need retry, partition may be dropped: The partition was dropped during the transfer. The system will check whether the partition exists when it generates the next load balancing task.Need retry, partition may be dropped or be transferre: The partition does not exist during the transfer, which may be because the partition was dropped or the partition is no longer in the source log stream. The system will check whether the partition exists or whether a new transfer task needs to be generated when it generates the next load balancing task.
After the transfer partition task is completed, check the partition information again.
obclient(root@sys)[oceanbase]> SELECT TABLE_ID AS TABLE_ID, OBJECT_ID, TABLET_ID, LS_ID FROM oceanbase.CDB_OB_TABLE_LOCATIONS WHERE TENANT_ID = 1006 AND DATABASE_NAME = 'SYS' AND TABLE_NAME= 'TBL1_LOG_R' AND PARTITION_NAME = 'M202005' LIMIT 1;The query result is as follows:
+----------+-----------+-----------+-------+ | TABLE_ID | OBJECT_ID | TABLET_ID | LS_ID | +----------+-----------+-----------+-------+ | 500003 | 500009 | 200006 | 1003 | +----------+-----------+-----------+-------+ 1 row in setThe result indicates that the
M202005partition of theTBL1_LOG_Rtable in theSYSdatabase has been migrated from log stream1002to log stream1003. The transfer partition operation was successful.
Transfer partition for a user tenant
This topic uses the mysql_tenant tenant as an example.
Connect to the database as the tenant administrator of the MySQL mode tenant.
The following example shows how to connect to the database. In your actual environment, you must use the actual database connection information.
obclient -h10.xx.xx.xx -P2883 -uroot@mysql_tenant#obdemo -p***** -ACheck the partition information.
Query the
DBA_OB_TABLE_LOCATIONSview to obtain theTABLE_ID,OBJECT_ID, andLS_IDof the specified partition.Obtain the
TABLE_ID,OBJECT_ID, andLS_IDof a non-partitioned tableAssume that a non-partitioned table
t1exists in themysql_tenanttenant. The following example shows how to query theTABLE_ID,OBJECT_ID, andLS_IDof thet1table.obclient(root@mysql_tenant)[test]> SELECT TABLE_ID AS TABLE_ID, OBJECT_ID, TABLET_ID, LS_ID FROM oceanbase.DBA_OB_TABLE_LOCATIONS WHERE DATABASE_NAME = 'test' AND TABLE_NAME= 't1' LIMIT 1;The query result is as follows:
+----------+-----------+-----------+-------+ | TABLE_ID | OBJECT_ID | TABLET_ID | LS_ID | +----------+-----------+-----------+-------+ | 500002 | 500002 | 200001 | 1001 | +----------+-----------+-----------+-------+ 1 row in setObtain the
TABLE_ID,OBJECT_ID, andLS_IDof a partitioned tableFor a partitioned table, you only need to specify the name of the partition. The following example shows how to query the
TABLE_ID,OBJECT_ID, andLS_IDof thetbl1_ltable.Assume that a partitioned table
tbl1_lexists in themysql_tenanttenant.obclient(root@mysql_tenant)[test]> CREATE TABLE tbl1_l (col1 BIGINT PRIMARY KEY,col2 VARCHAR(50)) PARTITION BY LIST(col1) (PARTITION p0 VALUES IN (1, 2, 3), PARTITION p1 VALUES IN (5, 6), PARTITION p2 VALUES IN (DEFAULT) );The following example shows how to query the information about the
p1partition of thetbl1_ltable.obclient(root@mysql_tenant)[oceanbase]> SELECT TABLE_ID AS TABLE_ID, OBJECT_ID, TABLET_ID, LS_ID FROM oceanbase.DBA_OB_TABLE_LOCATIONS WHERE DATABASE_NAME = 'test' AND TABLE_NAME= 'tbl1_l' AND PARTITION_NAME = 'p1' LIMIT 1;The query result is as follows:
+----------+-----------+-----------+-------+ | TABLE_ID | OBJECT_ID | TABLET_ID | LS_ID | +----------+-----------+-----------+-------+ | 500012 | 500014 | 200009 | 1001 | +----------+-----------+-----------+-------+ 1 row in setObtain the
TABLE_ID,OBJECT_ID, andLS_IDof a subpartitioned tableFor a subpartitioned table, you need to specify the names of the partition and subpartition.
Assume that a subpartitioned table
t2_f_rclcexists in themysql_tenanttenant.obclient(root@mysql_tenant)[test]> CREATE TABLE t2_f_rclc (col1 INT,col2 INT) PARTITION BY RANGE COLUMNS(col1) SUBPARTITION BY LIST COLUMNS(col2) (PARTITION p0 VALUES LESS THAN(100) (SUBPARTITION sp0 VALUES IN(1,3), SUBPARTITION sp1 VALUES IN(4,6), SUBPARTITION sp2 VALUES IN(7,9)), PARTITION p1 VALUES LESS THAN(200) (SUBPARTITION sp3 VALUES IN(1,3), SUBPARTITION sp4 VALUES IN(4,6), SUBPARTITION sp5 VALUES IN(7,9)) );The following example shows how to query the information about the
sp3subpartition of thet2_f_rclctable.obclient(root@mysql_tenant)[oceanbase]> SELECT TABLE_ID AS TABLE_ID, OBJECT_ID, TABLET_ID, LS_ID FROM oceanbase.DBA_OB_TABLE_LOCATIONS WHERE DATABASE_NAME = 'test' AND TABLE_NAME= 't2_f_rclc' AND PARTITION_NAME = 'P1' AND SUBPARTITION_NAME = 'sp3' LIMIT 1;The query result is as follows:
+----------+-----------+-----------+-------+ | TABLE_ID | OBJECT_ID | TABLET_ID | LS_ID | +----------+-----------+-----------+-------+ | 500003 | 500009 | 200005 | 1002 | +----------+-----------+-----------+-------+ 1 row in set
Select the destination log stream for the transfer.
Query the
DBA_OB_LSview to obtain the log stream status and information of the tenant.obclient(root@mysql_tenant)[oceanbase]> SELECT * FROM oceanbase.DBA_OB_LS;The query result is as follows:
+-------+--------+--------------+---------------+-------------+---------------------+----------+---------------------+---------------------+------+-----------+ | LS_ID | STATUS | PRIMARY_ZONE | UNIT_GROUP_ID | LS_GROUP_ID | CREATE_SCN | DROP_SCN | SYNC_SCN | READABLE_SCN | FLAG | UNIT_LIST | +-------+--------+--------------+---------------+-------------+---------------------+----------+---------------------+---------------------+------+-----------+ | 1 | NORMAL | zone1 | 0 | 0 | NULL | NULL | 1701247658419109377 | 1701247658419109377 | | | | 1001 | NORMAL | zone1 | 0 | 1001 | 1701239750437064613 | NULL | 1701247658419109376 | 1701247658419109376 | | 1001 | | 1002 | NORMAL | zone1 | 0 | 1002 | 1701239750441114919 | NULL | 1701247658223204599 | 1701247658223204599 | | 1002 | | 1003 | NORMAL | zone1 | 0 | 1003 | 1701239750443869478 | NULL | 1701247659122731843 | 1701247659030755559 | | 1003 | +-------+--------+--------------+---------------+-------------+---------------------+----------+---------------------+---------------------+------+-----------+ 4 rows in setQuery the
DBA_OB_TABLET_TO_LSview to obtain the Tablet distribution information on the log stream.obclient(root@mysql_tenant)[oceanbase]> SELECT LS_ID, COUNT(*) AS C FROM oceanbase.DBA_OB_TABLET_TO_LS GROUP BY LS_ID;The query result is as follows:
+-------+------+ | LS_ID | C | +-------+------+ | 1 | 590 | | 1001 | 4 | | 1002 | 3 | | 1003 | 3 | +-------+------+ 4 rows in setBased on the information displayed above, select an appropriate log stream as the destination for the transfer.
Execute the following command to transfer the partition.
ALTER SYSTEM TRANSFER PARTITION TABLE_ID [=] table_id, OBJECT_ID [=] object_id TO LS ls_id;where:
table_id: the ID of the table.object_id: the unique identifier of the partition.ls_id: the ID of the destination log stream.tenant_name: the name of the tenant to which the partition belongs.
The following example shows how to transfer the
p1partition of thetbl1_ltable in thetestdatabase of themysql_tenanttenant from the current log stream1001to the log stream1003.obclient(root@mysql_tenant)[oceanbase]> ALTER SYSTEM TRANSFER PARTITION TABLE_ID = 500012, OBJECT_ID = 500014 TO LS 1003;After the Transfer Partition command is executed successfully, you can view the task status in the following views.
Query the
DBA_OB_TRANSFER_PARTITION_TASKSview to obtain theTASK_ID,TRANSFER_TASK_ID, andBALANCE_JOB_IDof the task.The
DBA_OB_TRANSFER_PARTITION_TASKSview displays the Transfer Partition tasks that are being processed in the current tenant. The following example shows how to query theDBA_OB_TRANSFER_PARTITION_TASKSview:obclient(root@mysql_tenant)[oceanbase]> SELECT TASK_ID, BALANCE_JOB_ID, TRANSFER_TASK_ID, STATUS FROM oceanbase.DBA_OB_TRANSFER_PARTITION_TASKS WHERE TABLE_ID = 500012 AND OBJECT_ID = 500014;The query result is as follows:
+---------+----------------+------------------+--------+ | TASK_ID | BALANCE_JOB_ID | TRANSFER_TASK_ID | STATUS | +---------+----------------+------------------+--------+ | 1 | 26506 | 1 | DOING | +---------+----------------+------------------+--------+ 1 row in setYou can check the
STATUScolumn in the query result to confirm the task status. You can also view the task execution progress:WAITING: indicates that the task is waiting to be scheduled.INIT: indicates that theBALANCE_JOBhas been built. You can view the execution progress of the associatedBALANCE_JOBbased on theBALANCE_JOB_ID.DOING: indicates that the task has started to transfer the partition. You can view the associated Transfer Partition task based on theTRANSFER_TASK_ID. TheTRANSFER_TASK_IDchanges frequently. A Transfer Partition task involves multiple transfers.
If the query result of the
DBA_OB_TRANSFER_PARTITION_TASKSview is empty, you can query theDBA_OB_TRANSFER_PARTITION_TASK_HISTORYview to view the task result.Query the
DBA_OB_BALANCE_JOBSorDBA_OB_BALANCE_JOB_HISTORYview based on the obtainedBALANCE_JOB_IDto confirm the execution status of the associatedBALANCE_JOB.The
DBA_OB_BALANCE_JOBSview displays the load balancing tasks that are being executed in the current tenant. At a time, only one load balancing task (BALANCE_JOB) is executed in a tenant. Each load balancing task generates multiple load balancing subtasks (TRANSFER_TASK). TheDBA_OB_BALANCE_JOB_HISTORYview displays the history of load balancing tasks that have been executed in the current tenant. The following example shows how to query theDBA_OB_BALANCE_JOBSandDBA_OB_BALANCE_JOB_HISTORYviews:obclient [oceanbase]> SELECT * FROM oceanbase.DBA_OB_BALANCE_JOBS WHERE JOB_ID = 26506; obclient(root@mysql_tenant)[oceanbase]>``` ```shell obclient(root@mysql_tenant)[oceanbase]> SELECT * FROM oceanbase.DBA_OB_BALANCE_JOB_HISTORY WHERE JOB_ID = 26506;In the preceding example,
26506must be replaced with theBALANCE_JOB_IDobtained in the previous step.The
STATUScolumn in the query result displays the execution status of theBALANCE_JOB:DOING: indicates that the load balancing task is being executed.COMPLETED: indicates that the load balancing task is completed.CANCELING: indicates that the load balancing task is being canceled.CANCELED: indicates that the load balancing task has been canceled.
Query the
DBA_OB_TRANSFER_TASKSorDBA_OB_TRANSFER_TASK_HISTORYview based on the obtainedTRANSFER_TASK_IDto confirm the execution status of the associatedTRANSFER_TASK.The
DBA_OB_TRANSFER_TASKSview displays the load balancing subtasks that are being executed in the current tenant. At a time, multiple load balancing subtasks (TRANSFER_TASK) can be executed. These subtasks (TRANSFER_TASK) belong to the same load balancing task (BALANCE_JOB). TheDBA_OB_TRANSFER_TASK_HISTORYview displays the history of load balancing subtasks that have been executed in the current tenant. The following example shows how to query theDBA_OB_TRANSFER_TASKSandDBA_OB_TRANSFER_TASK_HISTORYviews:obclient(root@mysql_tenant)[oceanbase]> SELECT * FROM oceanbase.DBA_OB_TRANSFER_TASKS WHERE TASK_ID = 1;obclient(root@mysql_tenant)[oceanbase]> SELECT * FROM oceanbase.DBA_OB_TRANSFER_TASK_HISTORY WHERE TASK_ID = 1;In the preceding example,
1needs to be replaced with theTRANSFER_TASK_IDobtained in the preceding steps.The
STATUScolumn in the query result indicates the execution status of theTRANSFER_TASK:INIT: indicates that the task is being created.START: indicates that the transfer is started.DOING: indicates that the transfer is in progress.ABORTED: indicates that the transfer task has failed and has been terminated.COMPLETED: indicates that the transfer task has been completed.FAILED: indicates that the transfer task has failed.CANCELED: indicates that the transfer task has been canceled.
Query the
DBA_OB_TRANSFER_PARTITION_TASK_HISTORYview based on the obtainedTASK_IDto confirm the result of the transfer partition task.The
DBA_OB_TRANSFER_PARTITION_TASK_HISTORYview displays the history of transfer partition tasks executed in the current tenant. Here is an example of the query:obclient(root@mysql_tenant)[oceanbase]> SELECT * FROM oceanbase.DBA_OB_TRANSFER_PARTITION_TASK_HISTORY WHERE TASK_ID = 1;In the preceding example,
1needs to be replaced with theTASK_IDobtained in the preceding steps.The
STATUScolumn in the query result indicates the result of the transfer partition task:COMPLETED: indicates that the transfer partition task has been completed.FAILED: indicates that the transfer partition task has failed. You can further check the reason for the failure based on the value in theCOMMENTcolumn. The following are some common values in theCOMMENTcolumn:LS not exist or may be in DROPPING/WAIT_OFFLINE status: the log stream at the destination may not exist, or may be in theDROPPINGorWAIT_OFFLINEstate.LS status is not NORMAL or is in BLOCK_TABLET_IN state: the log stream at the destination may not be in theNORMALstate, for example, it may be in theCREATINGorCREATEDstate, or it may be in theBLOCK_TABLET_INstate and cannot receive tablets.Table has beed dropped: the table to which the partition belongs has been dropped.Partition has beed dropped: the partition to be transferred has been dropped.Partition is already in dest LS: the partition already exists at the destination.Need retry, partition may be dropped: the partition was dropped during the transfer. The system will check whether the partition exists when the next load balancing task is generated.Need retry, partition may be dropped or be transferre: the partition does not exist at the destination during the transfer. This is because the partition was dropped or has been transferred to the destination. The system will check whether the partition exists or whether a new transfer task needs to be generated when the next load balancing task is generated.
After the transfer partition task is completed, check the information of the corresponding partition again.
obclient(root@mysql_tenant)[oceanbase]> SELECT TABLE_ID AS TABLE_ID, OBJECT_ID, TABLET_ID, LS_ID FROM oceanbase.DBA_OB_TABLE_LOCATIONS WHERE DATABASE_NAME = 'test' AND TABLE_NAME= 'tbl1_l' AND PARTITION_NAME = 'p1' LIMIT 1;The query result is as follows:
+----------+-----------+-----------+-------+ | TABLE_ID | OBJECT_ID | TABLET_ID | LS_ID | +----------+-----------+-----------+-------+ | 500012 | 500014 | 200009 | 1003 | +----------+-----------+-----------+-------+ 1 row in setThe result indicates that the
p1partition of thetbl1_ltable in thetestdatabase has been transferred from the1001log stream to the1003log stream. The transfer partition operation is successful.
This topic uses the oracle_tenant tenant as an example to describe the procedure.
Connect to the database as the tenant administrator of the Oracle mode tenant.
Here is an example of the connection command. Please replace the parameters with those in your environment.
obclient -h10.xx.xx.xx -P2883 -usys@oracle_tenant#obdemo -p***** -ACheck the partition information.
Query the
DBA_OB_TABLE_LOCATIONSview to obtain theTABLE_ID,OBJECT_ID, andLS_IDof the specified partition.Obtain the
TABLE_ID,OBJECT_ID, andLS_IDof a non-partitioned tableAssume that a non-partitioned table named
T1exists in theoracle_tenanttenant. Here is an example of the query:obclient(sys@oracle_tenant)[SYS]> SELECT TABLE_ID AS TABLE_ID, OBJECT_ID, TABLET_ID, LS_ID FROM SYS.DBA_OB_TABLE_LOCATIONS WHERE DATABASE_NAME = 'SYS' AND TABLE_NAME= 'T1' AND ROWNUM = 1;The query result is as follows:
+----------+-----------+-----------+-------+ | TABLE_ID | OBJECT_ID | TABLET_ID | LS_ID | +----------+-----------+-----------+-------+ | 500002 | 500002 | 200001 | 1001 | +----------+-----------+-----------+-------+ 1 row in setObtain the
TABLE_ID,OBJECT_ID, andLS_IDof a partitioned tableFor a partitioned table, you only need to specify the name of the partition. Here is an example:
Assume that a partitioned table named
TBL1_LOG_Rexists in theoracle_tenanttenant.obclient(sys@oracle_tenant)[SYS]> CREATE TABLE tbl1_log_r(log_id INT,log_date DATE NOT NULL DEFAULT SYSDATE) PARTITION BY RANGE(log_date) (PARTITION M202001 VALUES LESS THAN(TO_DATE('2020/02/01','YYYY/MM/DD')) , PARTITION M202002 VALUES LESS THAN(TO_DATE('2020/03/01','YYYY/MM/DD')) , PARTITION M202003 VALUES LESS THAN(TO_DATE('2020/04/01','YYYY/MM/DD')) , PARTITION M202004 VALUES LESS THAN(TO_DATE('2020/05/01','YYYY/MM/DD')) , PARTITION M202005 VALUES LESS THAN(TO_DATE('2020/06/01','YYYY/MM/DD')) , PARTITION M202006 VALUES LESS THAN(TO_DATE('2020/07/01','YYYY/MM/DD')) , PARTITION M202007 VALUES LESS THAN(TO_DATE('2020/08/01','YYYY/MM/DD')) , PARTITION M202008 VALUES LESS THAN(TO_DATE('2020/09/01','YYYY/MM/DD')) , PARTITION M202009 VALUES LESS THAN(TO_DATE('2020/10/01','YYYY/MM/DD')) , PARTITION M202010 VALUES LESS THAN(TO_DATE('2020/11/01','YYYY/MM/DD')) , PARTITION M202011 VALUES LESS THAN(TO_DATE('2020/12/01','YYYY/MM/DD')) , PARTITION M202012 VALUES LESS THAN(TO_DATE('2021/01/01','YYYY/MM/DD')) , PARTITION MMAX VALUES LESS THAN (MAXVALUE) );Here is an example of the query for the
M202005partition of theTBL1_LOG_Rtable:obclient(sys@oracle_tenant)[SYS]> SELECT TABLE_ID AS TABLE_ID, OBJECT_ID, TABLET_ID, LS_ID FROM SYS.DBA_OB_TABLE_LOCATIONS WHERE DATABASE_NAME = 'SYS' AND TABLE_NAME= 'TBL1_LOG_R' AND PARTITION_NAME = 'M202005' AND ROWNUM = 1;The query result is as follows:
+----------+-----------+-----------+-------+ | TABLE_ID | OBJECT_ID | TABLET_ID | LS_ID | +----------+-----------+-----------+-------+ | 500003 | 500009 | 200006 | 1002 | +----------+-----------+-----------+-------+ 1 row in setObtain the
TABLE_ID,OBJECT_ID, andLS_IDof a subpartitioned tableFor a subpartitioned table, you need to specify the names of the partition and subpartition.
Assume that a subpartitioned table named
T2_F_RLexists in theoracle_tenanttenant.obclient(sys@oracle_tenant)[SYS]> CREATE TABLE t2_f_rl(col1 INT,col2 VARCHAR2(50)) PARTITION BY RANGE(col1) SUBPARTITION BY LIST(col2) (PARTITION p0 VALUES LESS THAN(100) (SUBPARTITION sp0 VALUES('01'), SUBPARTITION sp1 VALUES('02') ), PARTITION p1 VALUES LESS THAN(200) (SUBPARTITION sp2 VALUES('01'), SUBPARTITION sp3 VALUES('02'), SUBPARTITION sp4 VALUES('03') ) );Here is an example of the query for the
SP2subpartition of theT2_F_RLtable:obclient(sys@oracle_tenant)[SYS]> SELECT TABLE_ID AS TABLE_ID, OBJECT_ID, TABLET_ID, LS_ID FROM SYS.DBA_OB_TABLE_LOCATIONS WHERE DATABASE_NAME = 'SYS' AND TABLE_NAME= 'T2_F_RL' AND PARTITION_NAME = 'P1' AND SUBPARTITION_NAME = 'SP2' AND ROWNUM = 1;The query result is as follows:
+----------+-----------+-----------+-------+ | TABLE_ID | OBJECT_ID | TABLET_ID | LS_ID | +----------+-----------+-----------+-------+ | 500018 | 500023 | 200017 | 1003 | +----------+-----------+-----------+-------+ 1 row in set
Select a log stream as the destination for the transfer.
Query the
DBA_OB_LSview to obtain the status and information of the log streams of the tenant.obclient(sys@oracle_tenant)[SYS]> SELECT * FROM SYS.DBA_OB_LS;The query result is as follows:
+-----------+-------+--------+--------------+---------------+-------------+---------------------+----------+---------------------+---------------------+------+-----------+ | TENANT_ID | LS_ID | STATUS | PRIMARY_ZONE | UNIT_GROUP_ID | LS_GROUP_ID | CREATE_SCN | DROP_SCN | SYNC_SCN | READABLE_SCN | FLAG | UNIT_LIST | +-----------+-------+--------+--------------+---------------+-------------+---------------------+----------+---------------------+---------------------+------+-----------+ | 1006 | 1 | NORMAL | zone1 | 0 | 0 | NULL | NULL | 1701244663685197789 | 1701244663685197789 | | | | 1006 | 1001 | NORMAL | zone1 | 0 | 1001 | 1701239786827662637 | NULL | 1701244663685197789 | 1701244663685197789 | | 1001 | | 1006 | 1002 | NORMAL | zone1 | 0 | 1002 | 1701239786831568305 | NULL | 1701244664066906860 | 1701244664066906859 | | 1002 | | 1006 | 1003 | NORMAL | zone1 | 0 | 1003 | 1701239786834300282 | NULL | 1701244664175263949 | 1701244664175263948 | | 1003 | +-----------+-------+--------+--------------+---------------+-------------+---------------------+----------+---------------------+---------------------+------+-----------+ 4 rows in setQuery the
DBA_OB_TABLET_TO_LSview to obtain the distribution of tablets on the log streams.obclient(sys@oracle_tenant)[SYS]> SELECT LS_ID, COUNT(*) AS C FROM SYS.DBA_OB_TABLET_TO_LS GROUP BY LS_ID;The query result is as follows:
+-------+------+ | LS_ID | C | +-------+------+ | 1 | 578 | | 1001 | 7 | | 1002 | 5 | | 1003 | 7 | +-------+------+ 4 rows in setSelect an appropriate log stream as the destination for the transfer based on the information displayed in the preceding query results.
Execute the following command to perform the transfer partition operation.
ALTER SYSTEM TRANSFER PARTITION TABLE_ID [=] table_id, OBJECT_ID [=] object_id TO LS ls_id;where:
table_id: the ID of the table.object_id: the unique identifier of the partition.ls_id: the ID of the log stream at the destination.tenant_name: the name of the tenant to which the partition belongs.
The following example shows how to transfer the
M202005partition of theTBL1_LOG_Rtable in theSYSdatabase of theoracle_tenanttenant from the current log stream1002to log stream1003.obclient [SYS]> ALTER SYSTEM TRANSFER PARTITION TABLE_ID = 500003, OBJECT_ID = 500009 TO LS 1003;After the Transfer Partition command is executed, you can view the task status by querying the following views.
Query the
DBA_OB_TRANSFER_PARTITION_TASKSview to obtain theTASK_ID,TRANSFER_TASK_ID, andBALANCE_JOB_IDof the task.The
DBA_OB_TRANSFER_PARTITION_TASKSview displays the Transfer Partition tasks being processed in the current tenant. The query example is as follows:obclient(sys@oracle_tenant)[SYS]> SELECT TASK_ID, BALANCE_JOB_ID, TRANSFER_TASK_ID, STATUS FROM SYS.DBA_OB_TRANSFER_PARTITION_TASKS WHERE TABLE_ID = 500003 AND OBJECT_ID = 500009;The query result is as follows:
+---------+----------------+------------------+--------+ | TASK_ID | BALANCE_JOB_ID | TRANSFER_TASK_ID | STATUS | +---------+----------------+------------------+--------+ | 1 | 17304 | 1 | DOING | +---------+----------------+------------------+--------+ 1 row in setYou can view the task status based on the value of the
STATUScolumn in the query result. The following table describes the values of theSTATUScolumn.WAITING: indicates that the task is waiting to be scheduled.INIT: indicates that theBALANCE_JOBof the task is created. You can view the execution progress of theBALANCE_JOBbased on theBALANCE_JOB_ID.DOING: indicates that the task is being executed. You can view the execution progress of the Transfer Partition task based on theTRANSFER_TASK_ID. TheTRANSFER_TASK_IDchanges frequently. A Transfer Partition task may involve multiple Transfers.
If the query result of the
DBA_OB_TRANSFER_PARTITION_TASKSview is empty, you can query theDBA_OB_TRANSFER_PARTITION_TASK_HISTORYview to view the task result.Query the
DBA_OB_BALANCE_JOBSorDBA_OB_BALANCE_JOB_HISTORYview based on the obtainedBALANCE_JOB_IDto view the execution status of theBALANCE_JOB.The
DBA_OB_BALANCE_JOBSview displays the load balancing jobs being executed in the current tenant. Only one load balancing job (BALANCE_JOB) is executed in a tenant at a time. Each load balancing job generates multiple load balancing tasks (TRANSFER_TASK). TheDBA_OB_BALANCE_JOB_HISTORYview displays the history of load balancing jobs executed in the current tenant. The query examples are as follows:obclient(sys@oracle_tenant)[SYS]> SELECT * FROM SYS.DBA_OB_BALANCE_JOBS WHERE JOB_ID = 17304;obclient(sys@oracle_tenant)[SYS]> SELECT * FROM SYS.DBA_OB_BALANCE_JOB_HISTORY WHERE JOB_ID = 17304;In the preceding examples,
17304must be replaced with theBALANCE_JOB_IDobtained in the previous step.The
STATUScolumn in the query result indicates the execution status of theBALANCE_JOB. The following table describes the values of theSTATUScolumn.DOING: indicates that the load balancing job is being executed.COMPLETED: indicates that the load balancing job is executed.CANCELING: indicates that the load balancing job is being canceled.CANCELED: indicates that the load balancing job is canceled.
Query the
DBA_OB_TRANSFER_TASKSorDBA_OB_TRANSFER_TASK_HISTORYview based on the obtainedTRANSFER_TASK_IDto view the execution status of theTRANSFER_TASK.The
DBA_OB_TRANSFER_TASKSview displays the load balancing tasks being executed in the current tenant. Multiple load balancing tasks (TRANSFER_TASK) can be executed in a tenant at a time. These tasks (TRANSFER_TASK) belong to the same load balancing job (BALANCE_JOB). TheDBA_OB_TRANSFER_TASK_HISTORYview displays the history of load balancing tasks executed in the current tenant. The query examples are as follows:obclient(sys@oracle_tenant)[SYS]> SELECT * FROM SYS.DBA_OB_TRANSFER_TASKS WHERE TASK_ID = 1;obclient(sys@oracle_tenant)[SYS]> SELECT * FROM SYS.DBA_OB_TRANSFER_TASK_HISTORY WHERE TASK_ID = 1;In the preceding examples,
1must be replaced with theTRANSFER_TASK_IDobtained in the previous step.The
STATUScolumn in the query result indicates the execution status of theTRANSFER_TASK. The following table describes the values of theSTATUScolumn.INIT: indicates that the task is being created.START: indicates that the Transfer is being executed.DOING: indicates that the Transfer is being executed.ABORTED: indicates that the Transfer task is terminated due to failure.COMPLETED: indicates that the Transfer task is executed.FAILED: indicates that the Transfer task is failed.CANCELED: indicates that the Transfer task is canceled.
Query the
DBA_OB_TRANSFER_PARTITION_TASK_HISTORYview based on the obtainedTASK_IDto view the result of the Transfer Partition task.The
DBA_OB_TRANSFER_PARTITION_TASK_HISTORYview displays the history of Transfer Partition tasks executed in the current tenant. The query example is as follows:obclient(sys@oracle_tenant)[SYS]> SELECT * FROM SYS.DBA_OB_TRANSFER_PARTITION_TASK_HISTORY WHERE TASK_ID = 1;In the preceding example,
1must be replaced with theTASK_IDobtained in the previous step.The
STATUScolumn in the query result indicates the result of the Transfer Partition task. The following table describes the values of theSTATUScolumn.COMPLETED: indicates that the Transfer Partition task is executed.FAILED: indicates that the Transfer Partition task is failed. You can view the reason for the failure in theCOMMENTcolumn. The following table describes the common values of theCOMMENTcolumn.LS not exist or may be in DROPPING/WAIT_OFFLINE status: indicates that the log stream at the destination may not exist or may be in theDROPPINGorWAITOFFLINEstate.LS status is not NORMAL or is in BLOCK_TABLET_IN state: indicates that the log stream at the destination is not in theNORMALstate. For example, the log stream may be in theCREATINGorCREATEDstate, or the log stream is blocked byBLOCK_TABLET_INand cannot be migrated into.Table has beed dropped: indicates that the table to which the partition belongs is dropped.Partition has beed dropped: indicates that the partition is dropped.Partition is already in dest LS: indicates that the partition already exists at the destination.Need retry, partition may be dropped: indicates that the partition is dropped during the Transfer. The system will recheck whether the partition exists when a new load balancing task is generated.Need retry, partition may be dropped or be transferre: indicates that the partition does not exist at the destination during the Transfer. The partition may be dropped, or the partition is no longer in the source log stream. The system will recheck whether the partition exists or whether a new Transfer task needs to be generated when a new load balancing task is generated.
After the Transfer Partition task is successfully executed, check the partition information again.
obclient(sys@oracle_tenant)[SYS]> SELECT TABLE_ID AS TABLE_ID, OBJECT_ID, TABLET_ID, LS_ID FROM SYS.DBA_OB_TABLE_LOCATIONS WHERE DATABASE_NAME = 'SYS' AND TABLE_NAME= 'T2_F_RL' AND PARTITION_NAME = 'P1' AND SUBPARTITION_NAME = 'SP2' AND ROWNUM = 1;The query result is as follows:
+----------+-----------+-----------+-------+ | TABLE_ID | OBJECT_ID | TABLET_ID | LS_ID | +----------+-----------+-----------+-------+ | 500003 | 500009 | 200006 | 1003 | +----------+-----------+-----------+-------+ 1 row in setThe result indicates that the
M202005partition of theTBL1_LOG_Rtable in theSYSdatabase has been successfully migrated from log stream1002to log stream1003.
