Repository navigation
fix: the cluster.redis block selects the cache a mount actually uses (#178) - #259
Merged
Merged
Conversation
cache.NewFromConfig — the only reader of cluster.redis.* anywhere in the repository — had no caller. Adapter.Start built a MultiLevelConfig literal of its own instead, so seven cluster keys plus a seven-key redis sub-block were decoded, defaulted, validated and documented while no mount consulted any of them. A deployment that configured a shared Redis cache got a private in-process one, with no error and no warning, and looked correct until two nodes disagreed about a file. Third instance of the shape #156 and #176 were. Both halves of that mistake are fixed together, because they are the same mistake. NewFromConfig's other arm passed a literal nil to NewMultiLevelCache, discarding the L1/L2 sizing, the TTL, the persistent-cache directory and the eviction policy its argument carried — so even with a caller, most of the cache: block would still have been ignored. The mapping now lives in internal/cache beside the selection rather than in the adapter, since a second copy of it is how the two came to disagree in the first place, and Adapter.cache is typed as types.Cache: naming the concrete *cache.MultiLevelCache there is what made the function uncallable, as the field could not hold what it returns. An unreachable Redis fails the mount rather than falling back. Falling back is this same defect one layer out — both nodes come up, both believe the cache is shared, and nothing in either log explains the disagreement — so the error names cluster.redis and the mount does not start. Wiring it up first would have put a contract-violating cache on the read path, which is why the conformance suite came first. internal/cache/cachetest is a shared suite every types.Cache implementation is now run against. There were five implementations, one contract, and no test in common — each was checked against the questions its own author thought to ask, and that is why four of them satisfied a rule the fifth violated in the most consequential direction: the Redis cache answered a ten-byte request with two bytes. GETRANGE clamps to the stored value's length, so `GETRANGE k 8 17` over a ten-byte value returns two bytes and no indication that eight are missing. internal/fuse passes a non-nil hit to the kernel verbatim as file content, so that is a truncated read reported as a successful one — audit finding H7's shape arriving through a different door. It had ten tests of its own, all passing, none of which asked for a range longer than what was stored. Ten cases, each stating in its failure message what a caller would observe: exact-range hits, straddling and past-the-end reads as misses, a request longer than the entry as a miss, the open-ended size <= 0 form, the returned slice not aliasing the cache's own storage, a newer Put winning where it overlaps, and Delete removing the key it names and nothing that merely shares a prefix with it. A sixth implementation is one enrollment away. The adapter-level test drives Adapter.Start itself against a substrate-backed S3 endpoint and miniredis, because internal/cache's own tests can show that NewFromConfig selects a Redis cache and only this one can show that a mount does — which is the entire defect. It reads the stored key back out of the Redis server rather than asserting the type alone, and tolerates only the mount step failing, since that is the one step a host without a FUSE helper cannot perform and the cache is built four steps earlier. NewCache and NewFromConfig take a context for the connectivity check, which neither cache retains: a cache lives as long as the mount does, so a startup context stored inside one would cancel every later operation the moment startup returned. Closes #178
…host does The two Adapter.Start tests failed in CI and passed locally, and the difference was the machine rather than the code: buildS3Config deliberately maps no credential fields, so an adapter built from a Configuration gets its credentials from the AWS default chain — and on a developer machine that chain finds the ambient profile. In CI there is none, so it reaches EC2 IMDS, NewBackend's closing HealthCheck fails, and Start never gets as far as building the cache. The probe that convinced me these tests needed no credentials was run in this shell, with credentials in it, so it could only ever have said yes. TestMain sets the pair for the whole binary. Not t.Setenv, which cannot be called from a parallel test and mutates process-wide state that other parallel tests in the package read. Verified the way CI failed: with the environment stripped and HOME pointed at an empty directory, the package fails exactly as the job did, and passes with TestMain restored.
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 #178.
The defect
cache.NewFromConfig— the only reader ofcluster.redis.*anywhere in the repository — had no caller.Adapter.Startbuilt aMultiLevelConfigliteral of its own instead, so sevenclusterkeys plus a seven-keyredissub-block were decoded, defaulted, validated and documented while no mount consulted any of them. A deployment that configured a shared Redis cache got a private in-process one, with no error and no warning, and looked correct until two nodes disagreed about a file.Third instance of the shape #156 and #176 were: a config block whose every layer worked except the one that had to call it.
Both halves are fixed together, because they are the same mistake.
NewFromConfig's other arm passed a literalniltoNewMultiLevelCache, discarding the L1/L2 sizing, the TTL, the persistent-cache directory and the eviction policy its argument carried — so even with a caller, most of thecache:block would still have been ignored. The mapping now lives ininternal/cachebeside the selection rather than in the adapter, since a second copy of it is how the two came to disagree in the first place.Adapter.cacheis typedtypes.Cache: naming the concrete*cache.MultiLevelCachethere is what made the function uncallable, as the field could not hold what it returns.An unreachable Redis fails the mount rather than falling back. Falling back is this same defect one layer out — both nodes come up, both believe the cache is shared, and nothing in either log explains the disagreement.
What wiring it up would have shipped
A contract-violating cache on the read path. So the conformance suite came first, and it found one.
internal/cache/cachetestis a shared suite everytypes.Cacheimplementation is now run against. There were five implementations, one contract, and no test in common — each checked against the questions its own author thought to ask. That is why four of them satisfied a rule the fifth violated in the most consequential direction: the Redis cache answered a ten-byte request with two bytes.GETRANGEclamps to the stored value's length, soGETRANGE k 8 17over a ten-byte value returns two bytes and no indication that eight are missing.internal/fusepasses a non-nil hit to the kernel verbatim as file content, so that is a truncated read reported as a successful one — audit finding H7's shape arriving through a different door. It had ten tests of its own, all passing, none of which asked for a range longer than what was stored.Ten cases, each stating in its failure message what a caller would observe: exact-range hits, straddling and past-the-end reads as misses, a request longer than the entry as a miss, the open-ended
size <= 0form, the returned slice not aliasing the cache's own storage, a newerPutwinning where it overlaps, andDeleteremoving the key it names and nothing that merely shares a prefix with it. A sixth implementation is one enrollment away.Tests
TestStartReachesTheCacheTheConfigNamesAdapter.Startagainst a substrate-backed S3 endpoint plus miniredis, and reads the stored key back out of the Redis server rather than asserting the type aloneTestStartRefusesAnUnreachableRedisTestCacheHonorsTheCacheContract×5TestNewFromConfigReturnsTheImplementationTheConfigNamesNotNil, which holds for eitherTestMultiLevelConfigFromMapsEveryConfiguredValuecache:block reaching the cache, values spelled out rather than recomputed from the inputMutation-verified, all four ways: reverting
Startto the hand-built literal fails both adapter tests; removing the length check inredis.Cache.Getfails exactly the two conformance cases about short answers.Adapter.Start's mount step is tolerated because a host without a FUSE mount helper cannot perform it, and the cache is built four steps earlier. Skipping would be worse — the wiring under test is testable on every host, and a skip would silently retire the test on the machines that run it most.Gates
go build·go vet· fullgo test -race ./...clean · coverage gate 30 packages at or above their floor, withinternal/cacheratcheted 82 → 85 andinternal/cache/redis87 → 88 ·golangci-lint --new-from-merge-base=origin/main0 issues · markdownlint on the touched docs.NewCacheandNewFromConfigtake a context for the connectivity check, which neither cache retains — a cache lives as long as the mount does, so a startup context stored inside one would cancel every later operation the moment startup returned. Thecontextcheckfinding on the in-process arm is suppressed with the reason at the call site: whatctxwould reach there is the prefetch workers, which are stopped byCloseon the unmount path and would otherwise never fetch anything.Docs
docs/index.md's Not yet wired up table loses its Redis row.examples/config.yaml'scluster:comment no longer saysNewFromConfig"currently has no caller" and states what setting both flags does, including the refusal.