Diffinery

homeflare/celldpublic

celld/docs/testing.md
145 lines · 7.4 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 same on
8 celld.
9
10We test the API contract by differential execution against workerd, the
11coordination protocol by model checking and deterministic simulation, and the
12full system by fault injection on live fleets.
13
14## Conformance: two runtimes, one output
15
16We run the same Workers and Durable Objects programs on workerd, Cloudflare's
17production runtime, and on celld, and the outputs must match. workerd supplies
18the reference output, so the expected behavior does not depend on celld.
19
20Each new API adds fixtures to the corpus. We also port the workerd Durable
21Objects contract tests, its web-platform globals tests, and the upstream Web
22Platform Tests. Before a release, we replay storage, SQL, alarm, stream,
23WebSocket, and lifecycle scenarios through the full `celld` binary in each
24deployment mode.
25
26## Specification: exhaustive at small size
27
28The coordination protocol is specified in TLA+. Heyang Zhou wrote the
29specifications against celld v0.1.0. His model checking found four bugs and a
30split-brain that lost an acknowledged write. All are fixed. None had surfaced
31in our own review or testing.
32
33At a small configuration, the checker visits every reachable state. The model
34grants a linearizable object store and perfect shared clocks, so a violation
35needs no clock skew or storage anomaly. The invariants are one writer for each
36epoch and no lost acknowledged write. The checker also verifies that the epoch
37in the key stops a stale owner's late writes from losing an acknowledged write.
38
39Each configuration pins an expected verdict, and most verdicts are failures:
40each models a past protocol bug or a deliberately broken checker, and must
41produce its counterexample.
42
43A redesign of the write-acknowledgment fence was checked before it was built.
44The check found an eight-state counterexample against the old version: a
45dormant cell resumes at its old epoch while its release is in flight,
46acknowledges a write, and the following takeover restores without it. The fix
47shipped, and the counterexample stays as a pinned failure.
48
49The checker also removed code. celld once sealed a cell's durable history at
50restore. The verdicts showed that the seal only prevented the return of an
51unacknowledged write, which celld does not promise, and that it could turn a
52recoverable ordering error into permanent data loss.
53
54We update the specifications by hand with protocol changes. They do not run in
55continuous integration. A separate record tracks what the model does not yet
56describe, including guarantees weaker than the code's.
57
58## Simulation: the protocol under adversarial schedules
59
60The dangerous bugs are in coordination: a crash during an ownership handoff, a
61lease renewal that races a takeover, an alarm against a partially restored
62cell. These windows are too narrow and too rare to wait for.
63
64The coordination protocol is therefore a
65[pure decision core](https://github.com/denoland/celld/tree/main/crates/logic)
66with no I/O. The clock, the randomness, and the object store are interfaces
67that a simulator drives. The simulated store injects latency, compare-and-swap
68races, and lost responses. The clocks drift, and a node can crash at each
69await point. Scripted adversaries play the cells, such as a handler that never
70returns or a write stream that stops halfway. V8 is not deterministic, so it
71stays out of the simulation.
72
73A seeded scheduler drives each run, so a failure reproduces exactly. We check
74safety (two writers in one epoch, a lost acknowledged write, an expired lease
75that returns) and liveness (each armed alarm fires, ownership settles on one
76node after a crash). A property must survive tens of thousands of seeds, and
77the core protocols have run through millions of schedules. Deliberately broken
78protocol variants verify that the checkers detect the faults.
79
80## Live fleets: what simulation cannot see
81
82Simulation cannot see real S3 tail latency, real kernel and filesystem
83behavior, or V8 under memory pressure. A permanent fleet lab runs standard VMs
84from standard providers against a real bucket. Workloads rotate: chat rooms
85with many WebSocket connections, working sets that shift across tens of
86thousands of checksummed cells, deployment cutovers under load, and nodes
87filled to the memory limit. The lab qualifies each release. We archive each
88run's configuration, verification sweeps, node journals, kernel logs, and
89phase timings, including failed runs.
90
91Faults land between verification passes. A pass fetches each cell through
92different nodes and compares the status, the body, and the full message
93ledger. A cell can be briefly unavailable while ownership moves, but its
94committed state must stay complete and a live node must serve it again.
95
96The scenarios:
97
98- `SIGKILL` a node mid-write-stream and delete its local database, so recovery
99 comes only from the bucket. Every acknowledged write returns, because the
100 output gate held each response until the write was durable.
101- Freeze an owner, write to its cells through other nodes, and unfreeze it.
102 The node sees that its lease moved and refuses to serve the old state. Each
103 write lands exactly once.
104- Cut a node off from the bucket. It fences itself.
105- Throttle the bucket to 429 on every request. The engine slows to the store's
106 rate and does not amplify the throttle.
107- Stop a full host at the provider level mid-workload. Its cells move to other
108 nodes, and the returning host rejoins with no duplicate residency.
109
110Across every run of every scenario, the verification sweeps show zero body
111faults, zero status faults, and zero lost messages.
112
113## A few numbers we trust
114
115- **The epoch fence holds under contention.** Five hundred concurrent
116 claimants made 5,500 attempts on the same cells: one writer for each epoch,
117 zero violations.
118- **A warm resident request is local.** A request to a resident cell does zero
119 bucket operations and returns in p50 ~1.1 ms and p99 ~7 ms (a fixed-host
120 measurement). Only a cold activation touches object storage.
121- **A durable write waits for a durability proof.** A single node proves each
122 write through the bucket, so one storage round trip is the minimum. A fleet
123 of two or more nodes can instead prove a write when each follower holds it
124 on disk. A lab fleet measured about 600 ms for a bucket proof and about 25 ms
125 for a fleet proof. The bucket upload races every fleet proof, so a slow
126 follower cannot make a write slower than a bucket proof. Concurrent writes
127 to one cell share one upload.
128- **A restore is normal work.** Placement treats the restore of an inactive
129 cell as ordinary work. The measured restore times come from the retired
130 external replicator, so this page gives no number until a fleet run measures
131 `celld-ltx`.
132- **Ten small nodes held real scale.** Ten nodes, each with 4 vCPU and 8 GB,
133 held 10,000 resident cells and 20,000 concurrent WebSocket connections. With
134 two of the ten nodes stopped, every cell was available again on another node
135 in ~11 s at the tail (with reserve headroom).
136
137## Known failure edges
138
139A fleet at its resident limit has no space for a lost node's cells, so losing
140multiple nodes degrades service. We test recovery with and without reserve
141capacity to measure this limit.
142
143Report a schedule that breaks a guarantee, an untested fault, or a measurement
144that you cannot reproduce in the
145[issue tracker](https://github.com/denoland/celld/issues).