| 1 | # Ownership and fencing |
| 2 | |
| 3 | celld makes two claims. One node owns a cell at a time, and a write is |
| 4 | durable before celld acknowledges it. This page gives the mechanism |
| 5 | behind each claim, so you can check the argument against the code. |
| 6 | |
| 7 | A short version first. The ownership records use conditional writes. |
| 8 | The bucket replication path uses plain writes, because the epoch in the key |
| 9 | is the fence. After a bucket proof, celld re-reads the ownership record and |
| 10 | acknowledges the write only if the record still names this node. Every |
| 11 | follower must fsync the write for a fleet proof. During a cold activation, |
| 12 | celld recovers the prior node log before it reads the bucket. These paths |
| 13 | stop a stale node from acknowledging a write that the fleet does not store. |
| 14 | |
| 15 | ## The ownership record |
| 16 | |
| 17 | Each cell has one ownership record in the bucket. The record names the |
| 18 | owner node's session and carries a fencing epoch. A node acquires a |
| 19 | cell with a conditional write: a create when no record exists, and a |
| 20 | compare-and-swap on the previous record when one does. The bucket |
| 21 | accepts one such write, so two nodes cannot acquire the same cell. |
| 22 | |
| 23 | Every activation advances the epoch. A takeover advances it, and a |
| 24 | local wake advances it too. Each owner therefore replicates under a |
| 25 | fresh epoch, and an epoch never has two writers. |
| 26 | |
| 27 | ## Replication and the epoch prefix |
| 28 | |
| 29 | The replicator copies the SQLite data of each cell to the bucket under an |
| 30 | epoch prefix: `cells/<cell>/ltx/e<epoch>/`. These segment writes are plain, |
| 31 | unconditional PUTs. The tiering path can first combine segments from many |
| 32 | cells into a node bundle, and it later drains each segment into its per-cell |
| 33 | prefix. |
| 34 | |
| 35 | The epoch in the key is the fence, so the data path needs no conditional |
| 36 | write. A node that lost ownership can continue to write, but its writes land |
| 37 | in a superseded prefix. A restore selects the current lineage, so the stale |
| 38 | node cannot corrupt the data of the new owner. |
| 39 | |
| 40 | The prefix protects the current owner from stale writes. The acknowledgement |
| 41 | rule and the takeover recovery gate protect the durability promise. |
| 42 | |
| 43 | ## The acknowledgement rule (RPO=0) |
| 44 | |
| 45 | A gate holds each write response until a durability proof covers the write. |
| 46 | After a bucket proof, celld reads the ownership record one time. celld |
| 47 | acknowledges only if the record still names this node at this epoch. A |
| 48 | partitioned node can commit locally and replicate into its superseded prefix. |
| 49 | The ownership read then shows the new owner, so celld does not acknowledge the |
| 50 | write. The check reads the record instead of comparing a clock, so a paused |
| 51 | process or a skewed clock cannot pass it. |
| 52 | |
| 53 | A fleet proof does not require this read. Every member of the follower |
| 54 | ensemble must fsync the write. A takeover seals the prior node-log session |
| 55 | before it restores, so the stale owner cannot complete another fleet proof. |
| 56 | |
| 57 | ## The takeover recovery gate |
| 58 | |
| 59 | The default fleet mode can acknowledge a write after all members of a node |
| 60 | log ensemble store the write. The bucket upload can complete later. Each |
| 61 | process session therefore creates a conditional node log record before its |
| 62 | first fleet-durable acknowledgement. |
| 63 | |
| 64 | A cold activation checks the log records of the prior owner before it reads |
| 65 | the bucket. An absent record proves that the session never acknowledged past |
| 66 | the bucket, and a sealed record proves that recovery completed. An open or |
| 67 | recovering record makes the activation run recovery. |
| 68 | |
| 69 | Recovery uses compare-and-swap writes to fence the record. It seals the |
| 70 | reachable followers, gathers their retained segments and bundles, and uploads |
| 71 | the missing segments into the per-cell prefixes. Recovery then marks the log |
| 72 | record as sealed with another compare-and-swap write. The activation cannot |
| 73 | restore until this sequence completes. |
| 74 | |
| 75 | ## Full-prefix restore |
| 76 | |
| 77 | celld no longer writes an epoch seal object. A restore selects the newest |
| 78 | epoch prefix that contains LTX data, and it reads the full contiguous chain |
| 79 | from transaction zero. A legacy `e<epoch>.seal.json` object does not limit |
| 80 | this chain. |
| 81 | |
| 82 | A fenced node can append an unacknowledged tail to an older prefix. A later |
| 83 | restore can expose that tail if it selects the prefix. This result does not |
| 84 | violate the acknowledgement contract, because a failed or absent |
| 85 | acknowledgement does not prove that the write is absent. |
| 86 | |
| 87 | A node-log recovery or a bundle drain can add an acknowledged follower tail |
| 88 | after an earlier restore. A fixed restore cut stops at the transaction of that |
| 89 | earlier restore, therefore it hides the recovered tail and loses acknowledged |
| 90 | data. celld does not use a fixed restore cut. The full-prefix rule reads the |
| 91 | complete chain, so a later restore returns the recovered tail and the |
| 92 | acknowledgement contract holds. |
| 93 | |
| 94 | ## Self-fencing |
| 95 | |
| 96 | Each node holds a node lease in the bucket. The lease carries an expiry, and |
| 97 | the node renews the lease after one third of the lease lifetime. The |
| 98 | `CELLD_TTL_MS` variable sets that lifetime, and the default is 10000 ms. A |
| 99 | renewal that does not reach the bucket does not fence the node, because the |
| 100 | node retries while the published expiry has not passed. |
| 101 | |
| 102 | A node that cannot reach the bucket cannot renew its lease, and it cannot |
| 103 | replicate. Such a node must not own cells, so it fences itself when its |
| 104 | published expiry passes. It stops each active cell, and it fails every |
| 105 | request that it has not completed. A node whose lease record another writer |
| 106 | replaced or removed fences at once, because that record proves the authority |
| 107 | moved. |
| 108 | |
| 109 | The fence writes nothing to the bucket. Each peer already reads the lease |
| 110 | record as dead or as replaced, therefore a peer can acquire the cells through |
| 111 | the ownership records. The handover comes from the lease record itself, not |
| 112 | from a release that the fenced node performs. |
| 113 | |
| 114 | A request is safe even before the fence runs. celld compares the current time |
| 115 | against the published expiry each time it routes a request, so a node with a |
| 116 | lapsed lease refuses the request. The fence stops the process, and the |
| 117 | dispatch check keeps one owner per cell. |
| 118 | |
| 119 | A fenced node logs a line that starts with `SELF-FENCE:`, and then the process |
| 120 | stops with the exit code 3. The line names the cause, because celld reports |
| 121 | other internal failures with the same prefix and the same exit code. The |
| 122 | fenced state is terminal, so the process cannot take a new lease, and only a |
| 123 | restart returns the node to the fleet. A restart uses the same cold activation |
| 124 | path that a peer failure already uses, therefore celld needs no second |
| 125 | recovery procedure. |
| 126 | |
| 127 | You must run celld under a supervisor that restarts the process, such as |
| 128 | systemd, Docker with a restart policy, or Kubernetes. A node without such a |
| 129 | supervisor does not return after a fence, and the fleet loses that capacity |
| 130 | until an operator intervenes. The supervisor must restart the process without |
| 131 | an attempt limit, and it must wait at least one lease lifetime between |
| 132 | attempts. A node that cannot acquire a lease at startup retries and does not |
| 133 | exit, so a repeated fence needs a node that acquires a lease and then loses |
| 134 | it, and the wait keeps that cycle slow enough to observe. |
| 135 | |
| 136 | The failure of a node is a normal input, not a recovery procedure; the |
| 137 | [testing page](testing.md) shows the kill tests that exercise this path. |
| 138 | |
| 139 | ## What the bucket must provide |
| 140 | |
| 141 | celld needs three properties from the object store: |
| 142 | |
| 143 | - A conditional create. The create must fail when the object already |
| 144 | exists. |
| 145 | - A conditional overwrite. The write must fail when the object changed |
| 146 | after the read. |
| 147 | - Read-after-write consistency. A read after a successful write must |
| 148 | return that write. |
| 149 | |
| 150 | The bucket adapter treats `AlreadyExists` and `Precondition` as clean |
| 151 | conditional-write rejections. Azure uses `Precondition` for an HTTP 412 |
| 152 | response. The adapter keeps every other error ambiguous. A caller must |
| 153 | reconcile an ambiguous error because the write can have changed the object. |
| 154 | |
| 155 | On an S3-compatible bucket, celld sends the `If-None-Match: *` and |
| 156 | `If-Match` headers, and the condition compares the etag. Amazon S3, |
| 157 | Cloudflare R2, and Tigris document these operations. celld's release |
| 158 | tests run against Cloudflare R2, and the AWS S3 path uses the same |
| 159 | client and the same headers. |
| 160 | |
| 161 | A `gs://` bucket selects Google Cloud Storage. celld then uses the |
| 162 | Cloud Storage XML API with the `x-goog-if-generation-match` |
| 163 | precondition and OAuth credentials, and the condition compares the |
| 164 | object generation. celld does not send the S3 request dialect to |
| 165 | Cloud Storage, because Cloud Storage does not apply `If-Match` to a |
| 166 | PUT. |
| 167 | |
| 168 | An `az://` bucket selects Azure Blob Storage, where the NAME is the |
| 169 | container. celld then sends the same `If-None-Match: *` and `If-Match` |
| 170 | headers, and the condition compares the etag, because Put Blob applies |
| 171 | both headers. Microsoft documents these operations. |
| 172 | |
| 173 | The qualified stores are Amazon S3, Cloudflare R2, Tigris, Google Cloud |
| 174 | Storage, and Azure Blob Storage. |
| 175 | |
| 176 | Azure was qualified on 2026-08-18, against the shipped revision. The |
| 177 | four-step matrix passes under each credential family celld supports — |
| 178 | an account key, a VM managed identity, and an AKS workload identity — |
| 179 | and a node restores a cell from an Azure replica alone after its local |
| 180 | state is destroyed. An LTX file above the 5 MiB threshold, where celld |
| 181 | switches to block-blob multipart, uploads and reads back byte-for-byte; |
| 182 | Azure's own committed block list shows the parts. |
| 183 | |
| 184 | What that qualification does not cover: a managed identity on Azure App |
| 185 | Service or Azure Container Apps (see [limitations](limitations.md)), |
| 186 | per-blob write rate limits shaping lease cadence under sustained load, |
| 187 | and multi-node contention. Each run was single-node, and its conditions |
| 188 | are recorded with it. |
| 189 | |
| 190 | Some S3-compatible stores do not qualify. MinIO (the community |
| 191 | edition), Backblaze B2, Hetzner Object Storage, and DigitalOcean |
| 192 | Spaces do not implement the required conditional writes. celld is not |
| 193 | correct on such a store: two nodes can then own one cell. A store can |
| 194 | also accept the conditional headers and not apply the condition, and |
| 195 | that store fails late and silently. |
| 196 | |
| 197 | ## The storage test |
| 198 | |
| 199 | No object store publishes the answer, therefore celld asks the store |
| 200 | directly. The command `celld diagnose` sends four conditional writes to |
| 201 | your bucket, and it reports the result: |
| 202 | |
| 203 | ``` |
| 204 | ok bucket conditional write (create, reject-create, update, reject-stale) |
| 205 | ``` |
| 206 | |
| 207 | Two of the four writes must fail. A create over an existing object must |
| 208 | fail, and an update that carries a stale token must fail. A store that |
| 209 | applies either write cannot fence a cell, so celld names the store as |
| 210 | the fault and the command exits with an error. |
| 211 | |
| 212 | Each node runs the same test one time at startup. A node that finds a |
| 213 | broken store stops, because a node that serves on such a store can |
| 214 | share a cell with a second owner. The value `0` in the |
| 215 | `CELLD_STORAGE_PROBE` variable disables the startup test. |
| 216 | |
| 217 | The test writes one small object, and then it deletes the object. The |
| 218 | object uses the `probe/` prefix. celld reserves that prefix together |
| 219 | with `cells/`, `nodes/`, `node-cells/`, `fleet/`, `deploy/`, |
| 220 | `deploy-blobs/`, `wake/` and `telemetry/`, so an application must not |
| 221 | write under any of them. celld deletes objects under some of them. A |
| 222 | process that stops during the test does not delete the object. The |
| 223 | object is small, and celld never reads it. |
| 224 | |
| 225 | The test writes, so a credential that cannot write fails it. An |
| 226 | operator who diagnoses with a read-only credential runs |
| 227 | `celld diagnose --read-only`, and celld then skips the test. |
| 228 | |
| 229 | celld does not require a ranged read today, so a store that ignores the |
| 230 | `Range` header can still run a fleet. A later compaction level can hold |
| 231 | large snapshots, and such a level can need a ranged read again. |