TL;DR
Conflict-free Replicated Data Types (CRDTs) are crucial for building highly available distributed systems, but their complex nature makes them notoriously difficult to design and implement correctly. This paper introduces the Model Checking-driven Explorative Testing (MET) framework, which bridges the gap between formal design verification and practical code testing to uncover subtle, hard-to-find bugs in CRDTs.
What Problem Does This Paper Address?
Internet-scale distributed systems rely on data replication for availability and low latency. CRDTs are a popular framework for managing this replicated data, ensuring eventual consistency even with network partitions and failures. However, the core challenge lies in correctly handling concurrent updates and resolving conflicts. CRDTs are prone to "deep bugs" – subtle errors that manifest only under specific, rare interleavings of events and are difficult to reproduce with traditional testing methods. Existing approaches often rely on informal designs and manual reviews, which are insufficient for guaranteeing correctness due to the inherent complexity and the difficulty of human reasoning about all possible concurrent scenarios. This paper aims to provide a systematic and cost-effective way to find and fix these deep bugs in both CRDT designs and their implementations.
Methods
The MET framework operates in two layers:
- Design Layer (Model Checking):
- CRDT designs are formally specified using Temporal Logic of Actions (TLA+). This allows for precise definition of protocols and correctness properties (like eventual consistency).
- The Temporal Logic of Actions (TLA+) specifications are then model-checked using the TLC model checker. To combat the state explosion problem, MET employs two key techniques:
- Coarsening the Specification: The TLA+ model is simplified by "gluing together" send, receive, and do events, focusing on the core conflict resolution logic while pruning unnecessary interleavings.
- Limiting Model Scale: The "small scope hypothesis" is leveraged, meaning small numbers of replicas (e.g., 3) and client requests are used, as empirical studies suggest most bugs can be triggered in such small configurations.
- Implementation Layer (Explorative Testing):
- Test Case Generation: Model checking traces from the design layer are automatically translated into test cases for the implementation. These traces provide both the test input (event schedule) and the test oracle (expected sequence of system states).
- Testability Enhancement: To deterministically replay model checking traces and observe internal states, MET enhances system controllability and observability:
- Controllability: The networking component of CRDT replicas is "hacked" to redirect all communication through a central test manager. This manager precisely controls the timing and order of events, forcing the implementation to follow the model checking trace.
- Observability: Dedicated APIs are added to the CRDT implementation to allow the test manager to inspect the internal state of replicas, enabling direct comparison with the model checking trace.
Datasets
Not discussed in the paper. The authors focus on applying their framework to their own CRDT implementations (RWF-RPQ and RwF-List) and do not present results on external datasets.
Key Insights and Ideas
- Bridging the Formal-Code Gap: The core innovation is the systematic connection between formal model checking of a design and concrete testing of its implementation. This allows for the exhaustive exploration of the design space to guide targeted testing of the code.
- "Known Unknowns" are the Target: The paper argues that the most critical bugs in CRDTs are "known unknowns" – bugs whose general mechanism is understood but are hard to trigger and fix with traditional methods. MET is designed to efficiently find and fix these.
- Small Scope Hypothesis is Practical: The empirical evidence and theoretical argument for using small system instances (few replicas) to find deep bugs in distributed systems is a key enabler for MET's practicality.
- Testability is Crucial: The paper highlights that making the system controllable and observable is paramount for effective model-checking-driven testing. Hacking the networking and adding inspection APIs are key to achieving this.
- Formalization Forces Clarity: The process of formalizing CRDT designs in TLA+ itself helps uncover ambiguities and leads to cleaner, more robust designs, as seen in the separation of the "re-add" operation.
Key Results
- The MET framework was applied to the design and implementation of RWF-RPQ and RwF-List CRDTs.
- Seven bugs were found and fixed, including:
- One bug (Issue #1) that could be found by stress testing but was fixed at a much lower cost with MET.
- One bug (Issue #2) detectable by manual explorative testing, which MET automates.
- Four bugs (Issues #4-#7) that could only be detected by MET, including transcription errors and assumption bugs.
- The model checking phase significantly reduced the cost of fixing bugs compared to traditional methods.
- The authors report increased confidence in the correctness of their CRDT designs and implementations due to the systematic and exhaustive nature of MET.
- The cost of model checking was found to be faster than explorative testing, with the overall cost being reasonable and manageable.
Limitations and Future Work
- Threats from System Modeling: MET cannot detect bugs in aspects of the system that are not modeled (e.g., hardware failures, complex network behaviors beyond message reordering). The authors argue this is acceptable as MET targets "known unknowns" rather than "unknown unknowns."
- State Space Pruning: While MET aims for exhaustive exploration, the state space is still pruned to manage costs. The authors rely on the small scope hypothesis and careful pruning to ensure critical bugs are not missed.
- Future Work:
- Apply MET to other types of distributed systems (e.g., consensus components, atomic commit components).
- Explore heuristic exploration strategies and parallel checking frameworks to further tame state explosion.
Summary updated