#  (Hide) TiDB Scheduling Of A  cluster - PD 
+ **Placement Driver** It is the management module of TiDB cluster and is also responsible for real-time scheduling of cluster data. It is mainly responsible for:
  + Distribute each region evenly
  + When adding a node, move data from other nodes to the new node
  + Fast and stable failure recover when a node goes offline
  + Collect cluster status information and schedule read/write hotspots
-------------------------------------------------------------
PD needs to consider the following scenario:

- In order to improve the space utilization of the cluster, replica need to be distributed reasonably according to the space usage of the region.
- When a cluster is deployed across computer rooms, ensure that one room is dropped and multiple replica of the Raft Group will not be lost.
- After adding a node to the TiKV cluster, it is necessary to move data from other nodes in the cluster to the new node appropriately.
- When a node goes down, it is necessary to consider rapid and stable disaster recovery.
    - In terms of the recover time of the node
      - Does the node need to be scheduled if it only goes down briefly (restart the service).
      - How to schedule a node if it goes down for a long time (disk failure, loss of all data).
    - Assume that the cluster requires N replica of each Raft Group, based on the number of replica in a single Raft Group
      - Insufficient number of replicas (e.g. node drops, loss of replicas) and needs to be supplemented by selecting the appropriate machine.
      - The number of replicas is too large (for example, a dropped node returns to recover and automatically joins the cluster), and it is necessary to delete the excess replicas reasonably.
- Read/write is done through the leader. The distribution of the leader only in a few node will affect the cluster.
- Not all regions Region frequently visited. Access hotspots may only be in a few Region, and load balancing is required by scheduling.
- When a cluster is load balancing, it is often necessary to migrate data, which may consume a lot of network bandwidth, disk IO, and CPU, and affect online service.

If more than one of the above problems and scenario occurs at the same time, it is not easy to solve because global information needs to be considered. At the same time, the whole system is also changing dynamically, so a central node is needed to control and adjust the overall condition of the system, so there is a PD module.