Purpose
This statement is used by the system tenant to initiate a major compaction or minor compaction (freezing). Manual major compaction supports tenant-level, table-level, and partition-level operations; manual minor compaction supports tenant-level, zone-level, server-level, log stream-level, and partition-level operations.
Syntax
ALTER SYSTEM merge_action;
merge_action:
MAJOR FREEZE [tenant_list]
| MAJOR FREEZE TENANT [=] tenant_name {TABLE_ID = table_id | TABLET_ID = tablet_id}
| MINOR FREEZE [tenant_list | server_list | zone_list]
| MINOR FREEZE TENANT [=] tenant_name [LS [=] ls_id] [TABLET_ID = tablet_id]
| {SUSPEND | RESUME} MERGE [tenant_list]
| CLEAR MERGE ERROR [tenant_list]
tenant_list:
TENANT [=] { all | all_user | all_meta } | tenant_name [, tenant_name ...]
server_list:
SERVER [=] ('ip:port' [, 'ip:port'...])
zone_list:
ZONE [=] ('zone_name' [, 'zone_name' ...])
Parameters
Parameters |
Description |
|---|---|
| MAJOR FREEZE | Initiate a major compaction. Use TENANT=all or TENANT=all_user All user tenants (excluding the system tenant and Meta tenant) can be merged. It is recommended that users use all_user, all will be deprecated in the future; use TENANT=all_meta You can merge all Meta tenants, or use TENANT=tenant_name [, tenant_name ...] Only merges the specified tenant. |
| MINOR FREEZE | Initiates a minor compaction. |
| {SUSPEND \ | RESUME} MERGE | Pause or resume a major compaction. Use TENANT=all or TENANT=all_user You can pause or resume major compactions for all tenants (excluding the sys tenant and meta tenant). It is recommended that you use all_user, all Will be deprecated in the future; use TENANT=all_meta You can pause or resume all Meta tenants; you can also use TENANT=tenant_name [, tenant_name ...] Pause or resume major compaction only for the specified tenant. |
| CLEAR MERGE ERROR | Clean up the bad merge markers. Use TENANT=all or TENANT=all_user You can clear the error flags for all tenants (excluding the system tenant and the Meta tenant). It is recommended that users use all_user, all will be deprecated in the future; use TENANT=all_meta You can clean up and merge all Meta tenants; you can also use TENANT=tenant_name [, tenant_name ...] Clears the error flag only for major compactions of the specified tenant. |
| tenant_name | Specify the tenant for major compaction or minor compaction. |
| TABLE_ID | Specify table major compaction. |
| TABLET_ID | Specify the partition for major compaction or minor compaction. |
| SERVER | Specify the server for minor compaction. |
| ZONE | Specify the ZONE for minor compaction. |
| LS | Specify the log rotation storage. |
Considerations
Partitions and tablets have a one-to-one correspondence. When performing partition-level compaction, note the following:
- A partition-level major compaction cannot be initiated if a tenant-level major compaction is in progress for the corresponding partition.
- Partition-level compaction cannot be initiated when the corresponding partition is undergoing an adaptive-compaction major compaction task.
- Partition-level compaction cannot be initiated when multiple replicas of the corresponding partition are in an inconsistent state.
- Partition-level compaction cannot be initiated when the corresponding partition is in the recovery or transfer state.
- When a major compaction task is paused, partition-level major compactions are not allowed.
- Partition-level compaction essentially performs major compaction tasks on multiple replicas of the same partition, which consumes CPU and disk I/O. Before performing a partition-level compaction operation, you need to consider the current resource usage of the tenant. After the partition-level compaction command is successfully executed, CPU and I/O usage will increase.
Examples
Example of storage layer compaction
The system tenant initiates a major compaction for itself.
obclient> ALTER SYSTEM MAJOR FREEZE;The system tenant initiates major compactions for all user tenants (excluding the system tenant and the Meta tenant).
obclient> ALTER SYSTEM MAJOR FREEZE TENANT = all_user;The system tenant initiates major compactions for all Meta tenants.
obclient> ALTER SYSTEM MAJOR FREEZE TENANT = all_meta;The system tenant initiates a major compaction for tenants
tenant1andtenant2.obclient> ALTER SYSTEM MAJOR FREEZE TENANT = tenant1,tenant2;
Example of storage layer minor compaction
The system tenant initiates a minor compaction for itself.
obclient> ALTER SYSTEM MINOR FREEZE;The system tenant initiates minor or major compactions for all user tenants (excluding the system tenant and the Meta tenant).
obclient> ALTER SYSTEM MINOR FREEZE TENANT = all_user;The system tenant initiates minor compactions for all meta tenants.
obclient> ALTER SYSTEM MINOR FREEZE TENANT = all_meta;The system tenant initiates a minor compaction for tenants
tenant1andtenant2.obclient> ALTER SYSTEM MINOR FREEZE TENANT = tenant1,tenant2;The system tenant performs a minor compaction on the specified partition under the specified tenant
tenant1.obclient> ALTER SYSTEM MINOR FREEZE tenant = tenant1 tablet_id = 1100611139453887;The system tenant performs a minor compaction on the specified OBServer.
obclient> ALTER SYSTEM MINOR FREEZE SERVER = ('10.XXX.XXX.XXX:2882');The system tenant to the specified log shipping of a specified tenant.
obclient> ALTER SYSTEM MINOR FREEZE tenant = tenant1 LS 1;The system tenant performs a minor compaction on a specified partition in a specified log stream of a specified tenant.
obclient> ALTER SYSTEM MINOR FREEZE tenant = tenant1 ls 1 tablet_id = 60000;
Example of stopping or resuming a major compaction
The system tenant suspends major compactions for all user tenants (excluding the system tenant and the Meta tenant).
obclient> ALTER SYSTEM SUSPEND MERGE TENANT = all_user;The system tenant suspends major compaction for the specified tenants
tenant1andtenant2.obclient> ALTER SYSTEM SUSPEND MERGE TENANT = tenant1,tenant2;The system tenant pauses major compactions for all meta tenants.
obclient> ALTER SYSTEM SUSPEND MERGE TENANT = all_meta;The system tenant restores the major compactions of all user tenants (excluding the system tenant and the Meta tenant).
obclient> ALTER SYSTEM RESUME MERGE TENANT = all_user;The system tenant restores the major compactions of specified tenants
tenant1andtenant2.obclient> ALTER SYSTEM RESUME MERGE TENANT = tenant1,tenant2;The system tenant restores the major compactions for all Meta tenants.
obclient> ALTER SYSTEM RESUME MERGE TENANT = all_meta;
Example of cleaning up major compaction error flags
The system tenant clears the error flags for all user tenants (excluding the system tenant and Meta tenant).
obclient> ALTER SYSTEM CLEAR MERGE ERROR TENANT = all_user;The system tenant cleans up the error flags for major compactions of tenants
tenant1andtenant2.obclient> ALTER SYSTEM CLEAR MERGE ERROR TENANT = tenant1,tenant2;The system tenant clears the error flags for all meta tenants in a major compaction.
obclient> ALTER SYSTEM CLEAR MERGE ERROR TENANT = all_meta;
Initiate a table-level major compaction
The system tenant queries the
table_idof the table to be merged, tbl2.obclient(root@sys)[oceanbase]> SELECT a.tenant_id, b.tenant_name, a.database_name, a.table_id, a.table_name FROM oceanbase.CDB_OB_TABLE_LOCATIONS a, oceanbase.DBA_OB_TENANTS b WHERE a.tenant_id=b.tenant_id AND a.table_name = 'tbl2' AND b.tenant_name = 'mysql001';The query result is as follows:
+-----------+-------------+---------------+----------+------------+ | tenant_id | tenant_name | database_name | table_id | table_name | +-----------+-------------+---------------+----------+------------+ | 1002 | mysql001 | test | 500002 | tbl2 | +-----------+-------------+---------------+----------+------------+ 1 row in setRun the following command to initiate a table-level major compaction.
obclient(root@sys)[oceanbase]> ALTER SYSTEM MAJOR FREEZE TENANT = mysql001 TABLE_ID = 500002;
Initiate partition-level compaction
Query the TABLET ID of the table.
Example:
obclient> SELECT a.tenant_id, b.tenant_name, a.database_name, a.table_id, a.table_name, a.tablet_id, a.PARTITION_NAME, a.SUBPARTITION_NAME FROM oceanbase.CDB_OB_TABLE_LOCATIONS a, oceanbase.DBA_OB_TENANTS b WHERE a.tenant_id=b.tenant_id AND a.table_name = 'test_tbl1' AND b.tenant_name = 'mysql001';The return result is as follows:
+-----------+-------------+---------------+----------+------------+-----------+----------------+-------------------+ | tenant_id | tenant_name | database_name | table_id | table_name | tablet_id | PARTITION_NAME | SUBPARTITION_NAME | +-----------+-------------+---------------+----------+------------+-----------+----------------+-------------------+ | 1004 | mysql001 | SYS | 500011 | TEST_TBL1 | 200008 | P1 | SP0 | | 1004 | mysql001 | SYS | 500011 | TEST_TBL1 | 200009 | P1 | SP1 | | 1004 | mysql001 | SYS | 500011 | TEST_TBL1 | 200010 | P1 | SP2 | | 1004 | mysql001 | SYS | 500011 | TEST_TBL1 | 200011 | P1 | SP3 | | 1004 | mysql001 | SYS | 500011 | TEST_TBL1 | 200012 | P2 | SP4 | | 1004 | mysql001 | SYS | 500011 | TEST_TBL1 | 200013 | P2 | SP5 | | 1004 | mysql001 | SYS | 500011 | TEST_TBL1 | 200014 | P2 | SP6 | | 1004 | mysql001 | SYS | 500011 | TEST_TBL1 | 200015 | P2 | SP7 | +-----------+-------------+---------------+----------+------------+-----------+----------------+-------------------+ 8 rows in setFor more information about view columns, see oceanbase.CDB_OB_TABLE_LOCATIONS.
Initiate a major compaction.
Example:
obclient> ALTER SYSTEM MAJOR FREEZE TENANT = mysql001 TABLET_ID = 200008;
Initiate partition-level minor compaction
Query the TABLET ID of the table.
Example:
obclient> SELECT t1.tenant_id, t2.tenant_name, t1.database_name, t1.table_id, t1.table_name, t1.tablet_id, t1.PARTITION_NAME, t1.SUBPARTITION_NAME FROM oceanbase.CDB_OB_TABLE_LOCATIONS t1, oceanbase.DBA_OB_TENANTS t2 WHERE t1.tenant_id=t2.tenant_id AND t1.table_name = 'test_tbl1' AND t2.tenant_name = 'mysql001';The return result is as follows:
+-----------+-------------+---------------+----------+------------+-----------+----------------+-------------------+ | tenant_id | tenant_name | database_name | table_id | table_name | tablet_id | PARTITION_NAME | SUBPARTITION_NAME | +-----------+-------------+---------------+----------+------------+-----------+----------------+-------------------+ | 1004 | mysql001 | SYS | 500011 | TEST_TBL1 | 200008 | P1 | SP0 | | 1004 | mysql001 | SYS | 500011 | TEST_TBL1 | 200009 | P1 | SP1 | | 1004 | mysql001 | SYS | 500011 | TEST_TBL1 | 200010 | P1 | SP2 | | 1004 | mysql001 | SYS | 500011 | TEST_TBL1 | 200011 | P1 | SP3 | | 1004 | mysql001 | SYS | 500011 | TEST_TBL1 | 200012 | P2 | SP4 | | 1004 | mysql001 | SYS | 500011 | TEST_TBL1 | 200013 | P2 | SP5 | | 1004 | mysql001 | SYS | 500011 | TEST_TBL1 | 200014 | P2 | SP6 | | 1004 | mysql001 | SYS | 500011 | TEST_TBL1 | 200015 | P2 | SP7 | +-----------+-------------+---------------+----------+------------+-----------+----------------+-------------------+ 8 rows in setFor more information about view columns, see oceanbase.CDB_OB_TABLE_LOCATIONS.
Initiate a minor compaction.
Example:
obclient> ALTER SYSTEM MINOR FREEZE TENANT = mysql001 TABLET_ID = 200008;