Diffinery

homeflare/celldpublic

celld/docs/testing.md
187 lines · 9.7 KBRaw History
1# Testing
2
3celld makes three promises:
4
5- An acknowledged write is durable.
6- A cell has one writer at a time.
7- Code written for Cloudflare Workers and Durable Objects operates the
8 same on celld.
9
10We try to break each promise at the layer where a failure shows most
11clearly. We test the API contract with differential execution against the
12Cloudflare runtime. We check the coordination protocol against an
13exhaustively model-checked specification, and we test it with
14deterministic simulation. We test the full system with fault injection
15on live fleets.
16
17## Conformance: two runtimes, one output
18
19We run the same Workers and Durable Objects program on both workerd,
20Cloudflare's production runtime, and celld. The two outputs must match,
21so each test checks celld against the Cloudflare runtime.
22The reference output comes from workerd, so the expected behavior does
23not depend on the celld implementation.
24
25We expand the corpus with fixtures for each new API, and each fixture must
26give the same output on both engines. We also port test suites from workerd:
27the Durable Objects contract, the web-platform globals, and the upstream
28Web Platform Tests. Before a release, we replay storage, SQL, alarm,
29stream, WebSocket, and lifecycle scenarios through the full `celld` binary
30in each deployment mode.
31
32## Specification: exhaustive at small size
33
34The coordination protocol is also specified in TLA+. Heyang Zhou wrote
35the specifications against celld v0.1.0, and his model checking found
36four bugs and a split-brain that lost an acknowledged write. All are
37fixed. None had surfaced in our own review or testing.
38
39Where simulation samples schedules, the checker enumerates them: at a
40small configuration it visits every reachable state. The model grants
41the implementation a linearizable object store and perfect shared
42clocks, so a violation it finds needs no clock skew and no storage
43anomaly to occur. The invariants are the first two promises at the top
44of this page: one writer for each epoch, and no acknowledged write
45lost. The checker also verifies that the epoch in the key prevents a stale
46owner's late writes from causing the loss of an acknowledged write.
47
48Every configuration carries a pinned expected verdict, and most of the
49verdicts are failures: each failing configuration models a bug the
50protocol once had, or a deliberately broken checker, and the model
51must produce the counterexample. If a configuration stops producing its
52expected failure, we investigate and repair the check.
53
54Some specifications model a proposed protocol before it is built. When
55the fence on write acknowledgments was redesigned, the design-stage
56check produced an eight-state counterexample against the version it
57replaced: a dormant cell resumes at its old epoch while its release is
58in flight, acknowledges a write, and the takeover that follows
59restores without it. The fix shipped; the counterexample stays as a
60pinned failure.
61
62The checker has also removed code: celld once sealed a cell's durable
63history at restore, and the verdicts showed the seal defended only the
64return of an unacknowledged write, which celld does not promise to prevent.
65The seal could also turn a recoverable ordering error into permanent data
66loss, so celld no longer uses it.
67
68We update the specifications manually alongside the protocol changes.
69They do not run in continuous integration, because an outdated model can
70give false confidence. A separate record tracks what the model does not
71yet describe, including guarantees weaker than those in the code.
72Simulation checks each commit, and model checking adds exhaustive coverage
73of small configurations.
74
75## Simulation: the protocol under adversarial schedules
76
77The dangerous bugs live in the coordination: a crash during an ownership
78handoff, a lease renewal that races a takeover, an alarm that fires
79against a partially restored cell. These windows are nanoseconds wide and
80open rarely, so a test cannot wait for them.
81
82Thus the coordination protocol is a
83[pure decision core](https://github.com/denoland/celld/tree/main/crates/logic)
84with no I/O of its own: the clock, the randomness, and the object store
85are interfaces, and a simulator drives the core. The simulated store
86injects latency, compare-and-swap races, and lost responses; the clocks
87drift apart; a node can crash at each await point. Scripted adversaries
88play the cells: a handler that never returns, a write stream that stops
89halfway. V8 stays out of the simulation, because V8 is not deterministic.
90
91A seeded scheduler drives each run, so we can reproduce a failure exactly
92and keep its seed until we fix the bug. We check safety properties for
93two writers in one epoch, a lost acknowledged write, and an expired lease
94that returns. We also check liveness: each armed alarm fires, and ownership
95settles on one node after a crash. A property must survive tens of thousands
96of seeds, and the core protocols have run through millions of different
97schedules.
98
99We also run deliberately broken variants of the protocol to verify that
100the checkers detect the faults. A checker that accepts a broken protocol
101cannot protect the corresponding property.
102
103## Live fleets: what simulation cannot see
104
105Simulation cannot see the real S3 tail latency, the real kernel and
106filesystem behavior, or V8 under memory pressure. The third layer is
107therefore a permanent fleet lab: standard VMs from standard providers,
108and a real bucket. The workloads rotate: chat rooms under many WebSocket
109connections, working sets that shift across tens of thousands of cells
110(each cell has a unique checksum), deployment cutovers under load, and
111runs that fill the nodes to the memory limit. The lab qualifies each
112release and tests greater density and more faults between releases. We
113archive each run's configuration, verification sweeps, node journals,
114kernel logs, and phase timings. We preserve failed runs as well as
115successful ones, because both provide evidence of the system's behavior.
116
117We inject the faults between verification passes. A pass fetches each
118cell through different nodes and compares the durable state exactly: the
119status, the body, and the full message ledger. Each run therefore records
120the state before and after the fault. A cell can be unavailable for a short
121time while its ownership moves, but its committed state must
122stay complete, and a live node must serve that state again.
123
124The scenarios attack every seam that we know:
125
126- Stop a node with `SIGKILL` in the middle of a write stream and delete
127 its local database, so recovery can only come from the bucket. Every
128 acknowledged write comes back, because the output gate held each
129 response until the write was durable.
130- Freeze an owner node, write to its cells through other nodes, and
131 unfreeze it. The node sees that its lease moved and refuses to serve
132 the old state, and each write from the other nodes lands exactly one
133 time: one epoch has at most one writer.
134- Cut a node off from the bucket. It fences itself, because a node that
135 cannot replicate must not own cells.
136- Throttle the bucket, so it answers each request with a 429. The engine
137 slows to the write rate of the store and does not amplify the
138 throttle, because a node that knows its replicated position does not
139 ask a slow store for extra listings.
140- Stop a full host at the provider level in the middle of a workload.
141 Its cells move to the other nodes, and the returning host joins again
142 with no duplicate residency.
143
144Across every run of every scenario, no acknowledged write was lost and
145no committed state was damaged; the verification sweeps show zero body
146faults, zero status faults, and zero lost messages.
147
148## A few numbers we trust
149
150Each number includes its measurement conditions, so you can assess whether
151it applies to your workload.
152
153- **The epoch fence holds under contention.** Five hundred claimants
154 tried at the same time to own the same cells: 5,500 attempts, one
155 writer for each epoch, zero violations.
156- **A warm resident request is local.** A request to a resident cell does
157 zero bucket operations and returns in p50 ~1.1 ms and p99 ~7 ms (a
158 fixed-host measurement). Only a cold activation touches object storage.
159- **A durable write waits for a durability proof.** A single node proves
160 each write through the bucket, so one storage round trip is the minimum
161 latency for that write. A fleet of two or more nodes can prove a write
162 when each follower holds it on disk, and a follower fsync is much
163 faster than a storage round trip: a lab fleet measured about 600 ms for
164 a bucket proof and about 25 ms for a fleet proof. The bucket upload
165 races every fleet proof and either one proves the write, so a slow
166 follower cannot make a write slower than a bucket proof. Concurrent
167 writes to one cell join one shared upload, so the throughput of one
168 cell is not one round trip for each write.
169- **A restore is normal work.** Placement handles the restore of an
170 inactive cell as ordinary work, and not as an emergency procedure. The
171 measured restore times come from the retired external replicator, so this
172 page gives no number until a fleet run measures `celld-ltx`.
173- **Ten small nodes held real scale.** A fleet of ten nodes, each with 4
174 vCPU and 8 GB, held 10,000 resident cells and 20,000 concurrent
175 WebSocket connections. We stopped two of the ten nodes, and the data of
176 every cell was available again on another node in ~11 s at the tail
177 (with reserve headroom).
178
179## The failure edges we intend to find
180
181A fleet at its resident limit has no space for the cells of a lost node,
182so the loss of multiple nodes degrades the service. We test recovery with
183and without reserve capacity to measure this limit.
184
185Report a schedule that breaks a guarantee, a fault that we do not test,
186or a measurement that you cannot reproduce in the
187[issue tracker](https://github.com/denoland/celld/issues).