# Labeling for High Availability

![`smart`](LabelWithHighAvailability_aa_003_20220509.png)

--------------------------------------------------------------------------------
Observe the diagram, in which DC 1 ~ 3 represent 3 independent data centers, Rack 1 ~ 6 represent 6 racks, TiKV Server-1 ~ TiKV Server-12 represent 12 hosts, and each host has one TiKV instance. Next, we look at the distribution of 3 kinds of regions, assuming they are all default 3 replicas.

1. The distribution of `Region 1` is 1 Leader and 1 Follower respectively on 2 hosts TiKV Server-7 and TiKV Server-8 in `Rack 4`, and another Follower in `Rack 6` in `DC 3`. The risk of such deployment is that if `DC 2` has problems or `Rack 4` has problems, it will cause `Region 1` to be unavailable.

2. The distribution of `Region 2` is 1 Leader and 2 Followers in different racks, so any single rack has problems, `Region 2` can still be used, which is stronger than `Region 1`. However, if `DC 1` has problems, `Region 2` is not available anymore.

3. `Region 3` has 1 Leader and 2 Followers in different DCs, so no matter DC, rack or TiKV has problems, it won't affect the availability of `Region 1`.

After comparing the distributions of `Region 1`, `Region 2` and `Region 3`, we found that different Region distributions have an impact on availability. Especially if the metadata of the database, such as information schema, is stored in a certain Region, and the Region is unavailable, it will cause the entire database to malfunction.

However, we know that the original distribution of Regions is randomly deployed by PD, and PD nodes only guarantee that multiple replicas of the same Region will not be placed on the same TiKV node, but PD nodes are unaware of concepts such as DC, rack, and host.

So the concept of label came into being, which is what we often call tagging. We can set a label (tag) for each TiKV instance to identify which DC, rack and host it is on. And PD nodes agree on the format of the label, so that when PD nodes initially distribute regions, they can sense the location of DC, rack and host according to the label set on TiKV nodes, so as to achieve the highest availability of distribution.

