Locality describes the distribution of replicas at the table or tenant level. The distribution information refers to the number and types of replicas in each zone. The locality of each tenant is different and independent. Different tenants in a cluster can have different localities.
Syntax
Locality is described by the following syntax:
replicas{count}@location
The following table describes elements in the syntax.
| Element | Description |
|---|---|
| replicas | The type of the replica. For more information about the replica types, see Overview. The value of replicas is the name of the replica type. Both full names and abbreviations are supported. You can view the supported replica type names in the name row of the table in the topic. |
| location | Represents the location of the replica. It contains a collection of values that are known to the system. The value of location is the name of the zone. For more information about how to query zone names at the cluster or tenant level, see View cluster topology. |
| count | If this parameter is not specified, only one replica is available. {n} specifies N replicas. The special count {all_server} specifies that the number of replicas is the same as the number of available OBServer nodes. A partition can have at most one full-featured replica in a zone. These replicas are part of the Paxos replica group. |
Note
You do not need to specify the table-level locality. In this case, the locality is inherited from the tenant. You must specify the locality of the tenant.
When the locality of a tenant changes, if the locality of a table in the tenant is unspecified, the distribution of the table replicas also changes. When the locality of a tenant changes, if the locality of a table in the tenant is specified, the distribution of the table replicas does not change.
The following example describes the locality of different tenants in an OceanBase cluster that has five zones. The zones are z1 to z5.
The locality of the sys tenant:
F@z1,F@z2,F@z3,F@z4,F@z5The locality of tenant2:
F@z1
Locality change rules
Before you change the locality of a tenant, make sure that the previous locality change is completed.
Application scenarios of locality
Locality settings are often used when you want to increase or decrease the number of replicas in a cluster or migrate a cluster.
Increase the number of replicas in a cluster
You can increase the number of partition replicas in each tenant in a cluster. For example, after you change a locality from
F@z1,F@z2,F@z3toF@z1,F@z2,F@z3,F@z4,F@z5, the number of replicas of each partition in the tenant increases from three to five.Decrease the number of replicas in a cluster
You can decrease the number of partition replicas in each tenant in a cluster. For example, after you change a locality from
F@z1,F@z2,F@z3,F@z4,F@z5toF@z1,F@z2,F@z3, the number of replicas of each partition decreases from five to three.Cluster migration
You can change the locality of each tenant in a cluster. For example, after you change a locality from
F@hz1,F@hz2,F@hz3toF@hz1,F@sh1,F@sh2, two zones in Hangzhou are relocated to Shanghai. hz and sh indicate the Hangzhou and Shanghai regions.