This topic describes how to modify the locality of a tenant in a cluster to adjust the distribution of log stream 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 the nodes in the target zone do not have sufficient resources to accommodate the resource units required by 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.
When the locality of a tenant changes, the replica distribution of all tables in the tenant will also change.
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 zone1 with zone2, you must add zone2 first and then remove zone1.
After you add a replica to a tenant, the locality of the tenant does not match the primary zone of the tenant. If the added zone is involved in leader switchover, you must modify the primary zone. If the added zone is not involved in leader switchover, you do not need to modify the primary zone.
Procedure
The following example describes how to modify the locality of the mysql001 tenant from FULL{1}@zone1 to FULL{1}@zone2.
Log in to the
systenant of the cluster as therootuser.obclient -h172.30.xxx.xxx -P2883 -uroot@sys#obdemo -pxxxx -AAccess the database named
oceanbase.obclient(root@sys)[(none)]> USE oceanbase;Query the current locality of the
mysql001tenant.obclient(root@sys)[oceanbase]> SELECT TENANT_ID, TENANT_NAME, TENANT_TYPE, PRIMARY_ZONE, LOCALITY FROM oceanbase.DBA_OB_TENANTS;The query result is as follows:
+-----------+-------------+-------------+-------------------+---------------------------------------------+ | TENANT_ID | TENANT_NAME | TENANT_TYPE | PRIMARY_ZONE | LOCALITY | +-----------+-------------+-------------+-------------------+---------------------------------------------+ | 1 | sys | SYS | zone1;zone2 | FULL{1}@zone1, FULL{1}@zone2 | | 1001 | META$1002 | META | zone1 | FULL{1}@zone1 | | 1002 | mysql001 | USER | zone1 | FULL{1}@zone1 | +-----------+-------------+-------------+-------------------+---------------------------------------------+ 3 rows in setYou can see that the
mysql001tenant has one full-featured replica in zone1.Modify the locality of the
mysql001tenant to add a replica in zone2.obclient(root@sys)[oceanbase]> ALTER TENANT mysql001 locality="FULL{1}@zone1, FULL{1}@zone2";View the execution status of the locality change job.
obclient(root@sys)[oceanbase]> SELECT * FROM oceanbase.DBA_OB_TENANT_JOBS WHERE JOB_TYPE = 'ALTER_TENANT_LOCALITY';The query result is as follows:
+--------+-----------------------+------------+-------------+----------+----------------------------+----------------------------+-----------+---------------------------------------------------------------------------------------------+---------------------------------------------+----------------+-------------+ | 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 | NULL | 0 | 2023-01-05 19:38:38.416011 | 2023-01-05 19:38:38.416011 | 1002 | ALTER TENANT mysql001 locality='FULL{1}@zone1, FULL{1}@zone2' | FULL{1}@zone1 | xx.xx.xx.237 | 2882 | +--------+-----------------------+------------+-------------+----------+----------------------------+----------------------------+-----------+---------------------------------------------------------------------------------------------+---------------------------------------------+----------------+-------------+ 1 row in setIf the value of
JOB_STATUSisSUCCESS, the locality change job is successful.Modify the locality of the
mysql001tenant to remove the replica in zone1.obclient(root@sys)[oceanbase]> ALTER TENANT mysql001 locality="FULL{1}@zone2";View the execution status of the locality change job.
obclient(root@sys)[oceanbase]> SELECT * FROM oceanbase.DBA_OB_TENANT_JOBS WHERE JOB_TYPE = 'ALTER_TENANT_LOCALITY';The query result is as follows:
+--------+-----------------------+------------+-------------+----------+----------------------------+----------------------------+-----------+------------------------------------------------------------------------------+------------------------------------------------------------+----------------+-------------+ | 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 | NULL | 0 | 2023-01-05 19:38:38.416011 | 2023-01-05 19:38:38.416011 | 1002 | ALTER TENANT mysql001 locality='FULL{1}@zone2' | FULL{1}@zone1, FULL{1}@zone2 | xx.xx.xx.237 | 2882 | +--------+-----------------------+------------+-------------+----------+----------------------------+----------------------------+-----------+------------------------------------------------------------------------------+------------------------------------------------------------+----------------+-------------+ 1 row in setIf the value of
JOB_STATUSisSUCCESS, the locality change job is successful.View the modified locality of the
mysql001tenant.obclient(root@sys)[oceanbase]> SELECT TENANT_ID, TENANT_NAME, TENANT_TYPE, PRIMARY_ZONE, LOCALITY FROM oceanbase.DBA_OB_TENANTS;The query result is as follows:
+-----------+-------------+-------------+-------------------+---------------------------------------------+ | TENANT_ID | TENANT_NAME | TENANT_TYPE | PRIMARY_ZONE | LOCALITY | +-----------+-------------+-------------+-------------------+---------------------------------------------+ | 1 | sys | SYS | zone1;zone2 | FULL{1}@zone1, FULL{1}@zone2 | | 1001 | META$1002 | META | zone2 | FULL{1}@zone2 | | 1002 | mysql001 | USER | zone2 | FULL{1}@zone2 | +-----------+-------------+-------------+-------------------+---------------------------------------------+ 3 rows in setThe query results in step 3 and step 8 show that the locality of the
mysql001tenant is changed fromFULL{1}@zone1toFULL{1}@zone2, and themysql001tenant has a full-featured replica in zone2.
After you add the replica in step 4, the locality of the tenant does not match the primary zone of the tenant. If the added zone is involved in leader switchover, you must modify the primary zone. For more information about how to modify the primary zone, see Scale tenants by adjusting the primary zone. If the added zone is not involved in leader switchover, you do not need to modify the primary zone.