Skip to content

CAS-3: Replace executeStrongConsistency's N-identical-PUT fan-out, and fix the consistency taxonomy #284

Closed

Description

@scttfrdmn

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. ConsistencyStrong fans to
    all N and counts a majority; ConsistencySession executes on targetNodes[0] then
    replicateAsyncs the rest; ConsistencyEventual executes on targetNodes[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.executeLocally calls 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
    ConsistencyLevel and the three execute*Consistency functions, 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:

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
    ErrPreconditionFailed and 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.go to 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 ConsistencyLevel promotion dropped/revised; A2-6: Implement NegotiateConsistency in coordinator #144 revised or closed
  • Invalidations carry the ETag they were computed from (R4)
  • broadcastProposal stub and any producerless log-entry scaffolding deleted
  • Request-count test proving 1 request replaced N
  • Concurrent-update test proving no lost update
  • doc.go describes actual behaviour; -tags=distributed suite 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: distributedbreaking changeeffort: largepriority: hightype: bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions