Remove replicas

2023-08-01 06:02:28  Updated

This topic describes how to remove replicas from a tenant by modifying the locality of the tenant.

For more information about how to modify the locality, see Modify locality.

Prerequisites

Before you modify the locality of a tenant, check the status of the resource units and the resource pool 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 check the status of the resource units and resource pool in a zone, see View resource information of a cluster.

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:

    1. The tenant has an independent resource pool in z3. For example, the tenant has two resource pools: resource_pool1 and resource_pool2, and resource_pool2 belongs to z3. After you remove a replica, you must remove resource_pool2 from the resource pool list of the tenant. Then you can delete the resource pool to release the resources.
    1. The tenant has no independent resource pool in z3. For example, the resource_pool1 resource pool of the tenant belongs to z2 and z3. After you remove a replica, you must remove z3 from the zone list of resource_pool1 to release the resources.

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.

  1. Log on to the sys tenant of the cluster as the root user.

    obclient -h172.30.xxx.xxx -P2883 -uroot@sys -pxxxx -A
    
  2. Access the database named oceanbase.

    obclient>use oceanbase;
    
  3. View the locality of the mysql001 tenant.

    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 mysql001 tenant has a full-featured replica in each of Zone 1, Zone 2, and Zone 3.

  4. Modify the locality of the mysql001 tenant.

    obclient>ALTER TENANT mysql001 locality="FULL{1}@zone1, FULL{1}@zone2";
    
  5. 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_STATUS is SUCCESS, the locality modification job is successful.

  6. View the modified locality of the mysql001 tenant.

    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.

More information

Contact Us