This set practises the leader’s adoption step, the replica’s slot bookkeeping, and the invariants of Paxos Made Moderately Complex: what each says, which line of code enforces it, and how the safety proof chains them together.
Problem 1
Problem 9.1 (pmax and the update operator).Ballots are written
and compared lexicographically. Let and let a leader’s proposals be
.
- Compute
. - Compute
and list the commanders the leader spawns after adoption. - Is
the same set? Which order does the leader use, and why is the other order unsafe?
Solution
- Slot 1: ballots
, keep . Slot 2: only . Slot 4: , keep . So . - Every pair of
is kept, and from only slot 3 survives (slots 2 and 4 appear in ): . The leader spawns four commanders with its ballot: for , , , . - No:
. The leader uses : reported votes override its own proposals. The other order could replace in slot 2 by the leader’s own ; if had been chosen at ballot , that would violate C2 and eventually R1.
Problem 2
Problem 9.2 (Adoption trace).Three acceptors A1, A2, A3 are in the following state (pvalues in
accepted):
- A1:
ballot_num, accepted ; - A2:
ballot_num, accepted ; - A3:
ballot_num, accepted . Leader L2 is inactive with
ballot_numand proposals.
- Which commands can already be chosen, in which slots? Justify.
- L2’s scout for
sends p1a to all acceptors. Give each reply and say what the scout does. - L2 then uses ballot
and its scout hears from A2 and A3 first. Give pvals, the newproposals, and the commanders spawned.- Same as part 3 but the scout hears from A1 and A2. What changes? Explain why both outcomes are consistent with part 1.
Solution
- Slot 1:
is accepted by all three, so is chosen in slot 1. Slot 2: is accepted only by A1 and only by A2, so nothing is chosen yet in slot 2 (each pvalue has one vote). Slot 3: nothing. - Each acceptor’s
ballot_numis larger than, so none adopts it; replies are p1b(A1, (2,L1), ...),p1b(A2, (2,L1), ...),p1b(A3, (1,L1), ...). The first reply has a ballot different from, so the scout sends preempted((2, L1))(orif A3 answers first) and exits. L2 sets ballot_num(or ) and starts a new scout. - A2 and A3 adopt
(it is larger than theirs) and report their sets: . , and proposals. Commanders: , , . L2’s own is dropped (its replica will re-propose it). - Now
contains both and ; pmax picks the larger ballot, so slot 2 gets instead of . Slot 1 still gets and slot 3 still . Both outcomes are fine: slot 1’s chosen is preserved in both (every majority contains an acceptor that accepted it), and slot 2 had nothing chosen, so either or may become the decided command.
Problem 3
Problem 9.3 (A replica with WINDOW = 2).A replica starts with
slot_in = slot_out = 1, empty sets and. The following events happen in order:
- request
; 2. request ; 3. request ; 4. decision ; 5. decision ; 6. decision ; 7. decision . After each event, give
slot_in,slot_out,requests,proposals, and the commands applied so far. Assumeproposepicks requests in index order. Which invariant explains why the replica does not proposeat event 3? What happens to at event 7?
Solution
- Event 1: propose
for slot 1; slot_in= 2,slot_out= 1, requests, proposals . - Event 2:
, propose for slot 2; slot_in= 3, proposals. - Event 3:
is false, so waits: requests . This is R5: the replica proposes only for slots , i.e. slots whose configuration it knows (the configuration of slot 3 depends on slot , which is not decided yet). - Event 4: slot 2 decided but
slot_out= 1 is undecided: nothing applied. Thenproposestill blocked. State unchanged except decisions.- Event 5: slot 1 decided
: remove from proposals and put back into requests; apply , slot_out= 2. Slot 2 is decided, matching the proposal: remove it, apply , slot_out= 3. Thenpropose: slot 3 () gets (index order), slot 4 gets ; slot_in= 5. Requests, proposals . Applied: . - Event 6: slot 3 decided
, matches; apply , slot_out= 4. Applied:. - Event 7: slot 4 decided
, but the replica proposed there: goes back into requests. performseesalready decided in slot 3 4, so it is not executed again; slot_out= 5.proposesendsfor slot 5; slot_in= 6. Applied: still. (A decided duplicate such as in slot 4 can happen when another replica also proposed .)
Problem 4
Problem 9.4 (Which invariant is violated?).Each scenario describes a buggy implementation. Name the invariant it violates first (from A1-A5, C1, C2, R1-R5) and describe an execution in which the bug leads to two replicas deciding different commands for the same slot, or explain why it cannot.
- An acceptor that receives a p2a with
accepts it anyway and replies p2b(self, b). - A leader, on propose
while active, spawns a commander even if proposalsalready has a different command for slot. - A replica that restarts sets
slot_out := 1and re-applies all decisions to a fresh state.- On adopted, the leader sets
proposals := pmax(pvals) <| proposals.- To save memory, an acceptor deletes from
acceptedevery pvalue for slots it has already seen decided.
Solution
- A2. Execution: L1 is active with
and sends p2a , which is delayed. L2’s scout for is adopted by A2 and A3, which report nothing for slot ; L2’s commander gets accepted by A2 and A3 and decides . Now L1’s delayed p2a reaches A1 and A2; with the bug both accept it and reply p2b , so L1’s commander decides . Two replicas may decide and in slot : R1 is violated. The correct code refuses at A2 (A2 rule) and replies with , which preempts L1. - C1 (and hence A4). Two commanders for
carry . Every acceptor at ballot accepts every p2a with ballot , so A2 can accept both. Let A1 and A2 accept and A2 and A3 accept : the first commander decides with , the second decides with , and R1 is violated. - R4 is violated (
slot_outdecreases). Safety of the log is not affected: R1 holds and re-applying the same decided commands in order rebuilds the same state, so no two replicas disagree. The real harm is outside the model: responses are sent to clients again, and any effect outside the state machine is repeated.- C2 via the leader rule: own proposals override reported votes. If
was chosen in slot at ballot and the new leader has its own , it spawns a commander for with , and a later majority accepts : two decisions in slot , R1 is violated. This is the Module 8 no-adoption bug. - A3. A replica can see slot
decided while other replicas and future leaders have not. A new leader’s scout may then hear only from acceptors that deleted the pvalue, find nothing for slot , and propose its own command there: C2 and then R1 fail. Deleting is safe only for slots that all replicas have applied (and a new leader must then not propose for them at all, e.g. by starting from a snapshot).
Problem 5
Problem 9.5 (From C2 to R1).Assume C1 and C2 as proved in the module.
- Prove A5: if a majority has
in acceptedand some acceptor haswith , then . - Prove that if a replica receives decision
, then for some ballot a majority of acceptors have in accepted. Point to the exact lines of the acceptor and commander code you use.- Conclude R1.
- Where exactly would the proof of part 3 fail if acceptors used “any two” instead of “a majority” with five acceptors?
Solution
- Acceptors add pvalues only in the p2a handler, and only the commander for
sends a p2a with that pvalue. So a commander for was spawned with , and C2 gives . - The commander for
sends decision only after waitforhas shrunk below half of the acceptors, i.e. after p2bfrom a majority (it removes only when the reported ballot equals ). Each sends p2b with its current ballot_numin the same atomic step in which it testedb == ballot_numand, if true, added the pvalue. The reported value is, so the test was true and added ; by A3 it keeps it forever. - Let
and be decided, with ballots from part 2. If , the commanders for and are the same by C1, so . If , a majority has and a commander for was spawned, so C2 gives . - Part 3 itself would go through, but C2 would be false: its proof needs the decision quorum
and the scout quorum to intersect. With five acceptors, (decision) and (scout) are disjoint, so a later leader may never see the chosen pvalue and pick a different command. In general it suffices that every Phase-1 quorum meets every Phase-2 quorum (Homework 8, Problem 5).