Walrus includes a formal TLA+ specification that models the distributed data plane, providing mathematical guarantees about system correctness under concurrent operations.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/nubskr/walrus/llms.txt
Use this file to discover all available pages before exploring further.
Specification Overview
The TLA+ specification models the core distributed Walrus data plane with:- Segment-based sharding: Topics split into numbered segments with independent leaders
- Lease-based write fencing: Only designated leaders can write to their segments
- Cursor advancement: Reader progression across sealed and active segments
- Raft abstraction: Metadata treated as single authoritative source
The specification is located at
distributed-walrus/spec/DistributedWalrus.tla in the source repository.Model Structure
Constants
The specification is parameterized by:| Constant | Description | Example Value |
|---|---|---|
Nodes | Set of node IDs eligible to lead segments | {1, 2, 3} |
Topics | Universe of topic names | {"logs", "metrics"} |
SegIds | Finite set of allowed segment IDs | {1, 2, 3} |
MaxSegmentEntries | Rollover threshold for segments | 2 (for model checking) |
State Variables
The system state consists of four variables:Actions
The specification models four core operations:CreateTopic
Initialize a new topic with a designated leader and first segment.
WalAppend
Append an entry to the current open segment (only by the leader).
Rollover
Seal the current segment and create a new one with a new leader.
Read
Advance the reader cursor within the current segment or move to the next sealed segment.
Verified Invariants
The TLC model checker verifies the following safety properties hold in all reachable states:Domain Consistency
Single Writer per Segment
No Writes Past Open Segment
Sealed Counts Stable
Read Cursor Bounds
Sequential Write Order
Liveness Properties
The specification verifies temporal properties ensuring the system makes progress:Rollover Progress
Interpretation
Interpretation
If a segment reaches the maximum entry threshold and another segment ID is available, the system will eventually roll over to a new segment.This ensures the monitor loop’s periodic checks will detect the threshold and trigger rollover via Raft consensus.
Read Progress
Interpretation
Interpretation
If unread entries are available in the current segment, the reader cursor will eventually advance to consume them.This guarantees that available data will not remain unread indefinitely under fair scheduling.
Model Checking Configuration
The TLC model checker configuration (DistributedWalrus.cfg):
Running the Model Checker
To verify the specification with TLC:The model uses small constants to keep the state space tractable. Larger values would explore more behaviors but require significantly more time and memory.
Abstraction Boundaries
The specification intentionally abstracts certain implementation details:Raft Consensus
Modeled as a single authoritative metadata source rather than the full Raft protocol with leader election and log replication.
Network Communication
Request forwarding and RPC calls are not explicitly modeled. The specification assumes reliable eventual delivery.
Storage Backend
Walrus engine abstracted as per-segment entry sequences. Actual WAL file format and I/O operations are not modeled.
Lease Synchronization
The 100ms sync loop is not modeled. The specification assumes leases are always consistent with metadata.
Limitations
The current specification does not model:- Node failures and recovery
- Network partitions and message reordering
- Concurrent readers with different cursors
- Batch operations
- Multi-topic interactions
Relationship to Implementation
The TLA+ spec validates the design of the distributed data plane. Implementation correctness requires:- Faithful translation: Code must implement the modeled actions correctly
- Proper synchronization: Rust’s type system and careful locking ensure thread safety
- Integration testing: The test suite validates end-to-end behavior
Further Reading
- TLA+ Homepage - Learn TLA+ specification language
- PlusCal Algorithm Language - Higher-level specification syntax
- Specifying Systems - Comprehensive TLA+ textbook