Raft AppendEntries
Raft AppendEntries
A leader sends an AppendEntries request containing:
prevLogIndexandprevLogTerm- a list of new entry terms to append
The follower should accept only if its log matches at prevLogIndex. If accepted, it must truncate any conflicting entries after prevLogIndex then append the new entries.
Log indices are 1-based. prevLogIndex == 0 always matches.
Function signature
func AppendEntries(logTerms []int, prevLogIndex int, prevLogTerm int, entries []int) (newLog []int, ok bool)
Example
logTerms = [1,1,2,2]
prevLogIndex = 2
prevLogTerm = 1
entries = [3,3]
output log = [1,1,3,3], ok = true
Rules
- If
prevLogIndex > len(logTerms), reject. - If
prevLogIndex > 0andlogTerms[prevLogIndex-1] != prevLogTerm, reject. - Otherwise, accept: keep entries up to
prevLogIndex, appendentries.
Constraints
0 <= prevLogIndex <= len(logTerms)
Run tests to see results
No issues detected