Repository navigation
docs: evaluate S3 conditional writes as a Raft substitute (#169) - #265
Merged
Merged
Conversation
…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.
This was referenced Aug 3, 2026
Closed
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/distributedcoordinates ends in a write to a keyin one bucket every node can already read.
The full evaluation is
docs/design/conditional-writes-vs-raft.md, structured to the issue's fiveacceptance criteria. Highlights:
The premises were verified against source, not taken from the issue
applyLogEntryis three empty arms and nothing appendsEntryTypeOperation— the consensus engineelects leaders and replicates nothing.
executeLocallycalls the backend directly, never consultingthe log, commit index, term, or leadership.
executeStrongConsistencyfans N identical PUTs of thesame 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:
Two findings the issue did not anticipate, both changing caller code
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.
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:
`priority: critical`, and the largest single saving), A1-6: Fix broadcastProposal — replace simulation stub with real UDP broadcast #133 (UDP broadcastProposal — the
networking survives for gossip, the proposal framing does not), A3-2: Log compaction and Snapshot interface #151 (serializing
state-machine state that does not exist).
on coordination keys stays low), A1-5: Populate NodeInfo stats via gossip heartbeat #132 (NodeInfo via gossip), distributed: gossip has no message authentication, and cache-warming would make that a content-injection path #206 (gossip authentication — a real
security defect either way).
re-assert rule · replace `executeStrongConsistency`'s fan-out and fix the consistency-level
taxonomy · verify MinIO and Wasabi against real endpoints.
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.