baidu / braft

An industrial-grade C++ implementation of RAFT consensus algorithm based on brpc, widely used inside Baidu to build highly-available distributed systems.
Apache License 2.0
3.84k stars 862 forks source link

rand peer when find_the_next_candidate #425

Closed lintanghui closed 5 months ago

lintanghui commented 7 months ago

目前find_the_next_candidate 的逻辑是找到index最新的peerid作为下一个candidate, 但是由于replicagroup是个ordermap, 会导致index没有延时的时候,找到的next candidate都是同一个peer,在multi raft group的情况下,当node进行重启的时候,会导致leader 都 transfer到相同的节点从而导致负载过高。 在 find_the_next_candidate的时候,通过rand 打散,尽可能将leader 分配的不同的peerid, 避免重启的时候leader集中到某一个节点导致瞬间负载过高

wanghenshui commented 5 months ago

ping @PFZheng