| 1 | # What celld guarantees |
| 2 | |
| 3 | celld makes two promises about your data. Exactly one node serves a cell |
| 4 | at a time, so two machines never write the same database. And celld does |
| 5 | not answer a write until that write survives a failure, so nothing you |
| 6 | were told succeeded is lost. |
| 7 | |
| 8 | This page is how both promises are kept. Fencing is the part that keeps |
| 9 | the first one true when a node is slow, paused, or cut off from the |
| 10 | network: celld refuses that node's writes rather than trusting it to |
| 11 | notice it lost the cell. Both claims rest on the object |
| 12 | store, so this page starts with what you must provide: a bucket with |
| 13 | working conditional writes and ranged reads, and a supervisor that |
| 14 | restarts the process. The mechanism follows, so you can check the |
| 15 | argument against the code. |
| 16 | |
| 17 | ## What the bucket must provide |
| 18 | |
| 19 | celld needs four properties from the object store: |
| 20 | |
| 21 | - A conditional create: the write must fail when the object exists. |
| 22 | - A conditional overwrite: the write must fail when the object changed |
| 23 | after the read. |
| 24 | - Read-after-write consistency: a read after a successful write must |
| 25 | return that write. |
| 26 | - Ranged reads: a read must return the requested byte range and the bytes |
| 27 | from that range. |
| 28 | |
| 29 | The qualified stores are Amazon S3, Cloudflare R2, Tigris, Google Cloud |
| 30 | Storage, and Azure Blob Storage. celld's release tests run against R2, |
| 31 | and the S3 path uses the same client and the same headers. |
| 32 | |
| 33 | Backblaze B2, Hetzner Object Storage, and DigitalOcean Spaces do not |
| 34 | implement the required conditional writes. celld is not correct on such |
| 35 | a store: two nodes can then own one cell. A store can also accept the |
| 36 | conditional headers and ignore the condition, and that store fails late |
| 37 | and silently — so run the storage test below. |
| 38 | |
| 39 | MinIO (the community edition) implements the conditional writes and |
| 40 | passes the storage test, but celld has not qualified it for production. |
| 41 | One release is broken: RELEASE.2025-09-06T17-38-46Z answers the |
| 42 | conditional create of an absent object with `NoSuchKey`, so the first |
| 43 | deploy fails (denoland/celld#162). Use RELEASE.2025-09-07T16-13-09Z or |
| 44 | later. |
| 45 | |
| 46 | The request dialect differs per provider. An S3-compatible bucket gets |
| 47 | the `If-None-Match: *` and `If-Match` headers, and the condition |
| 48 | compares the etag. A `gs://` bucket selects the Cloud Storage XML API |
| 49 | with the `x-goog-if-generation-match` precondition and OAuth |
| 50 | credentials, because Cloud Storage does not apply `If-Match` to a PUT. |
| 51 | An `az://` bucket (the NAME is the container) uses the same `If-` |
| 52 | headers, which Put Blob applies. The adapter treats `AlreadyExists` and |
| 53 | `Precondition` (HTTP 412 on Azure) as clean conditional-write |
| 54 | rejections and keeps every other error ambiguous, because an ambiguous |
| 55 | write can have changed the object. |
| 56 | |
| 57 | Azure was qualified on 2026-08-18 under an account key, a VM managed |
| 58 | identity, and an AKS workload identity, single-node. A managed identity |
| 59 | on Azure App Service or Azure Container Apps does not work; see |
| 60 | [limitations](limitations.md). |
| 61 | |
| 62 | ## The storage test |
| 63 | |
| 64 | No store publishes these properties, so celld asks the store directly. |
| 65 | The command `celld diagnose` sends four conditional writes to your |
| 66 | bucket and reports the result: |
| 67 | |
| 68 | ``` |
| 69 | ok bucket conditional write (create, reject-create, update, reject-stale) |
| 70 | ``` |
| 71 | |
| 72 | Two of the four writes must fail. A store that accepts either one |
| 73 | cannot fence a cell, so celld names the store as the fault and the |
| 74 | command exits with an error. Each node also runs these writes before it |
| 75 | serves. The node then requests part of a second object and verifies the |
| 76 | returned range and bytes. |
| 77 | |
| 78 | The startup test uses new objects for each attempt. It makes at most |
| 79 | three attempts when an operation fails without a clear cause. The node |
| 80 | starts with a warning after all three attempts fail because a temporary |
| 81 | outage can end after startup. The node stops immediately when a required |
| 82 | conditional write or ranged read is unsupported. It also stops when the |
| 83 | store ignores a condition or returns a wrong range or wrong bytes. Set |
| 84 | `CELLD_STORAGE_PROBE=0` to disable the startup test, or run |
| 85 | `celld diagnose --read-only` with a credential that cannot write. |
| 86 | |
| 87 | The diagnose test writes and deletes one small object under `probe/`. |
| 88 | The startup test uses a second object for the ranged read. A process |
| 89 | that stops mid-test can leave an object behind; it is small, and celld |
| 90 | never reads it. celld reserves `probe/` together with `cells/`, |
| 91 | `nodes/`, `node-cells/`, `fleet/`, `deploy/`, `deploy-blobs/`, `wake/`, |
| 92 | and `telemetry/`, and it deletes objects under some of them, so an |
| 93 | application must not write under any of these prefixes. |
| 94 | |
| 95 | celld requires ranged reads for stored cell data. The startup test stops |
| 96 | a node when the store ignores the `Range` header or returns incorrect |
| 97 | bytes. |
| 98 | |
| 99 | ## The supervisor |
| 100 | |
| 101 | You must run celld under a supervisor that restarts the process, such |
| 102 | as systemd, Docker with a restart policy, or Kubernetes. A node fences |
| 103 | itself when it loses its lease (the mechanism is below), and a fenced |
| 104 | process exits; without a restart, the fleet loses that capacity until |
| 105 | an operator intervenes. |
| 106 | |
| 107 | The supervisor must restart without an attempt limit, and it must wait |
| 108 | at least one lease lifetime between attempts. A node that cannot |
| 109 | acquire a lease at startup retries and does not exit, so a repeated |
| 110 | fence needs a node that acquires a lease and then loses it, and the |
| 111 | wait keeps that cycle slow enough to observe. |
| 112 | |
| 113 | ## The mechanism |
| 114 | |
| 115 | The short version: the ownership records use conditional writes, so two |
| 116 | nodes cannot acquire one cell. The replicated data carries its fencing |
| 117 | epoch in the object key, so a node that lost ownership writes only into |
| 118 | a superseded prefix. And before celld acknowledges a write, it proves |
| 119 | the write durable and confirms that it still owns the cell. |
| 120 | |
| 121 | ### The ownership record |
| 122 | |
| 123 | Each cell has one ownership record in the bucket. The record names the |
| 124 | owner node's session and carries a fencing epoch. A node acquires a |
| 125 | cell with a conditional write — a create when no record exists, a |
| 126 | compare-and-swap on the previous record when one does — and the bucket |
| 127 | accepts one such write, so two nodes cannot acquire the same cell. |
| 128 | |
| 129 | Every activation advances the epoch, a takeover and a local wake alike. |
| 130 | Each owner therefore replicates under a fresh epoch, and an epoch never |
| 131 | has two writers. |
| 132 | |
| 133 | ### The epoch prefix |
| 134 | |
| 135 | The replicator copies each cell's SQLite data to the bucket under |
| 136 | `cells/<cell>/ltx/e<epoch>/`, with plain unconditional PUTs. The epoch |
| 137 | in the key is the fence: a node that lost ownership can keep writing, |
| 138 | but its writes land in a superseded prefix, and a restore selects the |
| 139 | current lineage. (The tiering path can first combine segments from many |
| 140 | cells into a node bundle, and it drains each segment into its per-cell |
| 141 | prefix later.) |
| 142 | |
| 143 | The prefix protects the new owner's data from stale writes. The next |
| 144 | two sections protect the durability promise. |
| 145 | |
| 146 | ### The acknowledgement rule (RPO=0) |
| 147 | |
| 148 | A gate holds each write response until a durability proof covers the |
| 149 | write. A read-only response waits in the same way when the object has |
| 150 | committed a write that no proof covers yet. An error answer waits under |
| 151 | the same rule, because the message of a handler that throws can carry a |
| 152 | value that the handler read. A response body that streams gets the same |
| 153 | rule for each chunk, so a chunk that an object produces after the |
| 154 | response head waits for a proof of the writes it can reveal. A client |
| 155 | therefore cannot act on a value that a crash can still lose. After a |
| 156 | bucket proof, celld reads the ownership record once and acknowledges |
| 157 | only if the record still names this node at this epoch. A partitioned |
| 158 | node can commit locally and replicate into its superseded prefix, but |
| 159 | the ownership read then shows the new owner, so celld does not |
| 160 | acknowledge the write. The check reads the record instead of comparing a |
| 161 | clock, so a paused process or a skewed clock cannot pass it. |
| 162 | |
| 163 | A fleet proof does not require this read. The owner sends each write to |
| 164 | one or two other nodes, which hold a copy of its recent writes; those |
| 165 | nodes are its followers, and the set of them is the ensemble. Every |
| 166 | follower must fsync the write, and a takeover seals the prior node-log |
| 167 | session before it restores, so the stale owner cannot complete another |
| 168 | fleet proof. |
| 169 | |
| 170 | ### The ensemble needs two nodes |
| 171 | |
| 172 | A node picks its followers from the other nodes in the fleet, so it never |
| 173 | counts itself. One follower is enough, therefore a fleet needs two |
| 174 | running celld nodes before any node can complete a fleet proof. |
| 175 | `CELLD_DURABILITY=fleet` is the default, so a fleet of one node requests the |
| 176 | fleet posture and does not get it. |
| 177 | |
| 178 | A node recruits up to two followers, so a fleet of three or more nodes holds |
| 179 | three copies of an acknowledged write. The ensemble keeps acknowledging while |
| 180 | one follower remains, therefore a fleet does not fall back to the bucket each |
| 181 | time it loses a follower. |
| 182 | |
| 183 | A node without an ensemble stays correct. It acknowledges each write on a |
| 184 | bucket proof instead, so celld still does not acknowledge a write before a |
| 185 | durability proof covers it. The cost is latency: the write waits for the object |
| 186 | store, and an object store round trip is much slower than a follower fsync. |
| 187 | |
| 188 | ### The takeover recovery gate |
| 189 | |
| 190 | The default fleet mode can acknowledge a write once the node-log |
| 191 | ensemble stores it; the bucket upload can complete later. Each process |
| 192 | session therefore creates a conditional node-log record before its |
| 193 | first fleet-durable acknowledgement. |
| 194 | |
| 195 | A cold activation checks the prior owner's log records before it reads |
| 196 | the bucket. An absent record proves that the session never acknowledged |
| 197 | past the bucket, and a sealed record proves that recovery completed. An |
| 198 | open or recovering record makes the activation run recovery: it fences |
| 199 | the record with a compare-and-swap, seals the reachable followers, |
| 200 | uploads their retained segments and bundles into the per-cell prefixes, |
| 201 | and then marks the record sealed. The activation cannot restore until |
| 202 | this sequence completes. |
| 203 | |
| 204 | A restarting node serves authenticated follower seal and tail requests before |
| 205 | it completes its own predecessor recovery. Therefore, nodes that restart |
| 206 | together can recover acknowledged writes from their surviving follower disks. |
| 207 | The node accepts application requests and new follower appends only after |
| 208 | startup completes. |
| 209 | |
| 210 | A large dead node can hold this recovery open for minutes. A recovery |
| 211 | attempt that fails or times out does not fail the waiting requests. |
| 212 | The cell waits, and it retries the activation with a backoff |
| 213 | (`CELLD_RECOVERY_RETRY_MS`, default 1000). The requests fail with a |
| 214 | resolve error only after the retry budget is spent |
| 215 | (`CELLD_RECOVERY_RETRIES`, default 240). |
| 216 | |
| 217 | ### Epoch-chain restore |
| 218 | |
| 219 | A restore composes the epoch prefixes that contain LTX data into one |
| 220 | chain. It starts at the newest prefix and walks down. An epoch that |
| 221 | opened with a whole-database snapshot starts the chain at transaction |
| 222 | one. An epoch that paged in continues its predecessor: its prefix holds a |
| 223 | marker object at the successor of the cut it paged from, and then its own |
| 224 | deltas, so the chain links the predecessor up to that cut and the epoch |
| 225 | from the cut onward. A link must end exactly at its successor's cut, so an |
| 226 | epoch that does not continue the chain is not part of it. celld no longer |
| 227 | writes an epoch seal object, and a legacy `e<epoch>.seal.json` object does |
| 228 | not limit the chain. |
| 229 | |
| 230 | A fenced node can append an unacknowledged tail to an older prefix. When |
| 231 | a successor opened with a whole-database snapshot, a later restore reads |
| 232 | the full chain and can expose that tail. This does not violate the |
| 233 | contract, because a failed or absent acknowledgement does not prove that |
| 234 | the write is absent, and a node-log recovery or a bundle drain can add an |
| 235 | acknowledged tail after an earlier restore. When a successor paged in, the |
| 236 | chain clips the older prefix at the successor's cut. This is safe because |
| 237 | the takeover recovery gate seals the prior node-log session before the |
| 238 | successor restores, so no write past the cut can be acknowledged. |
| 239 | |
| 240 | A paged cell's restore reads no chain up front. The cell opens over a |
| 241 | sparse local file, and each page the cell touches is read from the |
| 242 | objects on first use. The node then fills the rest of the file in the |
| 243 | background, and a filled cell reads only its local file. A chain smaller |
| 244 | than `CELLD_LTX_PAGED_MIN_MB` is downloaded whole, as before. |
| 245 | |
| 246 | ### Self-fencing |
| 247 | |
| 248 | Each node holds a lease in the bucket. The lease carries an expiry, and |
| 249 | the node renews it after one third of the lifetime (`CELLD_TTL_MS`, |
| 250 | default 10000 ms). A renewal that does not reach the bucket does not |
| 251 | fence the node, because the node retries while the published expiry has |
| 252 | not passed. |
| 253 | |
| 254 | A node that cannot reach the bucket cannot renew and cannot replicate, |
| 255 | so it must not own cells. When its published expiry passes, it fences |
| 256 | itself: it stops each active cell, and it fails every request that it |
| 257 | has not completed. A node also fences at once when its lease record is |
| 258 | gone, or no longer matches the record that the node published, because |
| 259 | the node can no longer prove that it holds the authority. |
| 260 | |
| 261 | The fence writes nothing to the bucket. Each peer already reads the |
| 262 | lease as dead or replaced, so a peer can acquire the cells through the |
| 263 | ownership records. And a request is safe even before the fence runs, |
| 264 | because celld compares the current time against the published expiry |
| 265 | each time it routes a request. |
| 266 | |
| 267 | A fenced node logs a line that starts with `SELF-FENCE:` and stops with |
| 268 | the exit code 3. celld reports other internal failures with the same |
| 269 | prefix and code, so the line names the cause. An expired lease uses the |
| 270 | `node_lease_watchdog_fence` event. A missing record uses the |
| 271 | `node_lease_record_missing_fence` event, and a record that no longer |
| 272 | matches the node uses the `node_lease_record_mismatch_fence` event. The |
| 273 | mismatch event does not name an author, because the node cannot prove |
| 274 | which writer wrote that record. The fenced state is terminal: |
| 275 | only a restart returns the node to the fleet, through the same |
| 276 | cold-activation path that a peer failure uses. |
| 277 | |
| 278 | The fence line names the lease state, and it cannot name the store |
| 279 | request that produced that state. A removed record, a replaced record |
| 280 | and a failed read are three different operator problems, so celld can |
| 281 | report each lease request on its own. Set |
| 282 | `RUST_LOG=celld=info,store=debug` to turn this on. The node then logs a |
| 283 | `node_lease_read` event and a `node_lease_write` event for each request |
| 284 | against its own lease record. Each event carries an `outcome` field: |
| 285 | `found`, `missing`, `applied`, `rejected` or `error`. An `error` |
| 286 | outcome carries the store failure in an `error` field, and a `found` |
| 287 | outcome carries the `generation` field of the record that came back. |
| 288 | The target is off at every other filter, so a node in production pays |
| 289 | nothing for it. |
| 290 | |
| 291 | The failure of a node is a normal input, not a recovery procedure; the |
| 292 | [testing page](testing.md) shows the kill tests that exercise this |
| 293 | path. |