Repository navigation
refactor(cache): delete redis's pub/sub Invalidator, which deleted from the wrong cache (#377) - #383
Merged
Merged
Conversation
…om the wrong cache (#377) `redis.Invalidator` implemented cross-node cache invalidation over Redis pub/sub — `Publish` broadcast "<nodeID>:<key>" on an `objectfs:invalidation` channel, `Subscribe` ran a goroutine that deleted received keys and skipped the node's own broadcasts. Exported, documented, covered by three tests, and started by nothing outside them. The `Cache` itself is wired, so the shipped behaviour was: nodes share a Redis cache, no node publishes, no node subscribes. Wiring it up was the other option. Two findings refuted it, either one sufficient. **It did not do what its name says.** The subscriber's delete was `Cache.DeleteContext`, which is `DEL` against Redis. So a received invalidation deleted the shared copy every node reads from, not a local copy — a cluster-wide cache flush caused by one node's write, strictly worse than the DEL that node had already performed itself. `TestInvalidator_Subscribe_RemoteInvalidation` looked like proof it worked because it pointed both nodes at one miniredis; what it established was that node2 could empty node1's cache. **And no configuration produces the state it was for.** The issue left this open — multilevel.go exists, but whether any configuration puts a local tier in front of the Redis tier was untraced. It does not: `cache.NewFromConfig` is strictly either/or, Redis cache OR `NewMultiLevelCache`, and `initializeLevels` builds only L1 (memory, optionally predictive) and L2 (on-disk). There is no Redis tier for a local tier to sit ahead of. Cross-node invalidation already happens, and not by pub/sub: `FileSystem.invalidate` calls `cache.Delete` on every mutation, which against this cache is one DEL on the one shared copy, so the next Get on every other node misses. One copy of the bytes is the coherence mechanism, and the package doc now says so — which is what the issue asked for on this branch of the decision. Should a local tier ever go in front of Redis, the invalidation needed then is not this one: it would have to reach the local tiers, which a DEL cannot, and carry the ETag it was computed from so it cannot be applied out of order relative to the write that caused it (R4 in docs/design/conditional-writes-vs-raft.md). Fifty lines that delete from the wrong cache are not a head start on that. `Cache.DeleteContext` was added by #179 for the subscriber's context and loses its only caller here, so it goes too rather than remaining an exported second way to do the same thing with no caller — which is the shape of the defect #376 closed. `Cache.Client` existed only to hand `NewInvalidator` a client, and go-redis is now imported by nothing outside this package's own file. Giving `types.Cache` a context is still worth doing and is still a change across four implementations and every call site in internal/fuse; it is not a change to make by way of one method a lint finding produced. Not a behaviour change: nothing outside the deleted tests called any of it. `internal/distributed`'s separate gossip `MessageTypeCacheInvalidate` / `SetCache` / `InvalidateCacheKey` path is also unstarted in production and is deliberately untouched — it belongs to #141, which is about hooking the cache write path to peers, and folding it in here would decide that issue by way of this one. Verified: go build, go vet, gofmt, `make lint` 0 issues, `go test -race -count=1 ./...` exit 0 across 37 packages, coverage gate 36 packages at or above floor. internal/cache/redis holds at 88.0% against its floor of 88 — the deleted code and the tests that covered it left together. `Cache.Delete` is still covered, confirmed by mutation: neutering it fails `TestDelete` and the shared conformance suite's "Delete removes the key". Closes #377
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 #377.
redis.Invalidatorimplemented cross-node cache invalidation over Redis pub/sub — exported, documented, covered by three tests, and started by nothing outside them. TheCacheitself is wired byNewFromConfig, so the shipped behaviour was: nodes share a Redis cache, no node publishes, no node subscribes.The issue framed this as "wire it or delete it," and left one question open as the decider. Both halves of the answer point to deletion, and the first is stronger than the issue's own framing.
It did not do what its name says
The subscriber's delete was
Cache.DeleteContext, which isclient.Del(ctx, c.rkey(key))— aDELagainst Redis itself, not any local cache. So a received invalidation deleted the shared copy every node reads from. That is a cluster-wide cache flush caused by one node's write, strictly worse than theDELthat node had already performed itself.TestInvalidator_Subscribe_RemoteInvalidationlooked like proof it worked because it pointedc1andnode2Clientat the same miniredis. What it established was that node2 could empty node1's cache.And no configuration produces the state it was for
The issue's open question — "
internal/cache/multilevel.goexists, so this is not hypothetical, but I have not traced whether any configuration puts a local tier in front of the Redis tier" — is answerable, and the answer is no:cache.NewFromConfigis strictly either/or:redis.NewCachewhencluster.enabled && cluster.redis.enabled, otherwiseNewMultiLevelCache. Never one in front of the other.MultiLevelCache.initializeLevelsappends only L1 (LRU, optionally predictive-wrapped) and L2 (persistent). There is no Redis tier for a local tier to sit ahead of.Cross-node invalidation already happens, and not by pub/sub
FileSystem.invalidate(internal/fuse/filesystem.go:1504) callscache.Deleteon every mutation. Against this cache that is oneDELon the one shared copy, so the nextGeton every other node misses. One copy of the bytes is the coherence mechanism — which the package doc now says, per the issue's instruction to explain why a shared keyspace does not need this.Should a local tier ever go in front of Redis, the invalidation needed then is not this one: it would have to reach the local tiers, which a
DELcannot, and carry the ETag it was computed from so it cannot be applied out of order relative to the write that caused it (R4 indocs/design/conditional-writes-vs-raft.md). Fifty lines that delete from the wrong cache are not a head start on that.What else went
Cache.DeleteContext— added by 570 pre-existing golangci-lint issues, 385 of them paralleltest: burn down the backlog the new config surfaced #179 for the subscriber's context, loses its only caller here. It goes too rather than remaining an exported second way to do the same thing with no caller, which is the shape of the defect ReadAheadManager.Stop has no production caller; the unmount path relies on context cancellation alone #376 closed. Givingtypes.Cachea context is still worth doing and is still a change across four implementations and every call site ininternal/fuse; it is not a change to make by way of one method a lint finding produced.Cache.Client— existed only to handNewInvalidatora client. go-redis is now imported by nothing outside this package's own file.Deliberately out of scope
internal/distributed's separate gossipMessageTypeCacheInvalidate/SetCache/InvalidateCacheKeypath is also unstarted in production. It belongs to #141, which is about hooking the cache write path to peers; folding it in here would decide that issue by way of this one.Verification
go build ./...,go vet ./...,gofmtcleanmake lint— 0 issuesgo test -race -count=1 ./...— exit 0, 37 packagesinternal/cache/redisholds at 88.0% against its floor of 88, because the deleted code and the tests that covered it left togetherCache.Deleteneutered →TestDeletefails and the shared conformance suite'sDelete removes the keyfails. Reverted, 0 markers left.Not a behaviour change: nothing outside the deleted tests called any of it.