You can scale in and out the resources of a tenant by modifying the UNIT_NUM parameter for a resource pool. This parameter specifies the number of resource units.
Prerequisites
Before you perform a scale-in or scale-out operation on a tenant, you must perform the following steps:
If the tenant is deleted, delete the resource pool of the tenant to release resources. Resources in an idle resource pool are also considered occupied resources.
For more information about how to delete a resource pool, see Delete a resource pool.
Perform a round of minor compaction to release the occupied memory resources.
For more information about how to manually trigger a minor compaction, see Manually trigger a minor compaction.
View the allocation of resources in the cluster to understand resource usage.
For more information about how to view the total amount of resources and the resource allocation on OBServer nodes, see View the resource information about a cluster.
You can modify the UNIT_NUM parameter by executing SQL statements or using OceanBase Cloud Platform (OCP).
Notice
The modified value of the UNIT_NUM parameter must not be greater than the number of OBServer nodes available in each zone.
Modify the UNIT_NUM parameter of a tenant by using SQL statements
You can increase or decrease the value of the UNIT_NUM parameter to scale out or in the resources of a tenant.
Background
Assume that you have a cluster that has three zones, which are z1, z2, and z3, and each zone has three OBServer nodes. The cluster has a user tenant named tenant1. The following code shows the resource distribution of the tenant:
obclient> CREATE RESOURCE UNIT unit1 MAX_CPU 6,MIN_CPU 6, MAX_MEMORY '36G', MIN_MEMORY '36G', MAX_IOPS 128, MIN_IOPS 128, MAX_DISK_SIZE '2T', MAX_SESSION_NUM 64;
obclient> CREATE RESOURCE POOL pool1 UNIT 'unit1', UNIT_NUM 2, ZONE_LIST ('z1','z2','z3');
obclient>CREATE TENANT tenant1 resource_pool_list=('pool1');
Increase the value of the UNIT_NUM parameter
As the business volume grows, the deployment mode of two resource units in each zone cannot meet the business requirements. Therefore, you need to increase the value of UNIT_NUM to improve the business capabilities of a tenant.
Log on to the
systenant as therootuser.Access the database named
oceanbase.obclient>USE oceanbase;Query the
oceanbase.gv$unitview to obtain the resource allocation information of the current tenant.obclient> SELECT * FROM oceanbase.gv$unit;For more information about fields in the
gv$unitview, see gv$unit.Execute the following statement to increase the value of
UNIT_NUM.Note
You are not allowed to increase the value of
UNIT_NUMwith a specifiedunit_idvalue.obclient>ALTER RESOURCE POOL pool1 UNIT_NUM = 3;After the statement is executed, the system adds a resource unit to each zone.
Decrease the value of the UNIT_NUM parameter
After the value of UNIT_NUM is decreased, a specific number of resource units are deleted. A deleted resource unit may contain the data of the corresponding tenant. Therefore, after the resource unit deletion statement is executed, the system needs to migrate the tenant data from the deleted resource units. 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 UNIT_NUM is decreased, each resource unit to be deleted is marked as DELETING. You can query the status column of the _all_unit table to check the status of resource units. After the tenant data is migrated from the deleted resource units, OceanBase Database updates the __all_rootservice_job table to complete the current deletion job and removes the resource units marked as DELETING from the _all_unit table.
Procedure:
Log on to the
systenant as therootuser.Access the database named
oceanbase.obclient>USE oceanbase;Query the
oceanbase.gv$unitview to obtain the resource allocation information of the current tenant.obclient> SELECT * FROM oceanbase.gv$unit;Execute the following statement to decrease the value of
UNIT_NUM.Decrease the value of
UNIT_NUMwithout a specifiedunit_idvalueobclient>ALTER RESOURCE POOL pool1 UNIT_NUM = 1;After the statement is executed, the system automatically deletes a resource unit from each zone.
Decrease the value of
UNIT_NUMwith one or more specifiedunit_idvaluesIn the following statement,
1001,1003, and1005are theIDsof the resource units to be deleted.obclient> ALTER RESOURCE POOL pool1 UNIT_NUM 1 DELETE UNIT = (1001, 1003,1005);After the statement is executed, the system deletes the specified resource units.
Change the number of resource units of a tenant in OCP
You can change the number of resource units in the resource pool of a tenant in OCP. This operation is equivalent to modifying the UNIT_NUM parameter.
Log on to the OCP console.
In the left-side navigation pane, click Tenants.
In the Tenants section, find the tenant whose resource configurations you want to view and click the tenant name.
In the Replica Details section of the Overview page, find the zone for which you want to change the number of resource units and click Edit in the Actions column.
In the Number of Units column, increase or decrease the number of resource units.
Click OK.
More information
During resource scaling for tenants, you can obtain resource information about the tenants in one of the following ways:
Use the
oceanbase__all_unit_configinternal tableThe
oceanbase.__all_unit_configinternal table records all unit_config settings in the current cluster.Example:
obclient> SELECT * FROM oceanbase.__all_unit_config; +----------------------------+----------------------------+----------------+-----------------------------+---------+---------+-------------+-------------+----------+----------+---------------+---------------------+ | gmt_create | gmt_modified | unit_config_id | name | max_cpu | min_cpu | max_memory | min_memory | max_iops | min_iops | max_disk_size | max_session_num | +----------------------------+----------------------------+----------------+-----------------------------+---------+---------+-------------+-------------+----------+----------+---------------+---------------------+ | 2021-11-11 14:29:24.847092 | 2021-11-11 14:29:24.847092 | 1 | sys_unit_config | 5 | 2.5 | 16106127360 | 12884901888 | 10000 | 5000 | 179593805824 | 9223372036854775807 | | 2021-11-11 14:43:01.449090 | 2021-11-11 14:43:01.449090 | 1002 | config_Oracle_zone1_S1_rhf | 1.5 | 1.5 | 6442450944 | 6442450944 | 1250 | 1250 | 536870912000 | 375 | | 2021-11-15 11:25:48.371781 | 2021-11-15 11:25:48.371781 | 1003 | config_MySQL_zone1_S1_zlz | 1.5 | 1.5 | 6442450944 | 6442450944 | 1250 | 1250 | 536870912000 | 375 | | 2021-11-15 11:26:38.979746 | 2021-11-15 11:26:38.979746 | 1004 | config_MySQL1_zone1_S1_cey | 1.5 | 1.5 | 6442450944 | 6442450944 | 1250 | 1250 | 536870912000 | 375 | | 2021-11-15 11:27:09.347510 | 2021-11-15 11:27:09.347510 | 1005 | config_MySQL2_zone1_S1_ydf | 1.5 | 1.5 | 6442450944 | 6442450944 | 1250 | 1250 | 536870912000 | 375 | | 2021-11-15 11:27:42.442706 | 2021-11-15 11:27:42.442706 | 1006 | config_Oracle1_zone1_S1_dfl | 1.5 | 1.5 | 6442450944 | 6442450944 | 1250 | 1250 | 536870912000 | 375 | | 2021-11-17 14:29:09.458317 | 2021-11-17 14:29:09.458317 | 1022 | unit1 | 5 | 5 | 38654705664 | 34359738368 | 128 | 128 | 2199023255552 | 64 | +----------------------------+----------------------------+----------------+-----------------------------+---------+---------+-------------+-------------+----------+----------+---------------+---------------------+ 7 rows in setUse the
gv$unitviewThe
gv$unitview records the resource allocation of all tenants in the current cluster.Example:
obclient> SELECT * FROM oceanbase.gv$unit; +---------+----------------+-----------------------------+------------------+------------------------+-------+-----------+-------------+----------------+----------+---------------------+-----------------------+---------+---------+-------------+-------------+----------+----------+---------------+---------------------+ | unit_id | unit_config_id | unit_config_name | resource_pool_id | resource_pool_name | zone | tenant_id | tenant_name | svr_ip | svr_port | migrate_from_svr_ip | migrate_from_svr_port | max_cpu | min_cpu | max_memory | min_memory | max_iops | min_iops | max_disk_size | max_session_num | +---------+----------------+-----------------------------+------------------+------------------------+-------+-----------+-------------+----------------+----------+---------------------+-----------------------+---------+---------+-------------+-------------+----------+----------+---------------+---------------------+ | 1 | 1 | sys_unit_config | 1 | sys_pool | zone1 | 1 | sys | xx.xx.xx.xx | 2882 | | 0 | 5 | 2.5 | 16106127360 | 12884901888 | 10000 | 5000 | 179593805824 | 9223372036854775807 | | 1002 | 1002 | config_Oracle_zone1_S1_rhf | 1002 | pool_Oracle_zone1_rhf | zone1 | 1002 | Oracle | xx.xx.xx.xx | 2882 | | 0 | 1.5 | 1.5 | 6442450944 | 6442450944 | 1250 | 1250 | 536870912000 | 375 | | 1003 | 1003 | config_MySQL_zone1_S1_zlz | 1003 | pool_MySQL_zone1_zlz | zone1 | 1003 | MySQL | xx.xx.xx.xx | 2882 | | 0 | 1.5 | 1.5 | 6442450944 | 6442450944 | 1250 | 1250 | 536870912000 | 375 | | 1004 | 1004 | config_MySQL1_zone1_S1_cey | 1004 | pool_MySQL1_zone1_cey | zone1 | 1004 | MySQL1 | xx.xx.xx.xx | 2882 | | 0 | 1.5 | 1.5 | 6442450944 | 6442450944 | 1250 | 1250 | 536870912000 | 375 | | 1005 | 1005 | config_MySQL2_zone1_S1_ydf | 1005 | pool_MySQL2_zone1_ydf | zone1 | 1005 | MySQL2 | xx.xx.xx.xx | 2882 | | 0 | 1.5 | 1.5 | 6442450944 | 6442450944 | 1250 | 1250 | 536870912000 | 375 | | 1006 | 1006 | config_Oracle1_zone1_S1_dfl | 1006 | pool_Oracle1_zone1_dfl | zone1 | 1006 | Oracle1 | xx.xx.xx.xx | 2882 | | 0 | 1.5 | 1.5 | 6442450944 | 6442450944 | 1250 | 1250 | 536870912000 | 375 | +---------+----------------+-----------------------------+------------------+------------------------+-------+-----------+-------------+----------------+----------+---------------------+-----------------------+---------+---------+-------------+-------------+----------+----------+---------------+---------------------+Use the
oceanbase__all_resource_poolinternal tableThe
oceanbase__all_resource_poolinternal table records the resource configurations of all resource pools in the current cluster.unit_countindicates the number of resource units in the resource pool.Example:
obclient> SELECT * FROM oceanbase.__all_resource_pool; +----------------------------+----------------------------+------------------+------------------------+------------+----------------+-------------+-----------+--------------+--------------------+ | gmt_create | gmt_modified | resource_pool_id | name | unit_count | unit_config_id | zone_list | tenant_id | replica_type | is_tenant_sys_pool | +----------------------------+----------------------------+------------------+------------------------+------------+----------------+-------------+-----------+--------------+--------------------+ | 2021-11-11 14:29:24.849909 | 2021-11-11 14:29:24.854242 | 1 | sys_pool | 1 | 1 | zone1 | 1 | 0 | 0 | | 2021-11-11 14:43:01.455415 | 2021-11-11 14:43:01.466884 | 1002 | pool_Oracle_zone1_rhf | 1 | 1002 | zone1 | 1002 | 0 | 0 | | 2021-11-15 11:25:48.384105 | 2021-11-15 11:25:48.406186 | 1003 | pool_MySQL_zone1_zlz | 1 | 1003 | zone1 | 1003 | 0 | 0 | | 2021-11-15 11:26:38.986014 | 2021-11-15 11:26:38.997594 | 1004 | pool_MySQL1_zone1_cey | 1 | 1004 | zone1 | 1004 | 0 | 0 | | 2021-11-15 11:27:42.454288 | 2021-11-15 11:27:42.467915 | 1006 | pool_Oracle1_zone1_dfl | 1 | 1006 | zone1 | 1006 | 0 | 0 | | 2021-11-17 14:38:03.945051 | 2021-11-17 14:38:03.945051 | 1022 | zyc_1117 | 1 | 1023 | zone1;zone2 | -1 | 0 | 0 | +----------------------------+----------------------------+------------------+------------------------+------------+----------------+-------------+-----------+--------------+--------------------+ 6 rows in set