Repository navigation
feat(cluster): a write on one node evicts what its peers cached (#141) - #403
Merged
Merged
Conversation
#140 gave the cluster the vocabulary. This is the read and write paths using it: a read that misses announces the range it cached, and a flush, an unlink, an rmdir, a mkdir, a create and both halves of a rename invalidate on every peer as well as locally. Until this, every part of the invalidation machinery existed and nothing called it, so a two-node deployment served a file's previous contents for up to five minutes after another node overwrote it. The invalidation carries the ETag the write itself reported, which is why vfs.Writer grows FlushReportingETag: a receiver's replay ledger is keyed on (key, version), so a version from a later HeadObject could name a third node's subsequent write and suppress an invalidation that was never applied. A delete sends an empty version, which means "evict whatever you hold" and can never serve wrong bytes. Local and remote eviction go through one call, because the half a future mutation path would forget is the remote one — invisible on a single-node mount. An announcement is sent only when this node already knows the object's version, from the stat the kernel issues before any read. With none known, nothing is announced rather than a version invented: a peer that fetches bytes it cannot place against an object version hands them to a reading process as file content. Both directions are fire-and-forget and neither fails a syscall, but a lost announcement costs a peer an S3 read (Debug) while a lost invalidation means peers serve replaced bytes until their TTL expires with nothing else reporting it (Warn). Tests. Ten in internal/fuse against a recording coordinator, a real S3 endpoint and a real cache — including that a read with no known version announces nothing, that a failing announce or invalidate still returns errno 0 with the right bytes stored, and that a nil coordinator changes neither the bytes read nor the bytes written. Two in internal/distributed drive two real filesystems over two real gossip sockets and assert node B's cached bytes are gone after node A writes and after node A unlinks; that placement is verified by compiling an import-cycle probe, not assumed. Fifteen mutations were applied to the production code and fifteen were killed, one of which found a real weakness rather than confirming a strength: the create subtest released its handle, and Release flushes, so it passed with Create's own invalidation removed. Benchmarks establish the "no regression with a nil coordinator" criterion, which had nothing in the repository to compare against — a cached 128 KiB read is 4.8 µs and 2 allocations with or without a coordinator, since a hit never reaches the announce call. The three guards that keep those benchmarks honest are mutation-killed too. They use an in-memory backend rather than internal/testaws because emulator.StartTestServer takes a *testing.T concretely, filed upstream as substrate#605. Closes #141
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 #141. Third of the warming chain, after #399 and #140.
What this is
#140 gave the cluster the vocabulary —
AnnounceKey,QueryKeyOwnership,InvalidateKeyover gossip. This is the read and write paths using it:Until this, every part of the invalidation machinery existed and nothing called it. A two-node deployment served a file's previous contents for up to five minutes after another node overwrote it, with nothing in the logs to say so.
Three decisions worth review
The invalidation carries the ETag the write itself reported. This is why
vfs.WritergrowsFlushReportingETagandFileHandle.Flushasks for it. A receiver's replay ledger is keyed on(key, version), so a version fetched from a laterHeadObjectcould name a third node's subsequent write and suppress an invalidation that was never applied. A delete has no version to name and sends an empty one — legal, means "evict whatever you hold", and cannot serve wrong bytes. An empty ETag with a nil error is a legitimate answer from the flush and is documented as such in three places, because reading it as a failure would fail writes that succeeded.Local and remote eviction go through a single call. Every mutation already called
invalidate; a cluster call sitting beside each of those as a separate statement is a pair a future mutation path can add one half of, and the half easier to forget is the remote one — invisible on a single-node mount and on every test that does not run two nodes.An announcement without a known version is not sent. The ETag comes from the metadata cache, populated by the stat the kernel must issue before any read. With nothing there, nothing is announced rather than a version being invented: a peer that fetches bytes it cannot place against an object version hands them to a reading process as file content. The gap that remains — an overwrite between the stat and the GET — costs a peer a rejected fetch and an S3 read, which is what it would have had with no announcement at all. That reasoning is in the code, at
announceCached.Both directions are fire-and-forget and neither fails a syscall. They are not logged alike: a lost announcement costs a peer an S3 read, which is slower and nothing more (Debug), while a lost invalidation means peers serve bytes this node replaced until their cache TTL expires and nothing else in the system reports it (Warn).
Tests
internal/fuse/coordinate_test.go— ten tests against a recording coordinator, a real S3 endpoint viainternal/testaws, a real byte-range cache and a real write path. The coordinator is the only mock and the file says why: what is under test is which announcements and invalidations this package makes with which fields, and a call whose errors are logged and never returned cannot be observed any other way. The metadata cache is deliberately not mocked — the announcement's ETag comes from it, so a fake there would let the announce path pass while reading a version production does not have.Covered: the announcement's Size is the object's and its Length is the range's (not collapsed);
NodeIDis left empty because this package does not know it and the coordinator overwrites it; a read with no preceding stat announces nothing; a failing announce or invalidate still returns errno 0 with the right bytes read and stored; the metadata key is invalidated too, with an empty ETag; every delete-shaped operation invalidates with no version; a nil coordinator changes neither the bytes read nor the bytes stored.internal/distributed/fuse_twonode_test.go— the two-node criterion, and nothing here is mocked but the second host. Two real filesystems, two real gossip sockets on loopback via the existingstartGossipPair, one shared bucket. Node A writes throughCreate→Write→Flush(the node entry points, so a test cannot pass with #141 reverted) and node B's cached bytes are gone; then the same forUnlink, which is worth its own test because an unversioned invalidation takes a different branch inhandleCacheInvalidateand bypasses the applied-once ledger. It lives ininternal/distributedbecauseinternal/fusecannot reachstartGossipPairor a*ClusterManager's unexported gossip field, and the absence of an import cycle was verified by compiling a probe rather than reasoned about.Mutation testing. Fifteen mutations applied to the production code, fifteen killed: announce field swaps, a zeroed
CachedAt, a fabricated ETag, a zero-length announce, the dropped metadata-key invalidation, an empty and a bogus flush ETag, all four per-operation invalidations, both rename halves, and two end-to-end (flush and unlink downgraded to local-only, caught by the two-node tests).One of those found a real weakness rather than confirming a strength: the create subtest released its handle,
Releaseflushes, and the flush invalidates the same key — so it passed withCreate's own invalidation removed. The handle is now left unreleased and the finding is recorded in the test.Benchmarks
#141's criterion asks for no regression with a nil coordinator, and there was nothing anywhere in the repository to compare against: its benchmarks cover the cache, the S3 backend and URI validation, none of which run the FUSE read path. So the comparison is established rather than asserted against a number nobody measured.
The cached pair is the criterion and the two are indistinguishable — a hit never reaches the announce call. The miss pair is where the work is: ~3.2 µs and 10 allocations, nearly all of it the metadata-cache read the ETag comes from, against a call that in production is followed by a UDP fan-out.
Three guards keep those figures honest and all three are mutation-killed: the cached benchmark asserts zero backend requests inside its timed loop, the cached-with-coordinator one asserts zero announcements, and the uncached-with-coordinator one asserts one announcement per iteration — without that last, it would happily report a figure for the early-return path, which is identical to the nil-coordinator path by construction.
They use an in-memory
types.Backendrather thaninternal/testaws, which is a departure from this package's convention and is justified in the file.emulator.StartTestServertakes a*testing.Tconcretely andtesting.TBhas an unexported method, so no cast bridges a*testing.Bto it — filed upstream as substrate#605. It does not weaken the measurement: the cached pair proves the backend is never reached inside its loop, and for the uncached pair an in-memory GET makes any coordinator overhead a larger fraction of the total than it would be against S3, so "no meaningful difference" holds a fortiori.Verification
go build ./...,gofmt -l .,go vet ./...— cleango test -race -count=1 ./...— cleango test -race -count=1 -tags=distributed ./internal/distributed/...— cleangolangci-lint run --new-from-merge-base=origin/main— 0 issuesinternal/fuse69.4%,internal/vfs98.4%,internal/distributed81.8%-count=5, figures aboveOne known mutation survivor, pre-existing and documented in both the code and
internal/vfs/flush_etag_test.go: theif n.Dirty()guard inFlushReportingETagis unreachable by design.