open-webrtc-toolkit / owt-server

General server (streaming/conference/transcoding/anayltics) for OWT. (A.k.a. MediaServer)
https://01.org/open-webrtc-toolkit
Apache License 2.0
1.13k stars 368 forks source link

optimize and add leader lease for raft #1383

Closed keycodingyfq closed 1 month ago

keycodingyfq commented 1 month ago
  1. change variable name commitId to commitIndex
  2. enable heartbeatTime and leaderLeaseTimeout configurations not to be calculated through electTimeout, but to support independent configuration
  3. optimize preLogTerm compare, by comparing the preLogIndex of the requesting voting node with its own preLogIndex to obtain preLogTerm, instead of using state. preLogTerm fixed, we can improves the speed of voting
  4. optimize the voting decision for candidates. candidates within the same term are first voted for by oneself. When receiving voting requests from other nodes within the same term, if one is still in a candidate state and their data is outdated, their votes will be transferred to other nodes improves the speed of voting
  5. optimize installsnapshot so that it can only be successfully issued once during concurrent execution of installsnapshot, and under the control of installSnapshotMutex, other queued requests entering the installsnapshot method are automatically canceled to determine if their request is outdated
  6. add responseHeartbeat for follower when it receive heartbeat from leader
  7. add a leader lease mechanism, where the leader determines whether more than half of the nodes are unresponsive by judging whether they have received a follower response, thereby actively transitioning to a follower state, avoiding the problem of dual leaders in network partitioning