Repository navigation
Description
Context
Third issue in the CAS series adopted from #169
/ docs/design/conditional-writes-vs-raft.md. Depends on #282, and on #283 where a lease is the
right primitive.
executeStrongConsistency (internal/distributed/coordinator.go:372) fans an operation to N nodes
and succeeds on successCount >= len(targetNodes)/2+1. But every node writes the same S3 key with
the same bytes, so those are N redundant identical PUTs. Majority success is a reachability
signal — "most nodes could talk to S3" — not a consistency guarantee. Per §1 of the doc, this is the
concrete reason the "strong consistency" label is wrong today.
The taxonomy around it is in the same condition. Verified on the current tree:
- The three levels differ only in how many identical PUTs are issued.
ConsistencyStrongfans to
all N and counts a majority;ConsistencySessionexecutes ontargetNodes[0]then
replicateAsyncs the rest;ConsistencyEventualexecutes ontargetNodes[0]then
replicateAsyncs the rest. Session and eventual are now nearly the same function — session's
only distinguishing feature is a comment saying it will "try to use the same node for related
operations," and there is no session state anywhere to make that true. Coordinator.executeLocallycalls the backend directly and never consults the log,commitIndex,
term, or leadership. Consensus was never on the data path.
Note two things that have already been fixed and should not be re-reported: doc.go's "Linearizable
operations across cluster" claim is gone (the doc flagged it as needing correction regardless of
direction, and grep for Linearizable now returns nothing), and selectConsistentHash is a real
rendezvous/HRW ring as of #131 — it is no longer nodes[:count].
What to implement
1. Replace the fan-out with a single conditional write
Per §1's requirements table, R2 ("a metadata update must not silently lose a concurrent one") is
served by If-Match: <etag> on one request to one key. N identical PUTs serve nothing: they
cost N× the requests, and the majority count answers a question nobody asked.
So executeStrongConsistency's replacement is a PutObjectIf with the caller's observed ETag,
returning the new ETag. Where the operation is a task that exactly one node should perform (tier
transitions, cache warming, scrubs — R1), the lease from #283 is the primitive, not a write fan-out.
2. Delete or redefine the taxonomy — do not leave three names for two behaviours
Two defensible outcomes; pick one and make the code say it:
- Delete it. If the honest inventory is "per-key CAS for coordination, gossip for membership,"
then a per-operation consistency level is not a thing callers should be choosing. Remove
ConsistencyLeveland the threeexecute*Consistencyfunctions, and let the operation type imply
its own guarantee. - Redefine it against reality. Keep names only where they describe distinguishable behaviour —
e.g. "conditional" (CAS, fails on conflict) vs "unconditional" (last-writer-wins). Two levels that
genuinely differ beat three that do not.
Either way the replicateAsync path needs a decision: replicating an identical PUT to peers that can
all reach S3 themselves is work with no stated purpose. If it is meant to warm peer caches, that is
the v0.13.0 cache-warming work (#141, #142) and should be named as such rather than living inside a
consistency level.
3. Coordinate with the issues that consume the taxonomy
Both are open and reference these constants, so this issue must not land without addressing them:
- A1-2: Define richer DistributedCoordinator interface with cache coordination methods #129 (A1-2, richer
DistributedCoordinator) proposes promotingConsistencyLeveland its three
constants intopkg/types. That part must be dropped or revised — do not promote a taxonomy into
the public types package while deleting its meaning. The rest of A1-2: Define richer DistributedCoordinator interface with cache coordination methods #129 (AnnounceKey,
QueryKeyOwnership,InvalidateKey) is cache coordination and survives. - A2-6: Implement NegotiateConsistency in coordinator #144 (A2-6,
NegotiateConsistency) is defined entirely in terms of these three levels, and its
downgrade rule is "requested Strong and not leader ⇒ Session." Under CAS the question changes from
"which level can I offer" to "does this backend support conditional writes, and do I hold the
lease." A2-6: Implement NegotiateConsistency in coordinator #144 should be revised or closed as part of this work.
Also fold in the leftover from #133, closed as not-the-direction: if broadcastProposal's
simulation stub (consensus.go, a time.Sleep that accepts its own proposal) is still present once
this lands, delete it rather than fixing it. Same for any EntryTypeOperation /
EntryTypeConfigChange scaffolding left with no producer.
4. R4: invalidation must carry its ETag
§1's R4 — a cache invalidation must not be applied out of order relative to the write it invalidates
— is satisfied by CAS only if the invalidation carries the ETag it was computed from. Whatever
replaces the fan-out must propagate the ETag PutObjectIf returns, so a receiver can discard an
invalidation that refers to a version it has already moved past. Dropping the ETag here silently
reintroduces the ordering bug.
Testing
- Assert requests issued, not just success: one conditional PUT where there used to be N. Use
internal/testaws's request counters (srv.Requests()/srv.GETs(key)); a mock would agree by
construction. - Concurrent metadata update from two coordinators: one succeeds, the other sees
ErrPreconditionFailedand no update is lost. Assert the final object bytes. - Whatever taxonomy survives: a test per surviving level proving the levels are distinguishable.
If two levels cannot be told apart by a test, that is the argument for deleting one. go test -count=1 -race -tags=distributed ./tests/must pass, and must not set config values
to work around defaults (per Gossip: the 1024-byte MaxGossipPacket default truncates sync messages, which then fail authentication #277: a test that overrides a default cannot notice the default
regressing).- Update
internal/distributed/doc.goto describe what the code does. It is the origin of the
linearizability claim that was already corrected once.
Acceptance criteria
-
executeStrongConsistency's N-identical-PUT fan-out replaced by a single conditional write - Taxonomy either deleted or redefined so no two names share one behaviour
-
replicateAsync's purpose named, or the path removed - A1-2: Define richer DistributedCoordinator interface with cache coordination methods #129's
ConsistencyLevelpromotion dropped/revised; A2-6: Implement NegotiateConsistency in coordinator #144 revised or closed - Invalidations carry the ETag they were computed from (R4)
-
broadcastProposalstub and any producerless log-entry scaffolding deleted - Request-count test proving 1 request replaced N
- Concurrent-update test proving no lost update
-
doc.godescribes actual behaviour;-tags=distributedsuite green with no config workarounds - CHANGELOG entry — this is user-facing behaviour change and likely a breaking change to the
distributed config surface
Dependencies
Blocked by #282; #283 where leases apply. Coordinate with #129 and #144.
Reference: docs/design/conditional-writes-vs-raft.md §1 (the R1–R6 table and the
executeStrongConsistency finding), §5.
Activity
docs: record the CAS decision where the code claims otherwise (#286)
fix: a cluster node whose status this build doesn't recognize
fix: a shutting-down node kept running its peers' S3 operations
lint: range over integers, and stop linting a dependency's Go files (#…
feat(s3): a write that happens only if an assertion about the key hol…
feat(distributed)!: replace the N-identical-PUT fan-out with per-key …
feat(types)!: cache coordination on DistributedCoordinator, with stub…
feat(cluster): peers learn which keys are cached elsewhere (#140) (#402)