Manage replicas
This topic describes how to manage tenant replicas by using ob-operator.
Modify the primary zone of a tenant
You can modify the priority
parameter of zones in the tenant configuration file to modify the primary zone of a tenant. A larger number indicates a higher priority. The minimum value is 1
.
The primary zone describes the preferred location of the leader. The leader handles strong-consistency read traffic and write traffic of the business. Therefore, the primary zone determines the traffic distribution of OceanBase Database. You can modify the primary zone to switch business traffic from one IDC to another or from one city to another in disaster recovery and scaling scenarios.
Procedure
-
Modify the tenant configuration file
tenant.yaml
to adjust the priority value for each zone.- zone: zone1
priority: 1
- zone: zone2
priority: 1
- zone: zone3
priority: 3
# After modification
- zone: zone1
priority: 3
- zone: zone2
@priority 2
- zone: zone3
priority: 1The preceding configuration changes the primary zone of the tenant from
zone3;zone1,zone2
tozone1;zone2;zone3
. -
Run the following command for the modification to take effect:
kubectl apply -f tenant.yaml
-
Run the following command to view the custom resources of the tenant in the current Kubernetes cluster to check whether the modification is successful:
kubectl get obtenants.oceanbase.oceanbase.com -n oceanbase -o yaml
If the value of the corresponding parameter in the
status.resourcePool.priority
section in the custom resources of the tenant is changed to the new value, the modification is successful.status:
...
resourcePool:
- zone: zone1
priority: 3
- zone: zone2
@priority 2
- zone: zone3
priority: 1You can also run the following command to view the result.
kubectl get obtenants.oceanbase.oceanbase.com -n oceanbase -o wide
The command output is as follows:
NAME STATUS TENANTNAME TENANTROLE CLUSTERNAME AGE LOCALITY PRIMARYZONE POOLLIST CHARSET
t1 running t1 PRIMARY obcluster 13m ... zone1;zone2;zone3 ... utf8mb4The result shows that the value of the
PRIMARYZONE
field is modified tozone1;zone2;zone3
, which matches the priority configuration.
Modify the locality of a tenant
To modify the locality of a tenant, you can modify the parameters in the type
section to specify the replica type and the number of replicas. The following replica types are supported: full
, logonly
, and readonly
.
For more information, see [Modify the primary zone of a tenant](# Modify the primary zone of a tenant).
Modify the tenant configuration file tenant.yaml
:
type:
name: Full # The Full and Readonly replica types are supported.
replica: 1
Add replicas
Prerequisites
- You have added a zone to the cluster. For more information, see Add zones to a cluster.
Procedure
You can add zones to a tenant by modifying the tenant configuration file tenant.yaml
.
Assume that the current cluster has four zones, zone1
, zone2
, zone3
, and zone4
, the zones corresponding to the tenant are zone1
, zone2
, and zone3
, and you want to scale out the tenant to four zones.
-
Modify the configuration file
tenant.yaml
to addzone4
.# For example, the tenant has three zones.
pools:
- zone: zone1
unitNum: 1
type:
name: Full
replica: 1
priority: 3
resource:
...
- zone: zone2
unitNum: 1
type:
name: Full
replica: 1
priority: 3
resource:
...
- zone: zone3
unitNum: 1
type:
name: Full
replica: 1
priority: 3
resource:
...
# Add zone4 to the tenant.
pools:
- zone: zone1
unitNum: 1
type:
name: Full
replica: 1
priority: 3
resource:
...
- zone: zone2
unitNum: 1
type:
name: Full
replica: 1
priority: 3
resource:
...
- zone: zone3
unitNum: 1
type:
name: Full
replica: 1
priority: 3
resource:
...
- zone: zone4
unitNum: 1
type:
name: Full
replica: 1
priority: 3
resource:
... -
Run the following command for the modification to take effect:
kubectl apply -f tenant.yaml
-
Run the following command to view the custom resources of the tenant in the current Kubernetes cluster:
kubectl get obtenants.oceanbase.oceanbase.com -n oceanbase -o wide
The following command output shows that the value of the LOCALITY field is as expected:
NAME STATUS TENANTNAME TENANTROLE CLUSTERNAME AGE LOCALITY PRIMARYZONE POOLLIST CHARSET
t1 running t1 PRIMARY obcluster 19m FULL{1}@zone1,FULL{1}@zone2,FULL{1}@zone3,FULL{1}@zone4 ... ... utf8mb4
Delete replicas
Procedure
You can modify the tenant configuration file tenant.yaml
to delete zones from a tenant.
Assume that the current cluster has four zones, zone1
, zone2
, zone3
, and zone4
, the zones corresponding to the tenant are zone1
, zone2
, zone3
, and zone4
, and you want to scale in the tenant to zone1
, zone2
, and zone3
.
-
Modify the configuration file
tenant.yaml
to deletezone4
.# For example, the tenant has four zones.
pools:
- zone: zone1
unitNum: 1
type:
name: Full
replica: 1
priority: 3
resource:
...
- zone: zone2
unitNum: 1
type:
name: Full
replica: 1
priority: 3
resource:
...
- zone: zone3
unitNum: 1
type:
name: Full
replica: 1
priority: 3
resource:
...
- zone: zone4
unitNum: 1
type:
name: Full
replica: 1
priority: 3
resource:
...
# Delete zone4 from the tenant.
pools:
- zone: zone1
unitNum: 1
type:
name: Full
replica: 1
priority: 3
resource:
...
- zone: zone2
unitNum: 1
type:
name: Full
replica: 1
priority: 3
resource:
...
- zone: zone3
unitNum: 1
type:
name: Full
replica: 1
priority: 3
resource:
... -
Run the following command for the modification to take effect:
kubectl apply -f tenant.yaml
-
Run the following command to view the custom resources of the tenant in the current Kubernetes cluster:
kubectl get obtenants.oceanbase.oceanbase.com -n oceanbase -o wide
The following command output shows that the value of the LOCALITY field is as expected:
NAME STATUS TENANTNAME TENANTROLE CLUSTERNAME AGE LOCALITY PRIMARYZONE POOLLIST CHARSET
t1 running t1 PRIMARY obcluster 25m FULL{1}@zone1,FULL{1}@zone2,FULL{1}@zone3 ... ... utf8mb4