To achieve horizontal scaling of resources under a tenant, you can modify the UNIT_NUM parameter of a resource pool for the tenant to dynamically adjust the available resources of the tenant. Specifically, you can increase or decrease the value of the UNIT_NUM parameter of a resource pool to adjust the number of resource units in each zone under a tenant. This way, you can upgrade or downgrade the service capability of the tenant in the corresponding zone.
Sample statements for modifying the UNIT_NUM parameter of a resource pool:
obclient> CREATE RESOURCE POOL rp1 UNIT 'uc1', UNIT_NUM 2, ZONE_LIST ('zone1', 'zone2');
obclient> ALTER RESOURCE POOL rp1 UNIT_NUM 3; // Increase the value of the UNIT_NUM parameter.
obclient> ALTER RESOURCE POOL rp1 UNIT_NUM 2; // Decrease the value of the UNIT_NUM parameter.
obclient> ALTER RESOURCE POOL rp1 UNIT_NUM 1 DELETE UNIT = (1001, 1003); // Decrease the value of the UNIT_NUM parameter by deleting the specified resource units.
You can increase or decrease the value of the UNIT_NUM parameter. The ALTER RESOURCE POOL rp1 UNIT_NUM 3; statement increases the value of the UNIT_NUM parameter. The ALTER RESOURCE POOL rp1 UNIT_NUM 2; and ALTER RESOURCE POOL rp1 UNIT_NUM 1 DELETE UNIT = (1001, 1003); statements decrease the value of the UNIT_NUM parameter.
Increase the value of the UNIT_NUM parameter
Typically, you need to increase the value of the UNIT_NUM parameter during resource scale-out of a tenant. The following example shows the current working status of a tenant:
obclient> CREATE RESOURCE POOL r_p0 UNIT 'uc1', UNIT_NUM 2, ZONE_LIST ('zone1', 'zone2', 'zone3');
obclient> CREATE TENANT tt RESOURCE_POOL_LIST = ('r_p0');
In this example, tenant tt uses resource pool r_p0. zone1, zone2, and zone3 each have two resource units. With increasing business growth, the two resource units in each zone cannot adapt to the current business volume. Therefore, you must increase the value of the UNIT_NUM parameter to upgrade the service capability of the tenant to meet new business requirements.
You can execute the following statement to adjust the number of resource units in resource pool r_p0 for the tenant to 3, to upgrade the service capability of the tenant:
obclient> ALTER RESOURCE POOL r_p0 UNIT_NUM = 3;
Decrease the value of the UNIT_NUM parameter
Decreasing the value of the UNIT_NUM parameter is equivalent to deleting resource units. A resource unit to be deleted may store data of the corresponding tenant. Therefore, after the statement for deleting the resource unit is executed, the system must migrate the tenant data from the deleted resource unit. Specifically, OceanBase Database records the deletion of the resource unit to the __all_rootservice_job internal table. You can query the table to check the deletion progress. After the value of the UNIT_NUM parameter is decreased, resource units to be deleted are set to the DELETING state. You can check the status of the resource units in the status column of the __all_unit table. After all tenant data is migrated from the deleted resource units, OceanBase Database updates the __all_rootservice_job table to mark completion of the deletion, and clears the __all_unit table to delete all resource units in the DELETING state.
The following examples provide more details about how to modify the UNIT_NUM parameter:
Example 1: Decrease the value of the
UNIT_NUMparameter without specifying theunit_idparameter.Create a resource pool named
test_pool. The resource pool spans three zones:z1,z2, andz3. Each zone has three resource units.obclient> CREATE RESOURCE POOL test_pool UNIT='uc', UNIT_NUM=3, ZONE_LIST=('z1','z2','z3');Execute the following statement to set the
UNIT_NUMparameter for each zone to1:obclient> ALTER RESOURCE POOL test_pool UNIT_NUM=1;In this example, the
unit_idparameter is not specified for the resource units to be deleted. Therefore, the system automatically selects two resource units from each zone and deletes them.
Example 2: Decrease the value of the
UNIT_NUMparameter with theunit_idparameter specified.Create a resource pool named
test_pool. The resource pool spans three zones:z1,z2, andz3. Each zone has three resource units.Assume that the
unit_idvalues of resource units inz1are1001,1002, and1003, theunit_idvalues of resource units inz2are1004,1005, and1006, and theunit_idvalues of resource units inz3are1007,1008, and1009.obclient>CREATE RESOURCE POOL test_pool UNIT='unit_config', UNIT_NUM=3, ZONE_LIST=('z1','z2','z3');Execute the following statement to set the
UNIT_NUMparameter for each zone to2:obclient> ALTER RESOURCE POOL test_pool UNIT_NUM=2 DELETE UNIT=(1001,1004,1007);In this example,
(1001,1004,1007)indicates the resource units to be deleted. Therefore, the system directly deletes the specified resource units.
Counter-examples for decreasing the value of the UNIT_NUM parameter:
Counter-example 1: Different numbers of resource units are to be deleted from zones when the value of the
UNIT_NUMparameter is decreased.Create a resource pool named
test_pool. The resource pool spans three zones:z1,z2, andz3. Each zone has three resource units.Assume that the
unit_idvalues of resource units inz1are1001,1002, and1003, theunit_idvalues of resource units inz2are1004,1005, and1006, and theunit_idvalues of resource units inz3are1007,1008, and1009.obclient> CREATE RESOURCE POOL test_pool UNIT='unit_config', UNIT_NUM=3, ZONE_LIST=('z1','z2','z3');Execute the following statement to delete one resource unit from each of
z1andz2and delete no resource unit fromz3:obclient> ALTER RESOURCE POOL test_pool UNIT_NUM=2 DELET UNIT=(1001,1004);Different numbers of resource units are to be deleted from the zones. Therefore, this operation is invalid, and the system returns an error.
Counter-example 2: The number of resource units to be deleted from zones does not match the value of the
UNIT_NUMparameter when the value of theUNIT_NUMparameter is decreased.Create a resource pool named
test_pool. The resource pool spans three zones:z1,z2, andz3. Each zone has three resource units.Assume that the
unit_idvalues of resource units inz1are1001,1002, and1003, theunit_idvalues of resource units inz2are1004,1005, and1006, and theunit_idvalues of resource units inz3are1007,1008, and1009.obclient> CREATE RESOURCE POOL test_pool UNIT='unit_config', UNIT_NUM=3, ZONE_LIST=('z1','z2','z3');Execute the following statement to set the
UNIT_NUMparameter to1and delete one resource unit from each ofz1,z2, andz3:obclient> ALTER RESOURCE POOL test_pool UNIT_NUM=1 DELETE UNIT=(1001,1004,1007);In this example, only one resource unit is deleted from each zone. However, the new value of the
UNIT_NUMparameter is set to 1 rather than2. The number of resource units to be deleted from the zones does not match the value variation of theUNIT_NUMparameter. Therefore, this operation is invalid, and the system returns an error.