ktoso/akka-raft

Log consistency check is incorrect

colin-scott opened this issue · 1 comments

The log consistency check is currently implemented as follows:

  /**                                                                  
   * Performs the "consistency check", which checks if the data that we just got from the
   */                                                                  
  def containsMatchingEntry(otherPrevTerm: Term, otherPrevIndex: Int): Boolean =
    (otherPrevTerm == Term(0) && otherPrevIndex == 0) || (lastTerm == otherPrevTerm && lastIndex == otherPrevIndex)

I don't think the second disjunct is correct. The Raft paper states that the log consistency check should fail "if log doesn’t contain an entry at prevLogIndex whose term matches prevLogTerm".

So I think the second disjunct should be:

(entries.isDefinedAt(otherPrevIndex - 1) && entries(otherPrevIndex - 1).term == otherPrevTerm)

(assuming 1-indexed log entries, following the raft paper)

For what it's worth, I have a (non-pull-request-worthy) fix to this issue here:

NetSys/demi-applications@705f8de