This topic describes how to modify the locality of a tenant in a cluster to reduce the number of partition replicas in the tenant.
For more information about how to modify the locality, see Modify locality.
Prerequisites
Before you modify the locality of a tenant, verify the resource information of each node in the target zone. If OBServer nodes in the target zone do not have sufficient resources to accommodate the new resource units of the tenant, the locality cannot be changed.
For more information about how to view the resource information of each node in a zone, see View tenant and resource information.
Considerations
The locality of a tenant must be specified.
Modifying the locality of a tenant also changes the distribution of table replicas for the tenant.
If a tenant locality modification is not finished, the next tenant locality modification cannot be performed.
You can perform only one action at a time when you modify the locality. For example, if you want to replace zone3 with zone4, you must add zone4 first and then remove zone3.
After you add a replica to a tenant, the locality of the tenant does not match the primary zone of the tenant. If the new zone is involved in leader switchover, you must modify the primary zone. If the new zone is not involved in leader switchover, you do not need to modify the primary zone.
After you remove replicas from a tenant, you can remove resource pools from the tenant if you want to release resources.
Assume that zones z1, z2, and z3 are configured for a tenant and you want to remove zone z3. The following scenarios exist:
The tenant has an independent resource pool in
z3. For example, the tenant has two resource pools:resource_pool1andresource_pool2, andresource_pool2belongs toz3. After the replica is removed, you must removeresource_pool2from the resource pool list of the tenant. Then you can delete the resource pool to release the resources. For more information, see Drop a resource pool.The tenant has no independent resource pool in
z3. For example, the resource poolresource_pool1of the tenant belongs toz2andz3. After you remove the replica, you must removez3from thezonelist ofresource_pool1to release the resources. For more information about how to modify thezonelist of a resource pool, see Modify attributes of a resource pool.
Procedure
The following example describes how to modify the locality of the mysql001 tenant from FULL{1}@zone1, FULL{1}@zone2, FULL{1}@zone3 to FULL{1}@zone1, FULL{1}@zone2, and reduce the number of replicas for the tenant.
Note
One zone is removed in this example. In practice, the majority principle must be met after you remove zones.
Log on to the sys tenant of the cluster as the root user.
obclient -h172.30.xxx.xxx -P2883 -uroot@sys#obdemo -pxxxx -AAccess the database named
oceanbase.obclient>use oceanbase;View the locality of the
mysql001tenant.obclient> SELECT TENANT_ID,TENANT_NAME,TENANT_TYPE,PRIMARY_ZONE,LOCALITY FROM oceanbase.DBA_OB_TENANTS; +-----------+-------------+-------------+-------------------+---------------------------------------------+ | TENANT_ID | TENANT_NAME | TENANT_TYPE | PRIMARY_ZONE | LOCALITY | +-----------+-------------+-------------+-------------------+---------------------------------------------+ | 1 | sys | SYS | zone1;zone2;zone3 | FULL{1}@zone1, FULL{1}@zone2, FULL{1}@zone3 | | 1001 | META$1002 | META | zone1;zone2;zone3 | FULL{1}@zone1, FULL{1}@zone2, FULL{1}@zone3 | | 1002 | mysql001 | USER | zone1;zone2;zone3 | FULL{1}@zone1, FULL{1}@zone2, FULL{1}@zone3 | +-----------+-------------+-------------+-------------------+---------------------------------------------+The query result shows that the
mysql001tenant has a full-featured replica in each of zone 1, zone 2, and zone 3.Modify the locality of the
mysql001tenant.obclient>ALTER TENANT mysql001 locality="FULL{1}@zone1, FULL{1}@zone2";View the execution status of the locality change job.
obclient>SELECT * FROM oceanbase.DBA_OB_TENANT_JOBS WHERE JOB_TYPE = 'ALTER_TENANT_LOCALITY'; +--------+-----------------------+------------+-------------+----------+----------------------------+----------------------------+-----------+------------------------------------------------------------------------------+---------------------------------------------+----------------+-------------+ | JOB_ID | JOB_TYPE | JOB_STATUS | RESULT_CODE | PROGRESS | START_TIME | MODIFY_TIME | TENANT_ID | SQL_TEXT | EXTRA_INFO | RS_SVR_IP | RS_SVR_PORT | +--------+-----------------------+------------+-------------+----------+----------------------------+----------------------------+-----------+------------------------------------------------------------------------------+---------------------------------------------+----------------+-------------+ | 1 | ALTER_TENANT_LOCALITY | SUCCESS | 0 | 100 | 2023-01-05 19:33:46.730319 | 2023-01-05 19:33:46.920111 | 1002 | ALTER TENANT mysql001 locality='FULL{1}@zone1, FULL{1}@zone2' | FULL{1}@zone1, FULL{1}@zone2, FULL{1}@zone3 | xx.xx.xx.xx | 2882 | +--------+-----------------------+------------+-------------+----------+----------------------------+----------------------------+-----------+------------------------------------------------------------------------------+---------------------------------------------+----------------+-------------+If the value of
JOB_STATUSisSUCCESS, the locality change job is successful.View the modified locality of the
mysql001tenant.obclient> SELECT TENANT_ID,TENANT_NAME,TENANT_TYPE,PRIMARY_ZONE,LOCALITY FROM oceanbase.DBA_OB_TENANTS; +-----------+-------------+-------------+-------------------+---------------------------------------------+ | TENANT_ID | TENANT_NAME | TENANT_TYPE | PRIMARY_ZONE | LOCALITY | +-----------+-------------+-------------+-------------------+---------------------------------------------+ | 1 | sys | SYS | zone1;zone2;zone3 | FULL{1}@zone1, FULL{1}@zone2, FULL{1}@zone3 | | 1001 | META$1002 | META | zone1;zone2 | FULL{1}@zone1, FULL{1}@zone2 | | 1002 | mysql001 | USER | zone1;zone2 | FULL{1}@zone1, FULL{1}@zone2 | +-----------+-------------+-------------+-------------------+---------------------------------------------+
The query results in step 3 and step 6 show that the locality of the mysql001 tenant is changed from FULL{1}@zone1, FULL{1}@zone2, FULL{1}@zone3 to FULL{1}@zone1, FULL{1}@zone2, and the number of replicas for the mysql001 tenant is reduced.