Skip to content

A2-4: Cache-warming read: try peers before S3 on cache miss #142

Closed

Description

@scttfrdmn

Summary

On a FUSE cache miss, ask the cluster which peers hold the key and, on a match, read further from S3 —
not from the peer. A peer's claim is evidence that the key is hot in this cluster, which is the one thing a
cold node cannot learn on its own; the bytes still come from the object store.

Why this is a rescope, and it is not a smaller version of the same thing

The original plan above fetched the bytes from the peer via ExecuteOperation(&types.ReadOp{...}). That
transport cannot carry them. A remote operation response travels a gossip datagram, whose ceiling was
measured at 5802 bytes of object payload at the default max_gossip_packet of 8192 — so a single
128 KiB kernel read is 21× over and is refused at the socket. The responder logs and abandons; the
requester learns nothing until a 30-second timeout on a different host. #399 made that failure honest
(it now returns a size-naming error instead of a timeout), which is what made this rescope possible rather
than merely necessary.

So peer-fetch is not implemented, and a peer_fetch_timeout config knob would describe a code path that
does not exist. Serving object bytes between nodes needs a stream transport, which is its own piece of
work; #399 records that direction.

What was implemented

FileSystem.warmFromPeers, called from FileHandle.Read on the miss path only:

  • Query QueryKeyOwnership. No holders, or an error, warms nothing — the read has already succeeded.
  • Compare each holder's ETag against the version this node is reading, from the metadata cache. A version
    mismatch, or no known version on either side, warms nothing.
    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. Same fail-closed rule announceCached applies in the other
    direction.
  • Of the holders at the matching version, take the one reaching furthest, not the freshest: holders
    arrive freshest-first and the most recent claim can be the shortest. A Length of 0 means the whole
    object from Offset, per types.KeyAnnouncement.
  • Warm [end of this read, that holder's end), capped at maxPeerWarmBytes = 4 MiB per miss. That is
    the bound on wasted egress; it is deliberately not read_ahead.window_size, which is a prediction from
    this reader's own offsets rather than a claim by another node.
  • Queue it through the read-ahead prefetch queue, so it inherits EOF clamping, skipping what is cached,
    standing off in-flight reads, and flight-sharing. It does not update the read pattern — another
    node's reads must not decide whether this reader looks sequential.
  • Called from 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.
  • cache.read_ahead.enabled: false suppresses the warm and the query, rather than asking peers and
    discarding the answer — one gossip round trip per cache miss in exchange for nothing.

Acceptance Criteria

  • A miss on a key a peer holds past the read queues a warm of [read end, holder end) — offset and
    length both asserted, since starting at the read's own offset re-fetches what was just cached
  • The warmed range really is fetched from S3 and lands in this node's cache: asserted on observed
    GETs and on cache.Get answering for the whole warmed range, not on a queued request
  • A claim about a different version warms nothing; so does a read with no version known for the
    object
  • The furthest holder at the matching version wins, with a further-reaching wrong-version claim present
    to catch an implementation that checks the ETag after choosing
  • Length: 0 is read as the whole object rather than as an empty range
  • The warm is capped at 4 MiB against a peer claiming a 64 MiB object
  • No holder reaching past the read warms nothing — the ordinary case, and why warming cannot loop
  • A nil coordinator asks no peers and queues nothing; a nil read-ahead manager does not panic
  • Read-ahead disabled issues no ownership query
  • A failed ownership query does not affect the read's returned bytes
  • The read pattern's predictedNext and sequentialHits are unchanged by a warm
  • go test -race ./internal/fuse/... passes; all nine guards mutation-verified (each mutation breaks a
    named test)

Not implemented, deliberately: peer fetch, Cluster.PeerFetchTimeout, and the 500 ms peer timeout — see
above.

Activity

  1. added
    type: enhancement
    priority: high
    area: cache
    on Apr 7, 2026
  2. added
    effort: large
    on Aug 3, 2026
  3. scttfrdmn commented on Aug 9, 2026

    @scttfrdmn
    OwnerAuthor

    Proposing a rescope: metadata over gossip, bytes from S3. The title — "try peers before S3 on cache miss" — describes fetching data from a peer, and that cannot be built on the transport this project has. #399 has the measurement.

    Why the current scope is blocked

    The only node-to-node transport is UDP gossip, and a remote operation's response goes through sendMessage's MaxGossipPacket guard (gossip.go:1246). NodeResult.Data is a []byte, so JSON base64-encodes it, and the envelope and MAC add more on top. Binary-searched against the real seal path at the default 8192:

    • largest object payload that fits: 5802 bytes
    • one byte more: 8196 sealed, refused
    • an 8 KiB object: 11380 sealed (38.9% inflation, not base64's 33% — envelope and MAC account for the rest)
    • a 128 KiB object, the kernel's MaxRead: 175220 sealed, 21× over

    So a peer fetch fails for essentially every real read, and it fails in the worst available way: the responder logs "failed to send operation response" at Warn (coordinator.go:705) and abandons the request, and the requester reports "operation timed out waiting for remote response" 30 seconds later (coordinator.go:578). A size failure presented as a timeout, on a different host, at a level most deployments do not collect. Raising MaxGossipPacket is not the fix — past the ~1500-byte path MTU it trades a clean error for IP fragmentation, where one lost fragment silently discards the datagram.

    The rescope

    Keep gossip carrying only what fits in a datagram, which is metadata:

    1. Announce — a node that caches a key gossips a KeyAnnouncement.
    2. Query — on a cache miss, ask whether any peer holds this key at this ETag.
    3. Invalidate — a write announces the new version so holders evict.
    4. On a peer hit, GetObject from S3 rather than from the peer.

    Step 4 is the change, and it still pays: the value is knowing which keys are worth warming, not where the bytes come from. A peer holding a key at the current ETag is evidence that key is hot in this cluster — which is exactly what a cold node cannot know on its own, and exactly what #143's cache.Warmup (internal/cache/multilevel.go:301) consumes, one GetObject per key. S3 read bandwidth is not the scarce resource here; knowing what to read is.

    What it gives up is the LAN-versus-S3 latency win on a miss. That is real, and it is what direction 2 in #399 (a separate stream transport, with its own listener, authentication and backpressure) would buy back later, as its own piece of work rather than as a hidden prerequisite of this one.

    KeyAnnouncement needs no change either way

    pkg/types/types.go:60 already carries Key, NodeID, ETag, Size, CachedAt, Offset and Length — and its doc comment is explicit that the version is required rather than optional, precisely so a recipient can place the bytes relative to the object in the bucket. That reasoning holds under both scopes: under the rescope, the ETag is what lets a querier decide whether the peer's copy is the version it wants before spending a read.

    Happy to be overruled on the direction, but the metadata-only version is buildable on today's transport and the data-plane version is not, so filing the distinction rather than discovering it mid-implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: cacheeffort: largepriority: hightype: enhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions