Skip to content

docs: evaluate S3 conditional writes as a Raft substitute (#169) - #265

Merged
scttfrdmn merged 3 commits into
mainfrom
v0.12.0-coordination-evaluation
Aug 3, 2026
Merged

scttfrdmn merged 3 commits into
mainfrom
v0.12.0-coordination-evaluation

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #169.

Recommendation

Adopt the hybrid: per-key compare-and-swap for coordination, gossip for membership, no
replicated log.
Stop building toward Raft.

Raft replicates a log so N nodes agree on state they each hold a copy of. ObjectFS nodes hold no
such state — S3 does. Every operation internal/distributed coordinates ends in a write to a key
in one bucket every node can already read.

The full evaluation is docs/design/conditional-writes-vs-raft.md, structured to the issue's five
acceptance criteria. Highlights:

The premises were verified against source, not taken from the issue

applyLogEntry is three empty arms and nothing appends EntryTypeOperation — the consensus engine
elects leaders and replicates nothing. executeLocally calls the backend directly, never consulting
the log, commit index, term, or leadership. executeStrongConsistency fans N identical PUTs of the
same bytes at one key and accepts on a majority, which is a reachability signal, not linearizability.

The CAS primitive is proven by execution, not by reading AWS docs

Substrate v0.85.0 implements conditional writes (from the previously-filed substrate#397), with a
64-stripe per-key mutex held across check→Put — so an exactly-one-winner result is meaningful rather
than an artifact of last-write-wins. Probed over real HTTP:

  • 32 concurrent `If-None-Match: *` PUTs → exactly 1 winner, 31 × PreconditionFailed
  • stale `If-Match` → 412, stored object unchanged
  • `If-Match` on an absent key → `NoSuchKey`, not 412
  • 8 workers in a read-ETag → increment → CAS loop → converges to exactly 8, zero lost updates
  • `PutObject` returns a fresh ETag, so a CAS loop needs no HEAD between iterations

Two findings the issue did not anticipate, both changing caller code

  1. 409 vs 412 are not synonyms. 412 = lost race, recompute and retry. 409
    ConditionalRequestConflict = a delete interleaved; a `PutObject` may be retried as-is, but a
    `CompleteMultipartUpload` has a dead upload ID and must restart from
    `CreateMultipartUpload`. A loop conflating them spins until it gives up — and substrate models
    only 412, so that bug is invisible in testing today. Filed as S3: conditional writes never return 409 Conflict, so the retry path a caller must take is untestable substrate#540.
  2. Ceph RGW does not support conditional writes at all. PUT Object documents only content-md5,
    content-type, x-amz-meta-*, x-amz-acl. That forces the compatibility rule: fail closed. An
    unconditional fallback turns "exactly one node performs this tier transition" into "every node
    does" — the failure the coordination exists to prevent, occurring silently. Precedent: the read
    path fails closed on a `Content-Encoding` it cannot decode.

Detection is by attempt, not by configuration — `If-Match` against a known-absent key
expecting `NoSuchKey`. A backend that succeeds at that probe is silently ignoring preconditions,
which is the dangerous case a feature flag would never notice.

The ceiling, which is the section to read before agreeing

No multi-key atomicity (R5, and nothing needs it today). No liveness guarantee on leadership — and
the design obligation that follows: every guarded action must re-assert the CAS, because an
action guarded by "I checked my lease a moment ago" is not guarded. Raft fails closed on quorum
loss; CAS only fails closed if the guarded action re-checks. Cost is per-attempt: AWS bills failed
conditional requests at normal rates, so a hot key with N contenders is O(N) requests — coordination
keys must be chosen for low contention.

Also in this PR

`internal/distributed/doc.go` claimed "Linearizable operations across cluster." That is
inaccurate on today's code whichever direction is chosen, so it is corrected here rather than left
pending a decision. The Consistency Levels section now states the structural reason once — every
node writes the same key in the same bucket, S3 is the single copy — and describes each level by
what it does. The stale warning pointing at "Sprint 4 (LocalStack)" is gone; this project does not
use LocalStack.

Issue consequences, for your call — nothing closed unilaterally

If the recommendation is accepted:

Verification

`go build ./...` clean · `gofmt -l .` → 0 · `go test -count=1 -race ./internal/config/
./internal/distributed/` both ok · `golangci-lint run --new-from-merge-base=origin/main` → 0
issues · markdownlint clean. Mutation-verified: deleting the mkdocs nav entry makes
`TestMkDocsNavMatchesTheTree` fail naming the file; restoring it passes.

…package claims

Closes #169.

The recommendation is to adopt per-key compare-and-swap, keep gossip for
membership, and stop building toward a replicated log. The reason is not that
Raft is the wrong protocol but that there is no replication problem here: Raft
exists so N nodes can agree on state they each hold a copy of, and ObjectFS
nodes hold no such state. Every operation internal/distributed coordinates ends
in a write to a key in one bucket that every node can already read.

The CAS properties are verified by execution against a substrate endpoint over
real HTTP, not read off AWS's documentation. Exactly one of 32 concurrent
If-None-Match:* PUTs wins; a stale-ETag If-Match gets PreconditionFailed and
leaves the object unchanged; If-Match on an absent key gets NoSuchKey rather
than 412; eight workers running a read-then-CAS increment loop converge to
exactly eight with no lost updates. PutObject also returns the new ETag, so a
lease renewal is one request rather than a HEAD plus a PUT.

Two findings the issue did not anticipate, both of which change caller code:

The failure taxonomy is three-way. 409 ConditionalRequestConflict is distinct
from 412 and means a delete interleaved; a PutObject may be retried as-is, but a
CompleteMultipartUpload that gets a 409 has a dead upload ID and must restart
from CreateMultipartUpload. A loop treating 409 as a synonym for 412 spins until
it gives up, and substrate models only 412 — so that mistake is invisible in
testing today. Filed as scttfrdmn/substrate#540, suggesting fault injection,
since 409 comes from a timing race rather than a state a request can assert.

Ceph RADOS Gateway does not support conditional writes at all: PUT Object
documents content-md5, content-type, x-amz-meta-*, x-amz-acl, and conditional
headers for reads only. MinIO supports both, though its own comment calls it "a
MinIO specific extension," so the semantics need verifying separately from the
header's presence. Wasabi is unverified — its docs moved and nothing citable
resolved. Hence the fail-closed rule: an unconditional fallback would turn
"exactly one node performs this tier transition" into "every node does," which
is the failure the coordination exists to prevent, occurring silently.

The interface sketch is a separate PutObjectIf rather than a changed PutObject
signature, because PutObject has one production implementation and five test
doubles, most of the nine call sites have no precondition to express, and a
backend that cannot honor a precondition must be able to say so rather than
ignore it.

doc.go: the last acceptance criterion, and it was inaccurate whichever direction
this went. Strong Consistency claimed "Linearizable operations across cluster";
what the code does is fan N identical PUTs of the same bytes at one key and
accept a majority, which reports that most nodes could reach S3. Session claimed
read-your-writes, which comes from reading through the write buffer —
internal/vfs does that per descriptor and this package is not involved. Each
level now says what it does, with the structural reason stated once. The package
warning also stops citing "integration tests pending Sprint 4 (LocalStack)":
this project does not use LocalStack and that sprint is long past, so it now
names the actual gap.

No code changes, per the issue's last criterion. Verified: go build clean, gofmt
clean, -race tests pass for internal/config and internal/distributed,
golangci-lint 0 issues, markdownlint clean. The mkdocs nav gate was checked by
mutation — deleting the nav entry fails TestMkDocsNavMatchesTheTree by name.
Both branches added an [Unreleased] entry; the merge keeps both.
scttfrdmn added a commit that referenced this pull request Aug 3, 2026
… (#268)

CI's race detector caught this on the run for #265, a documentation-only pull
request — so it was live on main rather than introduced there.

`Unmount` writes `m.server = nil` under `m.mu`. Two places read it without the
lock: the goroutine `Mount` spawns to serve, and `Wait`.

Both are also nil dereferences, which is what makes it more than a detector
report. If the unmount lands first, `m.server.Wait()` panics on a background
goroutine — unrecoverable, so it takes the process down together with the
mount, unmounting under every open file descriptor. `Wait`'s `if m.server !=
nil` check does not help: the write can land between the check and the
dereference.

The serving goroutine now waits on the `server` local already in scope. It is
the same server either way, and that goroutine's whole job is to outlive the
field. `Wait` reads the field into a local under `m.mu` and waits outside it —
holding the lock across `server.Wait()` would also silence the detector and
would deadlock every real unmount, since `Unmount` needs the same lock to clear
the field.

Why the suite did not catch it sooner: it reproduces only on Linux and only
intermittently. On darwin `fs.Mount` needs macFUSE, so the goroutine never
starts and the racing read is unreachable — the local -race suite is green while
CI went red once in many runs. A regression test inheriting that property would
be worthless, so mount_race_test.go drives both sides directly and needs no
mount: one goroutine writes the field under the lock, another calls Wait.

Mutation-verified: restoring the unlocked read makes the new test report
WARNING: DATA RACE and fail; the fix makes it pass.

Gates: go build, go vet, gofmt -l clean, full `go test -count=1 -race` suite
green, coverage gate 34 packages at or above floor, golangci-lint
--new-from-merge-base=origin/main 0 issues.
@scttfrdmn
scttfrdmn merged commit 61ae7b0 into main Aug 3, 2026
24 checks passed
@scttfrdmn
scttfrdmn deleted the v0.12.0-coordination-evaluation branch August 3, 2026 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Evaluate S3 conditional writes as a replacement for Raft coordination

1 participant