This topic describes how to adjust the distribution of log stream replicas in a tenant by modifying the locality of the tenant in the cluster.
For more information about modifying locality, see Modify locality.
Prerequisites
Before modifying locality, verify the resource allocation on each node in the zone to be modified. If the nodes in the zone do not have sufficient resources to accommodate the resource units required by the tenant, the locality modification cannot proceed.
For more information about the resource allocation 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 distribution of table replicas in the tenant also changes.
If a tenant locality modification is not finished, the next tenant locality modification cannot be performed.
Only one action can be performed at a time when you modify the locality. For example, to replace zone3 with zone4, you cannot do it directly. You must add zone4 first and then remove zone3.
Adding replicas may cause a mismatch between the tenant's locality and primary zone. If the added zone participates in leader switchover, you need to modify the primary zone. If the added zone does not participate 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, FULL{1}@zone2, FULL{1}@zone3 to FULL{1}@zone1, FULL{1}@zone2, FULL{1}@zone4.
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>use oceanbase;View the locality of the
mysql001tenant before modification.obclient> 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;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 | +-----------+-------------+-------------+-------------------+---------------------------------------------+ 3 rows in setYou can see that the
mysql001tenant has one full-featured replica in each of zone1, zone2, and zone3.Modify the locality of the
mysql001tenant to add a replica in zone4.obclient>ALTER TENANT mysql001 locality="FULL{1}@zone1, FULL{1}@zone2, FULL{1}@zone3, FULL{1}@zone4";View the execution status of the locality modification job.
obclient>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}@zone3, FULL{1}@zone4' | FULL{1}@zone1, FULL{1}@zone2, FULL{1}@zone3 | xx.xx.xx.237 | 2882 | +--------+-----------------------+------------+-------------+----------+----------------------------+----------------------------+-----------+---------------------------------------------------------------------------------------------+---------------------------------------------+----------------+-------------+ 1 row in setIf the value of
JOB_STATUSisSUCCESS, the locality modification job is successful.Modify the locality of the
mysql001tenant to remove the replica in zone3.obclient>ALTER TENANT mysql001 locality="FULL{1}@zone1, FULL{1}@zone2, FULL{1}@zone4";View the execution status of the locality modification job.
obclient>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}@zone4' | FULL{1}@zone1, FULL{1}@zone2, FULL{1}@zone3, FULL{1}@zone4 | xx.xx.xx.237 | 2882 | +--------+-----------------------+------------+-------------+----------+----------------------------+----------------------------+-----------+------------------------------------------------------------------------------+------------------------------------------------------------+----------------+-------------+ 1 row in setIf the value of
JOB_STATUSisSUCCESS, the locality modification job is successful.View the locality of the
mysql001tenant after modification.obclient> 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;zone3 | FULL{1}@zone1, FULL{1}@zone2, FULL{1}@zone3 | | 1001 | META$1002 | META | zone1;zone2 | FULL{1}@zone1, FULL{1}@zone2, FULL{1}@zone4 | | 1002 | mysql001 | USER | zone1;zone2 | FULL{1}@zone1, FULL{1}@zone2, FULL{1}@zone4 | +-----------+-------------+-------------+-------------------+---------------------------------------------+ 3 rows in setBy comparing the query results of steps 3 and 8, the locality of the
mysql001tenant has changed fromFULL{1}@zone1, FULL{1}@zone2, FULL{1}@zone3toFULL{1}@zone1, FULL{1}@zone2, FULL{1}@zone4, and themysql001tenant has one full-featured replica in each of zone1, zone2, and zone4.
After step 4 is executed, adding replicas will cause a mismatch between the tenant locality and the tenant primary zone. If the added zone participates in leader switchover, you need to modify the primary zone. For more information about modifying the primary zone, see Adjust primary zone. If the added zone does not participate in leader switchover, you do not need to modify the primary zone.