# Label With High Availability


![left](./student-guide/diagram/04-high-availability-01-01.png)

------------------------------------------------------------
To illustrate the function of label, let's take a look at the following diagram. In the figure, DC 1-3 represents 3 independent data centers, Racks 1 to 6 represent 6 cabinets (racks), and TikV-1 to TiKV-12 represent 12 host, each with one TiKV instance. Next, let's look at the distribution of the 3 regions, assuming that they are all 3 replica by default:
  - The distribution of Region 1 is 1 leader and 1 follower on 2 host TiKV-7 and TiKV-8 in Rack 4 cabinets, and the other follower in Rack 6 cabinets in DC 3. The risk of this deployment is that if there is a problem with DC 2 or a problem with Rack 4, it will cause Region 1 to become unavailable.
  - The distribution of Region 2 is that 1 leader and 2 followers are in different cabinets, so if there is a problem in any one cabinet alone, Region 2 is available, which is stronger than Region 1. However, if there is a problem with IDC 1, our Region 2 is no longer available.
  - The distribution of Region 3 is that 1 leader and 2 followers are in different DCs, so that there is no problem with DC, rack, or host (TiKV), it will not affect the availability of Region 1.

Comparing the distribution of Region 1, Region 2, and Region 3, we found that different Region distributions have an impact on availability. In particular, if the metadata of the database is stored in some regions, such as information schema, then the unavailability of a Region will be Causes the entire database to become unusable.

However, we know that the original distribution of regions is randomly deployed by PD, and PD nodes only guarantee that multiple replica of a region will not be placed on the same TiKV node, but for DC, the concepts of cabinet (rack) and host (host) PD nodes are completely ignorant.

How do you do it? So with the concept of label, which is what we often call labeling, we can set a label for each TiKV instance to identify which host in which rack of which DC it is on. The PD node agrees on the label format, so that when the PD node initially distributes the region, it can perceive the position of DC, rack, and host according to the lable set on the TiKV node, so as to maximize the availability distribution.

So how to set a label, we'll introduce it next.
