Unit 4 of 15 · about 6 hours · implement

Finite model bounds, TLC checking, counterexample traces and a two-phase commit specification

A commit protocol is where abstract checking meets the track's core. This safety-only model permits the blocking wait from the earlier unit on two-phase commit states, durable prepare, coordinator failure and in-doubt recovery; coordinator crash, persistence and recovery actions are left out, so add them before making recovery claims.

You'll be able to

  • Bound a protocol model (managers, values, queue lengths) and run TLC to a stated state count.
  • Read a TLC counterexample trace action by action and map each step to the spec action that enabled it.
  • Plant a bug, capture the first meaningful violating trace, and fix the spec or the invariant.

Covers

Finite model bounds and state explosionTLC safety and liveness checkingCounterexample trace interpretationTwo-phase commit specification
1

Read

In this order, only the parts listed

0 of 4 done

  1. Lecture 5: Transaction CommitTLA+ Video Course

    Full lecture (24:39): the abstract commit spec TCommit, including TCConsistent (no two RMs in conflict) and mathematical functions

  2. Lecture 6: Two-Phase CommitTLA+ Video Course

    Full lecture (21:22): how commitment is achieved; records in TLA+ and more TLC

  3. Lecture 7: Paxos CommitTLA+ Video Course

    Full lecture (19:46): a fault-tolerant commit algorithm; set construction and combination operations

    Watch for vocabulary, not for a second implementation. Your checked model in this unit is TwoPhase, not PaxosCommit.

  4. TwoPhase.tla and TCommit.tla with TwoPhase.cfgTLA+ Examples

    TwoPhase.tla (variables rmState, tmState, tmPrepared, msgs; actions TMRcvPrepared, TMCommit, TMAbort, RMPrepare, RMChooseToAbort, RMRcvCommitMsg, RMRcvAbortMsg; TPSpec == TPInit /\ [][TPNext]_<<rmState, tmState, tmPrepared, msgs>>) with TwoPhase.cfg (RM = {r1, r2, r3}, invariant TPTypeOK, SPECIFICATION TPSpec)

    Do not open specifications/TwoPhase/ elsewhere in the repo: it is a hardware handshake, not transaction commit.

2

Focus on

  • The header states the scope honestly: safety only, what is allowed. Liveness (what must happen) is not specified, so a run that commits nothing violates nothing.
  • Messages are never removed from msgs. Receipt is existence in the set, so duplicates are allowed and loss is modeled as never receiving.
  • TMCommit needs tmState = init and tmPrepared = RM; TMAbort needs only tmState = init. A prepared RM has no action of its own that decides, so it waits for a TM message the safety-only spec never forces to arrive: that is the blocking window.
  • The unchanged configuration checks TPTypeOK for three resource managers. The module also states THEOREM TPSpec => TC!TCSpec; to check it, define an alias for TC!TCSpec and select that alias as a temporal property in the model.
Common mistakes · 3
  • Assuming assigned constants make the run finite. Missing assignments are configuration errors; assigned constants still leave counters and queues unbounded, so bound them and record every restriction with the result.
  • Reading No error has been found as proved. It covers three resource managers and the configured invariant only; the file notes a separate six-RM check with 50816 reachable states.
  • Confusing specifications/TwoPhase/ with specifications/transaction_commit/TwoPhase.tla. The first is a hardware handshake and its model needs the TLAPS module to parse.
3

Try it yourself

Closed-book, before checking anything

From the Examples directory, run TLC on TwoPhase.cfg unchanged and get 1146 states generated, 288 distinct states found at depth 11 with No error has been found. Then assert a false invariant and read the violating trace to the committing action.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.What does TMCommit require, and what does TMAbort require?Answer

    Commit needs tmState = init and tmPrepared = RM, every manager prepared. Abort needs only tmState = init: the TM may abort spontaneously at any time before committing.

  2. 2.A prepared RM never receives a Commit or Abort message. Which property is violated?Answer

    None in this spec. It specifies safety only; the blocking wait is allowed. The violation would be against an unstated liveness claim.

  3. 3.What does a TLC trace line State 4: <RMPrepare ...> tell you?Answer

    State 4 is the state reached by applying RMPrepare to State 3. The source range names that action, and the /\ var = value lines below show the resulting state.

  4. 4.Your run reports 288 distinct states for three RMs. What changes with six RMs, and what stays the same?Answer

    The state count grows (the file notes 50816 reachable states); the spec text and the invariant are unchanged. Each bound is its own result.

  5. 5.What is TCConsistent, and which spec states it?Answer

    No two RMs in conflicting decisions (aborted versus committed), stated in TCommit.tla and asserted as THEOREM TCSpec => [](TCTypeOK /\ TCConsistent).

5

