cockroachdb / cockroachdb/cockroach
raft: pipeline probing logic into voting process
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
We can add a hint index and term in raft `MsgVoteResp` so that a newly elected leader can potentially directly start replicating to the follower if that hint index and term match an entry in its own log.
(We can do this mainly because of the 2 following guarantees:
raft log matching property explained in section 5.3 of the raft paper
after voting for a legitimate candidate "C", a voter would not vote or accept MsgApp from other nodes, which means if "C" wins the elction, the voter's log will stay unchanged)
**Proposed approach:**
Upon a voter receiving `MsgVote`, whether the voter decides to vote, it can add its `lastIndex` and `lastTerm` in its raftLog to `MsgVoteResp` as `hintIndex` and `hintTerm`.
When the candidate who initiated the voting process receives `MsgVoteResp`, it can remember the `hintIndex` and `hintTerm` in a temporary location (trk.progress or election tracker).
If the candidate won the election after receiving enough votes and becomes a new leader, the new leader can check each hintIndex/hintTerm that was previously collected and run it against its own raftLog to see if it is a match entry.
If it is indeed a match, we can change the state of that follower to `stateReplicate` and set next index as the hintIndex.
The leader will then send MsgApp messages with entries starting at that hintIndex. which allows for faster replication and saves us 1 rtt.
Jira issue: CRDB-48363
Contributor guide
Assessment
This issue has not been assessed yet.