This set practises the voting rules, the term rules, and the quorum argument behind Election Safety.
Problem 1
Problem 5.1 (Majorities and failure detectors).
- For
servers, give the number of votes a candidate needs and the largest number of crashed servers with which an election can still succeed. - A cluster is configured with 10 servers and 2 of them are down for maintenance (lecture 07.02). How many votes does a candidate need? Explain in two sentences why “a majority of the 8 live servers” would be unsafe.
- Why does a 4-server cluster tolerate no more crashed servers than a 3-server cluster?
- A follower suspects the leader after hearing nothing for 200 ms. Is this failure detector perfect, eventually perfect, or neither, in a partially synchronous system? Justify in one or two sentences.
Solution
- The majority is
: 2, 3, 3, 4, 4 votes for . An election succeeds as long as that many servers are up and connected, so : 1, 1, 2, 2, 3. - It needs
votes. A server cannot tell a crashed peer from one on the other side of a partition; if each side counted only what it can reach, a 5 and 5 split would let each side elect a leader with 3 votes, in the same term, violating Election Safety. - With
a majority is 3, so only one server may be missing, exactly as with (majority 2). The fourth server adds load and one more voter without adding fault tolerance; this is why clusters have odd sizes. - It is not perfect: by Proposition 5.2, a leader whose heartbeats are delayed by more than 200 ms (allowed before the network stabilizes) is wrongly suspected. It is eventually perfect, provided it stops suspecting a server as soon as a heartbeat arrives and the heartbeat period plus the eventual delay bound is below 200 ms: after stabilization the gap between heartbeats stays below the timeout, and a crashed leader is suspected forever.
Problem 2
Problem 5.2 (Tracing two elections).Five servers A to E start as followers in term 0 with no vote. Logs are empty, so the up-to-date check always passes.
- A and E time out at the same moment and both start an election. A’s RequestVote reaches B and C before E’s does; E’s reaches D before A’s. Afterwards all remaining requests and replies are delivered. Give the final (role, currentTerm, votedFor) of every server, and say who leads which term.
- Next, A’s heartbeats to D are lost for a while, so D times out. Its RequestVote reaches every server, including A. Give the new (role, currentTerm, votedFor) of every server after all requests and replies are delivered. What happens to A, and why?
- Much later a delayed reply VoteReply(term 1, granted) from C to E arrives. What does E do with it, and which line of the pseudocode decides?
Solution
- Both A and E move to term 1 and vote for themselves. B and C grant A (first request of term 1 they see) and later refuse E (already voted). D grants E and later refuses A. E refuses A and A refuses E (each voted for itself). A has votes from A, B, C, three of five, and becomes leader of term 1. E has E and D, two votes, and stays a candidate. Final states: A (leader, 1, A); B (follower, 1, A); C (follower, 1, A); D (follower, 1, E); E (candidate, 1, E), until E receives A’s first heartbeat of term 1, after which E is (follower, 1, E).
- D starts term 2 and votes for itself. Every other server sees term 2 > 1, applies the adopt rule (term 2, vote cleared, follower) and then grants D’s request because its vote is null. A is among them: on seeing term 2 it stops being leader. Final states: D (leader, 2, D) and A, B, C, E all (follower, 2, D). D has five votes.
- E is a follower in term 2. The reply carries term 1 < 2, so it is stale; the vote-counting handler returns immediately because
state != candidate(and alsoterm != currentTerm). Counting it would be wrong: it is a vote for E in term 1, not in the current term.
Problem 3
Problem 5.3 (A stale leader across two partitions).Five servers A to E; C is leader of term 2 and every server is in term 2. The network splits into {A, C} and {B, D, E}.
- Can {B, D, E} elect a leader? If yes, in which term at the earliest, and with which votes?
- Meanwhile C asks its side to acknowledge a request of term 2. Which acknowledgements can it collect, and can it reach a majority?
- Suppose B was elected leader of term 3 by B, D, E. The partition now changes to {A, C, D} and {B, E}. C sends a term-2 request to A and D. What does each reply, and what does C do next?
- Can B still collect a majority of term-3 acknowledgements? Can {A, C, D} elect a new leader, and in which term at the earliest?
Solution
- Yes. One of them, say B, times out, moves to term 3 and votes for itself; D and E adopt term 3 and grant. B has 3 of 5 votes and leads term 3. Term 3 is the earliest, because everyone was in term 2.
- Only A (and C itself) can answer, so C can collect at most 2 acknowledgements, below
. C cannot complete any decision, although it still believes it is the leader. - A is still in term 2 and acknowledges. D is in term 3, so it refuses by the reject rule and replies with term 3. On receiving that reply, C applies the adopt rule: currentTerm 3, vote cleared, follower. C has learned that it was voted out.
- B can reach only E, so at most 2 acknowledgements: no. B is now a stale leader of term 3. {A, C, D} can elect a leader, but not in term 3: a term-3 winner on this side would need all three of A, C, D, and D has already voted for B in term 3 (C’s term-3 vote is free, since adopting term 3 cleared it, but two votes are not enough). So the first successful election is in term 4, for example D times out, moves to term 4, and gets the votes of C and A. Once that happens, Proposition 5.12 says B can never again collect a fresh majority in term 3.
Problem 4
Problem 5.4 (Is this execution allowed?).For each statement about a run of the protocol of Module 5 (5 servers, correct implementation), say whether it can happen. If not, name the rule or result it contradicts.
- At the same instant, A is leader of term 3 and B is leader of term 4.
- A is leader of term 4 at 10:00, and B is leader of term 4 at 10:05 (A crashed in between).
- After a restart, C’s currentTerm is 3; before the crash it was 5.
- C votes for B in term 4 and for D in term 5.
- C votes for B in term 4, crashes, restarts, and votes for D in term 4.
- D is elected leader of term 4 by C, D, E. Afterwards, A, leader of term 3, receives acknowledgements of a term-3 request from A, B and C, all sent after D’s election.
- With D and E crashed, C becomes leader with the votes of A, B and C.
Solution
- Allowed. Election Safety is per term (Theorem 5.10); A is a stale leader.
- Not allowed. Election Safety forbids two different leaders of term 4 at any times, not only simultaneously. B’s voters and A’s voters would share a server that voted twice in term 4.
- Not allowed if C ever sent a message or a vote with term 4 or 5: by Lemma 5.5 (claim 2) its term can then never drop below that term, because the term is persisted before C acts on it. The one exception is harmless: if C adopted term 5 from an incoming message and crashed before persisting it or acting on it, it restarts in its stored term, which may be 3 (Remark 5.6). No other server can tell this run from one in which the message was lost.
- Allowed: one vote per term, and the vote is cleared when the term increases.
- Not allowed: Lemma 5.9; votedFor is persistent, so after the restart C still has votedFor B in term 4.
- Not allowed: by Proposition 5.12, C (a voter for D in term 4 and an acknowledger for A) must have acknowledged before it voted; an acknowledgement after its term-4 vote is impossible because its currentTerm is then at least 4 and it rejects term-3 requests.
- Allowed: 3 of the 5 configured servers is a majority, whatever the others are doing.
Problem 5
Problem 5.5 (Election Safety for general quorum systems).Replace “majority” in voting rule 3 by “a set in
”, where is a fixed family of subsets of the servers (a quorum system). The other rules are unchanged.
- Prove: if every two sets in
intersect, then at most one server becomes leader in each term. - Prove: if
contains two disjoint sets and , then there is an execution in which two different servers become leader in the same term. - Let the servers be A, B, C, D and let
consist of and all sets of three or more servers. Show that every two sets in intersect. Which sets of two crashed servers can this system survive, compared with majorities of 4?
Solution
- Repeat the proof of Theorem 5.10 with the intersection property in place of Lemma 5.8. If
both lead term , they hold term- votes from quorums ; by assumption some ; then voted for and for in term , contradicting Lemma 5.9 (which does not depend on the quorum system). - Since
, pick and ; they are different. Let all servers be in term 0 with no vote. Let and time out together and both move to term 1, voting for themselves. Deliver ‘s RequestVote first to all of and ‘s first to all of ; these sets are disjoint, so every receiver sees exactly one request first and grants it. Then holds votes from all of and from all of , and both become leader of term 1. - A set of three or more servers out of four misses at most one server, so it contains A or B; hence it meets
. Two sets of size at least 3 out of 4 have at least common servers. And meets itself. So all pairs intersect. With majorities of 4 (quorum size 3), any two crashes stop elections. This system survives the crash of C and D (the quorum remains), but no other pair: if A or B crashes together with any other server, only two servers remain and they are not . The price is that A and B become more important than C and D.