This topic describes how to scale in a cluster by deleting zones from the cluster.
Considerations
This method applies only to a cluster with three or more zones. If a cluster has less than three zones, data consistency cannot be ensured after a zone is deleted.
Notice
After a zone is deleted, all tenants using the zone are affected. Therefore, you must properly plan ahead to avoid the impact. This topic provides an example to describe how to delete a zone when only one tenant is affected.
Prerequisites
The resources in the cluster are excessive for the current load. For information about how to view the resource details of a cluster in OceanBase Cloud Platform (OCP), see View the resource details of a cluster.
Delete zones from a cluster by using SQL statements
You can use SQL statements to delete zones from a cluster. For example, you can use this method to decrease the number of replicas from 5 to 3 for a tenant. You need to delete both zones and OBServer nodes from the relevant cluster.
Assume that the current cluster has five zones z1, z2, z3, z4, and z5, these zones are located in the same region, and that each zone has one OBServer node. The cluster has a user tenant named tenant1. The tenant information is as follows: CREATE TENANT IF NOT EXISTS tenant1 CHARSET='utf8mb4', ZONE_LIST=('z1','z2','z3','z4','z5'), PRIMARY_ZONE='z1,z2,z4', RESOURCE_POOL_LIST=('pool1'). The distribution of replicas is as follows: locality='F@z1,F@z2,F@z3,F@z4,F@z5', resource_pool_list=('pool1'). The distribution of resources in the resource pool is as follows: CREATE RESOURCE POOL pool1 UNIT 'uc1', UNIT_NUM 1, ZONE_LIST ('z1', 'z2', 'z3','z4', 'z5').
To meet business requirements, you need to reduce the number of replicas from 5 to 3 for tenant1. That is, you need to modify the locality to locality='F@z1,F@z2,F@z3. The following example describes how to delete z4 and z5, which are used only by the tenant tenant1.
Log on to the
systenant of the cluster as therootuser.Optional. If the tenant uses z4 or z5 as the primary zone, you must change the primary zone of this tenant.
obclient> ALTER TENANT tenant_name PRIMARY_ZONE='z1,z2,z3';Modify the locality of
tenant1to delete replicas in z4:Based on the locality modification rule, you can delete only one zone at a time. For more information about the locality modification rule, see Overview.
obclient>ALTER TENANT tenant1 LOCALITY='F@z1,F@z2,F@z3,F@z4'; obclient>ALTER TENANT tenant1 LOCALITY='F@z1,F@z2,F@z3';Execute the following statements to stop
z4andz5.obclient> ALTER SYSTEM STOP ZONE z4; obclient> ALTER SYSTEM STOP ZONE z5;Remove the
z4andz5zones from thepool1pool.obclient> ALTER RESOURCE POOL pool1 ZONE_LIST=('z1','z2','z3');Execute the following statement to delete the specified OBServer nodes from zones in the cluster.
Notice
In this example, only the tenant1 tenant uses the resources in z4 and z5. If other tenants also use the resources in z4 or z5, you must also perform steps 2 to 5 for these tenants.
obclient> ALTER SYSTEM DELETE SERVER 'xxx.xxx.x.xx4:2882';
obclient> ALTER SYSTEM DELETE SERVER 'xxx.xxx.x.xx5:2882';
Execute the following statement to query existing OBServer nodes. If the preceding OBServer nodes are not included in the returned list, the delete operation is successful.
obclient> SELECT * FROM oceanbase.DBA_OB_SERVERS;
Execute the following statement to delete the specified zones from the cluster.
obclient> ALTER SYSTEM DELETE ZONE z4; obclient> ALTER SYSTEM DELETE ZONE z5;Execute the following statement to query existing zones. If the preceding zones are not included in the returned zone list, the delete operation is successful.
obclient> SELECT * FROM oceanbase.DBA_OB_ZONES;The scale-in process is completed.