# Additional Knowledge: Pd Scheduling Concepts


![left](./student-guide/diagram/03-30-1.png)

------------------------------------------------------------
PD scheduling

Understanding scheduling-related concepts and how they relate to each other helps you quickly locate issues and make adjustments through configuration in practice.

- Store
Store in PD refers to the storage node in the cluster, that is, the TiKV instance. Note that Store and TiKV instance are strictly one-to-one correspondence. Even if multiple TiKV instances are deployed on the same host or even the same disk, these instance will correspond to different Stores.

- Region/Peer/Raft Group
Each Region maintains a contiguous piece of data for the cluster (an average of about 96 MB by default), with multiple copies of each data stored in different Stores (3 replica by default), and each replica is called a peer. Peers in the same region synchronizing/syncing data via the raft protocol, so peers are also used to refer to members in the raft instance. TiKV uses a multi-raft mode to manage data, that is, each region corresponds to an independent raft instance. We also call such a raft instance a Raft Group.

- Leader/Follower/Learner
They correspond to each of the three roles of the peer. The Leader is responsible for responding to reads and writes request from the client; the Follower passively synchronizes data from the Leader, and when the Leader fails, a new Leader is elect; the Learner is a special role that only participates in synchronizing/syncing the raft log and not voting, and only exists briefly in the current implement for adding Intermediate steps for replica.

- Region Split/Merge
Region in a TiKV cluster are not divided at the beginning, but are generated gradually as data is written, and the splitting process is called region split.
The mechanism is to construct an initial region to cover the entire key space when the cluster is initialized, and then a new region is created through Split every time a certain amount of region data reaches a certain amount during operation. Conversely, if the number of key-values in a Region does not reach the agreed number, in order to reduce the administrative cost (number) of Region, we can try to merge Region, a process called Merge.

- Pending/Down
Pending and Down are two special states that a peer may experience. Pending indicates that there is a large gap between the raft log of the follower or learner and the leader, and a follower with a pending status cannot be elect as a leader. Down means that the Leader has not received a message from the peer for a long time, which usually means that the corresponding node is down or isolated from the network.

- Scheduler
The Scheduler (scheduler) is a component in the PD that generates schedules. Each scheduler in the PD operates independently and service different scheduling purposes. Commonly used schedulers and their calling targets are:
  balance-leader-scheduler: Keeps leaders balanced across different node.
  balance-region-scheduler: Keeps peers balanced across different node.
  Hot-region-scheduler: Maintains a balanced reads and writes hotspot region for different nodes.
  evict-leader- {store-id}: Evict all leaders of a node. (commonly used for rolling update)

- Operator
An Operator is a collection of operations that apply to a region and service a scheduling purpose. For example, “Migrate the Leader of Region 2 to Store 5", “Migrate a replica of Region 2 to Store 1, 4, 5", etc. Operators can be computationally generated by the Scheduler or created by external API.

- Operator Step
An Operator Step is a step in the Operator execution process, and an Operator often contains multiple Operator Steps.
Currently, the steps that can be generated by PD include:
  TransferLeader: Migrate the region leader to the specified peer
  AddPeer: Add Followers in the specified Store
  RemovePeer: Delete a region peer
  AddLearner: Add a region learner in the specified store
  PromoteLearner: Promote the specified Learner to a Follower
  SplitRegion: Divides the specified region in two
