jasonrogena / lightraft

Wrapper around SQLite that makes it distributed. This is an experiment, don't use in production
11 stars 2 forks source link

Reconciling Log With Leader #10

Closed jasonrogena closed 4 years ago

jasonrogena commented 4 years ago

According to In Search Of An Understandable Consensus Algorithm, section 5.3:

If last log index >= nextIndex for a follower: send AppendEntries RPC with log entries starting at the follower's nextIndex:

  1. If successful: Update nextIndex and matchIndex for follower
  2. If AppendEntries RPC fails because of log inconsistencies, decrement nextIndex and retry.

Make sure this is implemented. Notes on how an AppendEntries RPC should be handled when received:

  1. Reply false if term < currentTerm (5.1). What should happen on the leader if reply is false?
  2. Reply false if log doesn't contain an entry at prevLogIndex whose term matches prevLogTerm (5.3).
  3. If an existing entry conflicts with a new one (same index but different terms), delete the existing entry and all that follow it (5.3).
  4. Append any new entries not already in the log.
  5. If leaderCommit > commitIndex, set commitIndex = min(leaderCommit, index of last entry).