Practice

  • TLA+ Examples: check TwoPhase.tla with TLC

    With TLA2TOOLS set to your tools jar, run java -cp "$TLA2TOOLS" tlc2.TLC -workers 1 -config TwoPhase.cfg TwoPhase from specifications/transaction_commit/; with TLC 2.19 expect 1146 generated and 288 distinct states

    Then add a false invariant such as tmState /= "committed", keep the first violating trace, and map every step to its action before deleting it.

  • TLA+ Video Course Lecture 6: TwoPhase Commit model

    Rebuild the lecture's commit model in the Toolbox and check it

    Use the lecture for the construction habit; the Examples run above is the exact-numbers check.

You're done when

An unchanged Examples run reproduces 288 distinct states, and a planted false invariant yields a trace you can map action by action to the committing step.

Only when you can do this without notes.

Leads to

Notes

Resources · 2 for this unit, 13 more in the section
  • TLA+ Video CourseLeslie Lamport · primary

    Complete lectures 1 to 10 (lectures 8, 9 and 10 have two parts each) and check the corrections page, while specifying a reduced transaction, workflow or replicated-log model from the capstone. Run TLC after every extension, report the model bounds with every result, and retain the first meaningful counterexample rather than polishing only the final model.

  • TLA+ ExamplesTLA+ Foundation · support

    Check specifications/transaction_commit/ (TCommit.tla, TwoPhase.tla, PaxosCommit.tla with their .cfg files) with TLC alongside the lectures, and read the Paxos specifications for depth. specifications/TwoPhase/ is a hardware handshake, not transaction commit.

Also in this section

  • Cambridge Concurrent and Distributed Systems Notes (Kleppmann) - CRDTs and CollaborationUniversity of Cambridge (Martin Kleppmann) · support

    Use Section 8.1 (operation-based and state-based CRDTs, operational transformation) for the CRDT unit, and work Exercise 21 (prove the operation-based map CRDT converges) and Exercise 22 (its multi-value variant).

  • A Comprehensive Study of Convergent and Commutative Replicated Data Types (Shapiro et al., 2011)INRIA report (Berkeley course copy) · support

    Read Sections 1 to 3 (state-based and operation-based definitions, the semilattice and delivery conditions) and one example type for your implementation, not the whole catalog.

  • Learn TLA+Hillel Wayne · support

    Use the core lessons and the examples as a second explanation when a lecture stalls, and as the PlusCal reference if you write algorithms rather than raw actions.

  • Hypothesis - Stateful TestingHypothesis · required

    Use RuleBasedStateMachine against a reference model for property-based state-machine tests of your extension, keep the failing seeds and shrunk examples, and plant a bug to show the machine detects it.

  • MIT 6.5840 - Verification Lecture and Final ProjectMIT PDOS · required

    Study the Spring 2026 verification lecture and IronFleet reading, then use the final-project guidance to frame a bounded real-system extension, evaluation and report. Course grading and staff review are unavailable to self-study, so use the roadmap defense rubric.

  • Jepsen - Consistency Models and AnalysesJepsen · required

    Use the framework's generator, client, nemesis and checker roles to design the campaign, Knossos for single-register linearizability and Elle for transactional anomalies on recorded histories, and the public analyses for fault models. A simplified local checker must declare its object, model and completeness limits.

  • Elle: Inferring Isolation Anomalies from Experimental Observations (Kingsbury and Alvaro)arXiv · required

    Read how Elle infers version orders from list-append and register histories and detects cycles for G0 to G2. It needs complete histories, and a clean run is not a proof of serializability.

  • How Amazon Web Services Uses Formal Methods (Newcombe et al., 2015)Amazon Science · support

    Read it for why industrial teams specify designs in TLA+ and which bugs model checking found that testing missed. Its effort figures are anecdotes, not benchmarks.

  • FoundationDB: A Distributed Unbundled Transactional Key Value Store (Zhou et al., 2021)FoundationDB · support

    Read the simulation-testing section (deterministic single-threaded simulation, fault injection, seed replay) as the model for your own scheduler, and the architecture for unbundled transactions.

  • DDIA 2e - Chapters 9, 10 and 14 ReviewMartin Kleppmann and Chris Riccomini · required

    Revisit uncertainty, consistency, consensus and responsible system design while extracting the final contract. Use the book to challenge assumptions and alternatives, not to replace executable evidence.

  • HLD Handbook - CRDTs, Multi-Region and Architecture Trade-offsHLD Handbook · support

    Read the CRDT, multi-region, distributed SQL and relevant case-study chapters only after the formal core passes. Use its design prompts to prepare the final comparison and defense.

  • CMU 15-721 - Selected Advanced Database Systems UnitsCarnegie Mellon Database Group · depth

    Select at most one lecture group that informs your extension: #02 and #03 (data formats and encoding), #08 (scheduling and coordination) or #17 to #22 (system analyses such as BigQuery, Databricks, Snowflake, DuckDB and Redshift), with their papers. The course project needs a group, cloud credits and staff sign-off, so there is no runnable self-study project.

  • Replicated Log and Stream Processor - Final CapstoneRoadmap-Final · support

    Finish the protocol and invariant specification, deterministic fault campaign, bounded real-code extension, fallback, ablations, workload regions, negative result, operations dossier and independent reproduction package.