Skip to content

refactor(cache): delete redis's pub/sub Invalidator, which deleted from the wrong cache (#377) - #383

Merged
scttfrdmn merged 1 commit into
mainfrom
chore/delete-redis-invalidator-377
Aug 8, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
chore/delete-redis-invalidator-377

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #377.

redis.Invalidator implemented cross-node cache invalidation over Redis pub/sub — exported, documented, covered by three tests, and started by nothing outside them. The Cache itself is wired by NewFromConfig, 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 is client.Del(ctx, c.rkey(key)) — a DEL against 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 the DEL that node had already performed itself.

TestInvalidator_Subscribe_RemoteInvalidation looked like proof it worked because it pointed c1 and node2Client at 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.go exists, 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.NewFromConfig is strictly either/or: redis.NewCache when cluster.enabled && cluster.redis.enabled, otherwise NewMultiLevelCache. Never one in front of the other.
  • MultiLevelCache.initializeLevels appends 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) calls cache.Delete on every mutation. Against this cache that 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 — 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 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.

What else went

Deliberately out of scope

internal/distributed's separate gossip MessageTypeCacheInvalidate / SetCache / InvalidateCacheKey path 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 ./..., gofmt clean
  • make lint — 0 issues
  • go test -race -count=1 ./... — exit 0, 37 packages
  • coverage gate — 36 packages at or above floor; internal/cache/redis holds at 88.0% against its floor of 88, because the deleted code and the tests that covered it left together
  • mutation: Cache.Delete neutered → TestDelete fails and the shared conformance suite's Delete removes the key fails. Reverted, 0 markers left.

Not a behaviour change: nothing outside the deleted tests called any of it.

…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
@scttfrdmn
scttfrdmn merged commit a5f3b9c into main Aug 8, 2026
33 checks passed
@scttfrdmn
scttfrdmn deleted the chore/delete-redis-invalidator-377 branch August 8, 2026 08:03
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.

cluster.redis's pub/sub Invalidator is never started, so a Redis cache is shared but never invalidated

1 participant