Skip to content

feat(cluster): make cluster.enabled actually start cluster coordination (#139) - #401

Merged
scttfrdmn merged 2 commits into
mainfrom
feat/139-cluster-wiring
Aug 9, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
feat/139-cluster-wiring

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #139.

cluster.enabled: true did nothing. Every part of internal/distributed was built and tested and
reached no mount, because nothing in internal/adapter constructed a ClusterManager: the flag
selected a Redis cache through cache.NewFromConfig and otherwise had no effect, so a two-node
deployment got no cache invalidation and no key announcements while its configuration said it was
clustered.

What this wires

Adapter.startCluster (step 5 of Start, before the mount) constructs the manager, injects the
backend and cache, and starts it. Adapter.clusterCoordinator() hands the coordinator to
MountConfig → fuse.Config → FileSystem.coordinator. Stop tears it down in step 3.

The teardown window is the one that is correct in both directions: after the write-path flush,
which is the last chance for this node's pending writes to become durable, and before the backend
and cache close, because the gossip receive loop executes peers' operations against the backend and
evicts from the cache.

Nil is the single-node value, and the guard cannot move

clusterCoordinator() returns a nil interface when clustering is off. Two things go wrong without
that method:

  • GetCoordinator() dereferences cm.coordinator, so calling it on a nil manager panics — that
    is what every single-node mount would do, on every start.
  • Pushing the check inside GetCoordinator would not help: it returns &coordinatorWrapper{...}, a
    non-nil types.DistributedCoordinator whatever it wraps, so a mount handed one would take the
    coordinated branch at every if fs.coordinator != nil in internal/fuse and dereference the
    nothing inside.

Verified by mutation, which is how both failure modes were found — the first comment I wrote here
claimed only the typed-nil case.

Raft stays unstarted

buildClusterConfig deliberately does not set EnableConsensus, and the config schema has no key for
it. Coordination in ObjectFS is compare-and-swap against S3 (the recorded 2026-08-03 decision), so a
mount has no use for a leader, and putting an election on the path of a filesystem read would make a
cluster that cannot hold a quorum degrade a mount that never needed one.

The adapter test asserts the request (buildClusterConfig().EnableConsensus == false) and says so
explicitly, because from the adapter the behavior is unmeasurable: ElectionTimeout is not
operator-facing, so the cluster runs on the 5s default and a freshly started node has held no election
either way. Leadership assertions at that level pass with the gate removed. The behavioral half lives
in TestClusterManager_Start_DoesNotStartConsensusUnlessAskedTo, which sets 20ms and watches ~25
timeouts pass.

Failing closed, and the breaking change that follows

A cluster that cannot start fails the mount rather than degrading to a single node. Coordination
is a correctness capability, not a performance one: a node that believes it is clustered and is not
serves cached bytes a peer has already overwritten, with nothing in its logs to say why. That is the
project thesis's rule for this kind of capability, and the same reasoning the Redis cache already
follows.

BREAKING: because cluster.enabled gates both subsystems, an existing Redis-only deployment now
needs a gossip secret. Found from a real failure in TestStartReachesTheCacheTheConfigNames, not
predicted. It is justified rather than papered over: a shared cache with no invalidation between its
users is exactly the incoherence the cluster block exists to prevent. Recorded in the CHANGELOG under
### Changed.

Two adjacent defects the wiring made reachable

  • cluster.secret_file did not exist. LoadClusterSecret's error had been telling operators to
    "set OBJECTFS_CLUSTER_SECRET or cluster.secret_file" — a key absent from the schema. Added, with
    the path-not-secret and mode-0600 requirements documented; the env var still takes precedence.
  • examples/config.yaml described the old behavior, including a comment asserting that the block
    started nothing and that secret_file's absence was deliberate. Rewritten, with an
    openssl rand -hex 32 && chmod 600 recipe.

Tests

internal/adapter/cluster_wiring_test.go (5 tests): the no-op-unless-enabled path, gossip actually
binding and the coordinator reaching the mount, the consensus request, the operator settings carried
across two disjoint ClusterConfig types, and the missing-secret mount failure.
internal/fuse/coordinator_wiring_test.go (2 tests) goes through the real
CreatePlatformMountManager and testaws rather than constructing a FileSystem by hand.

Verified: go build ./..., gofmt -l ., go vet ./... clean; go test -race -count=1 ./... and
-count=2 -tags=distributed ./internal/distributed/... pass; golangci-lint run --new-from-merge-base=origin/main reports 0 issues.

…on (#139)

Every part of internal/distributed was built, tested, and reached by nothing.
No code path outside that package constructed a ClusterManager, so a two-node
deployment whose configuration said it was clustered got no membership, no
cache invalidation and no warming: the cluster: block's only live effect was
selecting a Redis cache through cache.NewFromConfig.

internal/adapter now builds one when cluster.enabled is set, injects the
backend and cache before Start (so the gossip receive loop cannot dispatch a
peer's message at a nil either), starts it before the mount, and stops it
during teardown — after the write-path flush, before the backend and cache
close, which is the one window correct in both directions. The coordinator
travels down through MountConfig and CreatePlatformMountManager to
FileSystem.coordinator, where #140 and #141's calls will read it.

buildClusterConfig is the only conversion between the two disjoint
ClusterConfig types, which is most of why this issue existed: seven
operator-facing fields on one side, eighteen on the other, and no function
anywhere that turned one into the other.

Two things this deliberately does not do.

It does not start Raft. ClusterConfig.EnableConsensus is new, off by default,
and a mount leaves it off: coordination here is compare-and-swap against S3,
so a filesystem read consults no leader, and an election on that path would
make a cluster below quorum degrade a mount that never needed one. The engine
is still constructed, so gossip's vote and append-entries arms stay harmless
without their own guards — with no election loop this node never becomes a
candidate and has no term to defend. The -tags=distributed suite drives
elections deliberately and is untouched; testConfig opts in.

And it does not degrade. A cluster that cannot start fails the mount with the
reason. Coherence is a correctness capability, and a node that believes it is
clustered and is not serves cached bytes a peer has already overwritten with
nothing in its logs to say why — the thesis's fail-closed rule.

Also here, because wiring the cluster is what made it reachable:

cluster.secret_file, the key LoadClusterSecret's error message had been
telling operators to set before it existed. The path, never the secret; the
file must be mode 0600 or startup refuses it; OBJECTFS_CLUSTER_SECRET still
takes precedence.

ClusterManager.GossipAddr, so a test can tell a bound socket from a manager
that exists. A manager whose Start failed reports its configuration back just
as happily as a running one, and "127.0.0.1:0" is not an address any peer can
be told about.

BREAKING: cluster.enabled: true now requires a gossip secret, including for a
deployment that set it only to get Redis. The coupling is deliberate — a
shared cache with no invalidation between its users is the incoherence the
block exists to prevent — but it will fail an existing config at startup, so
it is in the changelog under Changed rather than buried here.

Verification, all by mutation rather than prediction:

- dropping fuseConfig.Coordinator = config.Coordinator fails
  TestCoordinatorReachesTheFilesystem
- removing clusterCoordinator's nil guard panics
  TestStartClusterIsANoOpUnlessEnabled: GetCoordinator dereferences the
  manager, so the guard is load-bearing at every single-node start, not only
  in the typed-nil case
- degrading a construction failure to a warning fails
  TestStartClusterFailsTheMountWithoutASecret on the missing error
- dropping SeedNodes and SecretFile from the mapping fails
  TestBuildClusterConfigCarriesTheOperatorSettings on both
- setting EnableConsensus fails TestStartClusterDoesNotAskForConsensus

What the adapter-level test deliberately does not assert is the *behavior* of
consensus being off — no leader, no term, follower state. ElectionTimeout is
not operator-configurable, so from there the cluster runs on the 5-second
default and a freshly started node has held no election either way; those
assertions would pass with the gate removed. They live in
TestClusterManager_Start_DoesNotStartConsensusUnlessAskedTo, which can set
20ms and watch ~25 timeouts pass.
…ytes

A prefetch is queued and the reader does not wait for it, so under load the
reader can consume the front of the very range predicted for it before a
worker picks the request up.

Neither existing guard sees those reads. They have *finished*, so `finish`
removed them from the in-flight set that `unclaimedStart` consults, and the
prefetch's full range is not a cache hit either — its tail was never cached,
and a partial hit is a miss because a cache that is never told an object's
length cannot tell a short object from a partially-cached one. So the
prefetch re-read the overlap.

Measured on CI, which is loaded enough for the queue to fall behind: a 16 KiB
file read in 1 KiB steps transferred 18432 bytes across GETs of 0-1023 …
4096-5119 and then 3072-16383, the last re-reading 2048 bytes the reads at
3072 and 4096 had already fetched. The identical traversal passed locally 28
times in a row, because there the worker kept up and the in-flight trim
caught it. That is why the end-to-end test could not pin this: whether the
duplication happens is a race between a prefetch worker and the
application's next read(2).

performPrefetch now advances past what the reader has consumed, reading the
detector's own ReadPattern rather than probing the cache. A probe per
candidate prefix would allocate bytes only to discard them, and — the reason
it is not merely wasteful — every probe would land in the hit and miss
counters the read path exports, scoring the prefetcher as a reader. The bound
is conservative in the safe direction: a read the detector never saw leaves
it behind where the reader is, so a prefetch trims less than it could; it can
never run ahead and leave a hole the following read pays full price for.

Trimming rather than skipping, and the new test asserts both directions,
because dropping the prefetch outright also stops the byte count exceeding
the file — by turning read-ahead off. TestPrefetchSkipsRangeTheReaderHasAlreadyRead
removes the race instead of trying to win it: no workers drain the queue, the
reads run to completion, and performPrefetch is called directly with the
request the detector queued several reads earlier. Verified by mutation in
both directions — without the trim it reproduces CI's 18432 bytes and its
exact ranges; with the trim replaced by a return it reports the prefetch
fetching nothing.
@scttfrdmn
scttfrdmn merged commit 9c5e509 into main Aug 9, 2026
35 checks passed
@scttfrdmn
scttfrdmn deleted the feat/139-cluster-wiring branch September 20, 2026 05:25
scttfrdmn added a commit that referenced this pull request Oct 9, 2026
… that every test tag is executed (#570) (#596)

ci.yml's build-tags job vets seven tags and runs none. Two of them, e2e and
distributed, need nothing, and both were red the first time they ran:

- e2e asserted wording the code had since improved past: "unsupported
  storage scheme" and "bucket name" for messages that now name the
  rejected scheme and say the URI names no bucket, and "ObjectFS version"
  for the lowercase line e8750eb made deliberate. The two validation
  assertions now check what the message must tell the operator rather
  than its phrasing.
- distributed waited on a consensus engine that #401 made opt-in while
  keeping it "because the -tags=distributed suite drives elections
  deliberately". Nothing in the suite turned it on. The three tests that
  assert an election now set EnableConsensus: true. Passes 21/21 over
  -count=3.

The issue's earlier note that both passed was wrong; run tag-only with
credentials denied, both failed.

New tagged-suite job, matrix [e2e, distributed], named tagged-suite (<tag>):
finds the packages and the tag-only tests itself, runs them with -race and
AWS credentials denied, requires a PASS for each, and fails on any SKIP. Its
package paths are forced to ./dir, because BSD grep prints tests/x where
GNU prints ./tests/x and go reads a bare tests as a standard-library path;
found by dry-running the step on macOS.

TestEveryTestTagIsExecuted fails when a build tag used by a _test.go file is
passed to no workflow's go test, resolving literals, matrix.tag, and $TAG
via step env. integration, aws_s3 and s3compat (#570) and benchmark (#568)
are exempt with their issues, and an exemption fails once its tag is
executed or gone. Floors: six tags in the tree, and fuse_mount and e2e
must resolve as executed.

Mutations: dropping distributed from the matrix, a stale e2e exemption, and
a new unexecuted tag each fail named. Removing -tags from the fuse-mount run
and breaking the $TAG indirection survived twice, because the go test -list
discovery line beside each was credited as an execution: once because -list
was not checked at all, then because it was checked against a match that
ends before -list. Lines carrying -list are now skipped, and both fail.
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.

A2-1: Wire ClusterManager into Adapter and FileSystem

1 participant