Back to Module 6 notes

This set practises running Raft’s two RPCs by hand on concrete logs. Logs are written as the list of their entries’ terms, index 1 first.

Problem 1

Problem 6.1 (Persistent or volatile).
  1. For each of currentTerm, votedFor, log[], commitIndex, lastApplied, nextIndex[], matchIndex[], say whether the Raft paper keeps it on stable storage.
  2. For each persistent variable, describe in one or two sentences an execution that goes wrong if an implementation keeps it only in memory.
  3. Explain how a restarted follower and a newly elected leader each find out the correct commitIndex again.
  4. Why must a persistent variable be written to stable storage before the reply is sent, not after?

Problem 2

Problem 6.2 (Who can win an election?).

Five servers have these logs (terms of the entries):

  • S1: 1, 1, 2, 2
  • S2: 1, 1, 2
  • S3: 1, 1, 1, 1, 1
  • S4: 1, 1, 3
  • S5: 1, 1, 2, 2, 2

Assume every server is in the same term and has not voted, and the candidate starts the next term.

  1. S1 becomes a candidate. Which servers grant their vote? Can S1 win?
  2. Answer the same for S2, S3, S4 and S5.
  3. A student says “the server with the longest log becomes leader”. Use your answers to refute it.
  4. Suppose S1 and S5 both become candidates in the same term, and S2’s request from S1 arrives first. Can S5 still win? Explain with the immutability of votes.

Problem 3

Problem 6.3 (Running the AppendEntries receiver).

A follower F is in term 3 with log 1, 1, 2, 2, 2 and commitIndex 1. It receives the following AppendEntries requests in this order (entries are written by their terms). For each, give F’s reply (term, success, matchedUpTo), its log and its commitIndex afterwards.

  1. term 3, prevLogIndex 3, prevLogTerm 3, entries none, leaderCommit 2.
  2. term 3, prevLogIndex 2, prevLogTerm 1, entries 3, 3, leaderCommit 2.
  3. term 3, prevLogIndex 2, prevLogTerm 1, entries 3, leaderCommit 2 (an older, delayed copy).
  4. term 2, prevLogIndex 4, prevLogTerm 2, entries 2, leaderCommit 5.
  5. term 3, prevLogIndex 4, prevLogTerm 3, entries 3, leaderCommit 5.

Finally: an implementation deletes everything after prevLogIndex on every successful request, conflict or not. Show what goes wrong in request 3.

Problem 4

Problem 6.4 (Counting the walk-back).

A leader of term 8 has log 1, 1, 1, 4, 4, 5, 5, 6, 6, 6 (this is the leader of the Raft paper’s Figure 7) and was just elected, so nextIndex is 11 for everyone.

  1. Follower X has log 1, 1, 1, 4. How many AppendEntries fail before one succeeds? What does X’s log look like afterwards?
  2. Follower Y has log 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3. Same questions; which entries of Y are deleted?
  3. Now use this optimization: on failure, if the follower has no entry at prevLogIndex it replies conflictIndex = its last index + 1; otherwise it replies conflictIndex = the first index of its log whose term equals the term of its entry at prevLogIndex. The leader sets nextIndex to conflictIndex. Redo parts 1 and 2.

Problem 5

Problem 6.5 (Randomized timeouts).

Use the model of Proposition 6.4, but let each election timer be uniform on with width .

  1. For servers, prove directly, by computing an area in the square , that the probability that the two timers fire more than apart is .
  2. State the formula for general (you may use the proof of Proposition 6.4 with replaced by ) and compute it for , ms and ms, and for with the same values.
  3. Explain the trade-off in choosing : what improves and what gets worse when grows?
  4. The model assumes equally up-to-date logs. Give an example with 5 servers in which the round is clean but the first candidate still loses, and say what happens next.