Raft Conflict Backtracking
Raft Conflict Backtracking
When a follower rejects AppendEntries, it can return conflict information to help the leader skip back efficiently.
Given the leader's log terms and the follower's conflict reply:
- If
conflictTerm == 0, the follower is missing entries. SetnextIndex = conflictIndex. - Otherwise, if the leader has entries with
conflictTerm, setnextIndexto last index ofconflictTermin the leader log + 1. - If the leader does not have
conflictTerm, setnextIndex = conflictIndex.
Indices are 1-based. An empty log has length 0.
Function signature
func NextIndexAfterConflict(leaderLog []int, conflictTerm int, conflictIndex int) int
Example
leaderLog = [1,1,2,2,3]
conflictTerm = 2
conflictIndex = 3
last index of term 2 is 4, so nextIndex = 5
Constraints
0 <= len(leaderLog) <= 1000000 <= conflictTerm <= 1_000_0001 <= conflictIndex <= len(leaderLog)+1
Notes
- This models the optimization described in the Raft paper.
Run tests to see results
No issues detected