Skip to content

feat(cluster): warm a cold read on a peer's evidence, and a joiner on a join (#142, #143) - #404

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/peer-informed-cache-warming
Aug 9, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/peer-informed-cache-warming

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #142, closes #143. The last two issues in the v0.13.0 warming chain.

What this does

A cache miss asks the cluster who holds the key. If a peer holds a range reaching past what was just read, this node reads ahead to the end of that range — from S3, capped at 4 MiB per miss. And a node answering a join follows the membership sync with a cache_warmup message listing the keys it holds, which the joiner records as ownership claims.

Both issues specified something the transport cannot do

#142 planned to fetch the bytes from the peer via ExecuteOperation(&types.ReadOp{...}). A gossip datagram carries 5802 bytes of object at the default limit, so a 128 KiB kernel read is 21× over and fails as a 30-second timeout on the requesting host (#399 made that failure honest, which is what made this rescope possible). What a peer's claim is actually evidence of is that the key is hot in this cluster — the one thing a cold node cannot learn on its own — and that is worth acting on even when the bytes still cost an S3 read. PeerFetchTimeout is deliberately not added: it would describe a code path that does not exist.

#143 specified "max 256 entries per warmup message" and cache.Warmup(keys) on receipt. Neither works:

  • Measured against the real seal path, 256 announcements with 52-character keys seal to 65631 bytes against the 8192-byte default — 8× over. Every warmup datagram would be refused at the socket and a joiner would warm nothing at all. 31 fit. And 31 is not a constant to write down instead, because it moves with key length — so the chunk is grown one entry at a time and the whole message sealed to check, reusing syncChunkFits's shape. A count cannot bound a byte limit.
  • MultiLevelCache.Warmup is one GetObject per key, so calling it on a warmup message turns cold-start into an egress burst. The criterion "100% hit rate before any S3 request" cannot pass against it under any bound — Warmup is the S3 request. Recording the announcements delivers what that criterion was reaching for, and costs nothing.

Both issue bodies have been rewritten to match.

Design notes worth a reviewer's attention

A claim is acted on only at the version this node is reading. A holder's range describes the object it cached; against another version the object may have a different length entirely, so warming on it fetches bytes chosen by a claim about something else. A mismatch — or no known version on either side — warms nothing, which costs exactly the read the application asked for. Same fail-closed rule announceCached applies in the other direction.

selfAnnounced is a second map beside announcements, and the separation is load-bearing. announcements answers QueryKeyOwnership, which is asked because this node's cache missed, so a self-claim there is a holder guaranteed not to hold, returned in place of a peer that does. And the cache cannot be enumerated instead: types.Cache stores bytes with no version beside them, so the only record of what this node holds and at which version is what it announced. The existing sweep now covers both maps — the second is the half that would have leaked silently, since recentHoldings filters expired entries on read.

The warm goes through the prefetch queue, so it inherits EOF clamping, skipping what is cached, standing off in-flight reads, and flight-sharing. It does not touch the read pattern: another node's reads must not decide whether this reader looks sequential. It is called from FileHandle.Read and never from fetchUncached, so a warm's own GET cannot query ownership and queue another — a warm cannot feed itself and walk the object.

read_ahead.enabled: false suppresses the warm and the ownership query both, rather than asking peers once per cache miss and discarding the answer.

Verification

  • go test -race ./... — clean, whole repo, not -short
  • go test -race -tags=distributed ./internal/distributed/... — clean
  • go build ./..., gofmt -l, go vet ./internal/..., golangci-lint run --new-from-merge-base=origin/main — clean
  • 30 new tests: 16 in internal/distributed/cache_warmup_test.go, 14 in internal/fuse/warm_test.go

