Add New Peer in TiKV

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: TIKV新增Peer

| username: TiDBer_NGmQDBXo

When TiKV starts for the first time, there is only one Peer in the Region. It reports to PD via heartbeat, and PD responds with ChangePeer in the heartbeat. After receiving this message, TiKV writes it into Raft and creates a new Peer.
How does TiKV create a new Peer? After writing into Raft, how is it created? It would be great if you could provide the code location. Thank you very much!

| username: TiDBer_NGmQDBXo | Original post link

How does the Leader send the information of the new Peer to the corresponding Store?
How does the Store that receives the message add the Peer?