Raft Commit Index
Raft Commit Index
A Raft leader can advance commitIndex to the largest index N such that:
- A majority of
matchIndexvalues are>= N logTerms[N-1] == currentTerm
Given the match indices for all nodes (including the leader), the log terms, and the current term, compute the commit index.
If no index in the current term satisfies the majority rule, return 0.
Function signature
func CommitIndex(matchIndex []int, logTerms []int, currentTerm int) int
Example
matchIndex = [5,5,4,3,2]
logTerms = [1,1,2,2,3]
currentTerm = 2
output = 4
Constraints
len(matchIndex) >= 1len(logTerms) >= 0matchIndex[i]may be 0
Run tests to see results
No issues detected