Mutation-verified, thirteen guards, each breakage failing a named test. Two initially survived and both were test defects, now fixed:

  • TestJoinWarmsTheJoiner cleared the joiner's ownership map after announcing. Delivery is asynchronous on the joiner's receive goroutine, so a broadcast still in flight lands after the clear — that version passed with recordSelfHolding deleted entirely. The joiner is now removed from the sender's memberlist before anything is announced, and the test asserts zero announcements arrived, so the join is provably the only channel. It also surfaced that testConfig advertises 127.0.0.1:0, which is a request for a free port rather than an address anything can reply to.
  • A separate empty-holdings guard in sendCacheWarmup duplicated the send loop's own break, so no test could distinguish them. Removed, with the reasoning recorded where the remaining check lives.

The #142 assertions are on decisions and on effects: most read the prefetch queue with no workers draining it (deterministic, per read_path_test.go's hard-won precedent), but TestWarmingReallyFetchesTheRange runs a real worker and asserts the warmed range lands in the cache with the right bytes and came from S3 — queue assertions alone would pass against a warm that queued onto a channel nothing read.

… a join (#142, #143)

A cache miss now asks the cluster who holds the key and, when a peer holds a
range reaching past what was just read, reads ahead to the end of that range
from S3 — capped at 4 MiB per miss. And a node answering a join follows the
membership sync with the keys it holds, so the joiner starts knowing where the
cluster's working set lives.

Both issues specified something the transport cannot do, and both are
implemented as the rescope rather than as written.

#142 planned to fetch the bytes from the peer over ExecuteOperation. A gossip
datagram carries 5802 bytes of object at the default limit, so a 128 KiB read
is 21x over and fails as a 30-second timeout on the requesting host (#399).
What a peer's claim is actually evidence of is that the key is hot in this
cluster — the one thing a cold node cannot learn on its own — which is worth
acting on even when the bytes still come from S3.

#143 specified "max 256 entries per warmup message to bound UDP payload" and
cache.Warmup(keys) on receipt. Measured: 256 announcements with 52-character
keys seal to 65631 bytes against the 8192-byte default, 8x over, so every
warmup datagram would be refused at the socket and a joiner would warm nothing.
31 fit, and 31 is not a constant to hardcode either — it moves with key length,
which TestMarshalWarmupChunk_TheCountVariesWithKeyLength asserts. So the chunk
is grown one entry at a time and sealed to check, reusing syncChunkFits's shape.
MultiLevelCache.Warmup is one GetObject per key, so calling it would turn
cold-start into an egress burst; recording the announcements delivers what the
"100% hit rate before any S3 request" criterion was reaching for, and costs
nothing.

A claim is acted on only at the version this node is reading. A holder's range
describes the object it cached; against another version the object may have a
different length entirely. A mismatch, or no known version on either side,
warms nothing — the same fail-closed rule announceCached applies in the other
direction.

selfAnnounced is a second map beside announcements, and the separation is
load-bearing: announcements answers QueryKeyOwnership, which is asked because
this node's cache missed, so a self-claim there is a holder guaranteed not to
hold. The cache cannot be enumerated instead — types.Cache stores bytes with no
version beside them. The existing sweep now covers both maps; the second is the
half that would have leaked silently, since recentHoldings filters on read.

read_ahead.enabled: false suppresses the warm and the ownership query both,
rather than asking peers once per cache miss and discarding the answer.

Every guard is mutation-verified: each of thirteen deliberate breakages fails a
named test. Two of them initially survived and both were test defects —
TestJoinWarmsTheJoiner cleared the joiner's map after announcing, which races
asynchronous delivery and passed with recordSelfHolding deleted entirely, and a
redundant empty-holdings guard duplicated the send loop's own break.

Closes #142
Closes #143
@scttfrdmn
scttfrdmn merged commit cc3e868 into main Aug 9, 2026
35 checks passed
@scttfrdmn
scttfrdmn deleted the feat/peer-informed-cache-warming branch September 20, 2026 05:25
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-5: Cache warming on node join via MessageTypeCacheWarmup gossip A2-4: Cache-warming read: try peers before S3 on cache miss

1 participant