Skip to content

A2-6: Implement NegotiateConsistency in coordinator #144

Closed as not planned

Description

@scttfrdmn

Summary

Implement NegotiateConsistency in coordinatorWrapper (cluster.go) and wire it into the FUSE read path before ExecuteOperation (A2-4). This gives the distributed layer a principled consistency level for each read rather than silently making assumptions.

Background

The DistributedCoordinator interface (expanded in A1-2) includes NegotiateConsistency(ctx, key, ConsistencyLevel) (ConsistencyLevel, error). The rules are simple and deterministic, making this a low-risk correctness improvement.

Implementation Rules

Condition Return
Only one alive node ConsistencyEventual (no peers to coordinate)
Caller requests ConsistencyStrong AND this node is NOT leader ConsistencySession (downgrade — can't guarantee strong without leader)
Caller requests ConsistencyStrong AND this node IS leader ConsistencyStrong
All other cases Echo the requested level
func (cw *coordinatorWrapper) NegotiateConsistency(
    ctx context.Context,
    key string,
    requested types.ConsistencyLevel,
) (types.ConsistencyLevel, error) {
    aliveCount := cw.cluster.AliveNodeCount()
    if aliveCount <= 1 {
        return types.ConsistencyEventual, nil
    }
    if requested == types.ConsistencyStrong && !cw.cluster.IsLeader() {
        return types.ConsistencySession, nil
    }
    return requested, nil
}

Wire into FUSE read path (A2-4 integration):

level, _ := fs.coordinator.NegotiateConsistency(ctx, key, types.ConsistencyStrong)
if level == types.ConsistencyEventual {
    // peer warmup read is fine
} else {
    // require peer to be current leader or skip peer fetch
}

Acceptance Criteria

  • Unit test covers all three decision cases
  • FUSE read path (A2-4) uses negotiated level to decide whether to attempt peer fetch
  • Single-node case returns ConsistencyEventual without network calls
  • go test -race ./internal/distributed/... passes

Dependencies

  • Requires A1-2 (NegotiateConsistency added to interface, ConsistencyLevel promoted to pkg/types)
  • Requires A2-1 (coordinator wired into FileSystem)
  • Requires A2-4 (FUSE read path with peer fetch)

Activity

  1. added
    type: enhancement
    priority: medium
    area: distributed
    on Apr 7, 2026
  2. added
    effort: small
    on Aug 3, 2026
  3. scttfrdmn commented on Aug 3, 2026

    @scttfrdmn
    OwnerAuthor

    Heads-up from the CAS decision on #169: this issue's premise is going away.

    The Raft build-out (#128, #130, #133, #151) is closed as not-the-direction; per-key S3 conditional
    writes replace it. #284 will delete or redefine the ConsistencyLevel taxonomy, and this issue is
    defined entirely in terms of its three constants.

    The rule table here also depends on the two things #284 is fixing:

    this issue's rule problem
    requested Strong AND leader ⇒ Strong executeStrongConsistency fans the same PUT with the same bytes to N nodes and calls majority success "strong." There is nothing to promise
    requested Strong AND not leader ⇒ downgrade to Session Session and Eventual are nearly the same function today — both execute on targetNodes[0] then replicateAsync. The downgrade lands somewhere indistinguishable from where it started
    one alive node ⇒ Eventual reasonable, but it is the only rule doing work, and it does not need a three-level taxonomy to express

    Under CAS the question a caller is actually asking changes shape: not "which level can you offer
    me"
    but "does this backend support conditional writes" (#282's capability probe) and "do I hold
    the lease"
    (#283). Both are yes/no facts about the world rather than a negotiated level, and both
    fail closed — a backend that cannot do conditional writes makes the feature refuse to start rather
    than silently downgrade.

    So this should be revised or closed as part of #284. Leaving it open and unmilestoned-in-spirit
    for now rather than closing unilaterally: if there is a genuine negotiation left after #284 lands, it
    belongs here; if not, this closes with #284.

    Also note IsLeader() is load-bearing in the proposed implementation. Leadership survives the CAS
    decision — #279 got a three-node cluster electing a single leader race-free — but per §2 of
    docs/design/conditional-writes-vs-raft.md, a leader that loses network still believes it leads,
    so IsLeader() is not safe as a guard on its own. That is exactly the re-assert obligation #283
    exists to enforce.

  4. scttfrdmn commented on Aug 8, 2026

    @scttfrdmn
    OwnerAuthor

    Closing as not planned: #284 deleted ConsistencyLevel, so there is no longer a type for this method to negotiate over. Not a deferral — the thing being negotiated turned out not to exist.

    Why the type went rather than being cut down. ConsistencyEventual, ConsistencySession and ConsistencyStrong all issued the same unconditional PutObject, and differed only in how many nodes issued it and whether the caller waited. So a negotiated level selected the same request either way; the table in this issue would have returned a different string and changed nothing about what happened.

    And the premise under the table does not hold. Every rule keys on leadership, and leadership confers no read guarantee here. Raft's leader can serve a fresh read because it holds the committed state; these nodes hold no state — the bucket does — and a read goes to S3 the same way from a leader and a follower. applyLogEntry has no state machine, so there is nothing a leader is more current about. Downgrading Strong to Session on a non-leader was therefore protecting against a staleness that does not arise from leadership, while the staleness that does arise — a peer's cached copy being older than S3 — is not something leadership tells you about either.

    The residual question is real and belongs to #141. "Should this node fetch this key from a peer's cache, or go to S3?" is a genuine decision, and the answer is a version comparison rather than a consistency level: fetch from the peer if the peer's announced ETag matches what we believe is current, otherwise go to S3. KeyAnnouncement (#129) already carries ETag for exactly this. Filing it under cache warming rather than reopening here, because it is a cache-coherence rule and not a consistency-level negotiation, and because it needs the announcement plumbing #141 builds.

    Two related notes, so nothing is lost with this issue:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: distributedeffort: smallpriority: mediumtype: enhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions