Skip to content

A2-5: Cache warming on node join via MessageTypeCacheWarmup gossip #143

Closed

Description

@scttfrdmn

Summary

When a node joins, the node it joined answers the membership sync with a cache_warmup message listing the
keys it holds, freshest first. The joiner records them as ownership claims, so it starts knowing where
the cluster's working set lives instead of discovering it one cache miss at a time.

Two things in the plan above could not be implemented as written

1. cache.Warmup(keys) is the S3 traffic this feature exists to avoid. MultiLevelCache.Warmup
(multilevel.go:301) is one GetObject per key. Calling it on a warmup message would have a joining node
issue a whole-object GET for every key in it — turning cold-start cost into a burst of egress before the node
serves a single read, and gigabytes of it on a large-object workload. So the acceptance criterion "hit rate
for warmed keys is 100% before any S3 request" cannot pass against that function under any bound:
Warmup is the S3 request. What the criterion was reaching for is delivered by recording the
announcements into the ownership map, which costs nothing and is what the joiner needs — the bytes come from
S3 when a read actually wants them, as in #142.

2. "Max 256 entries" does not bound a UDP payload. Measured against the real seal path at the default
8192-byte limit, with 52-character keys shaped like a research bucket's: 256 announcements seal to 65631
bytes, 8× over.
Every warmup datagram would be refused at the socket and a joining node would warm nothing
at all, with the failure visible only in whatever the sender did with the error. 31 fit at that key
length — and 31 is not a constant to write down instead, because it moves with key length. A count cannot
bound a byte limit.

What was implemented

  • MessageTypeCacheWarmup and CacheWarmupMessage{Keys []types.KeyAnnouncement}, dispatched from
    handleIncomingMessage. Full announcements rather than bare keys: the ETag is what makes an entry
    actionable, per A2-2: Implement AnnounceKey and QueryKeyOwnership in coordinator #140.
  • handleJoinMessage sends the warmup after the membership sync, on the same goroutine — a node that
    knows which keys are hot but not who its peers are cannot act on either, and sequential sends keep the two
    off the same socket at once while the joiner's receive loop is still starting.
  • Coordinator.selfAnnounced, a second map beside announcements, recorded by AnnounceKey. It has to
    be separate: announcements answers QueryKeyOwnership, which is asked because this node's cache
    missed
    , so a self-claim there is a holder guaranteed not to hold. And it cannot be replaced by
    enumerating the cache — 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. Same mutex, same TTL, same bound, and the
    existing sweep covers it (the half that would otherwise leak silently, since recentHoldings filters
    expired entries on read).
  • Coordinator.recentHoldings(limit) — freshest first, expired excluded. Freshest-first is what makes a
    truncated message the useful half rather than an arbitrary one.
  • Bounded by measured sealed bytes, reusing the shape of syncChunkFits: the chunk is grown one entry at
    a time and the whole message sealed to check, so the envelope, the MAC and the base64 expansion are all
    measured rather than estimated. A join sends at most maxWarmupDatagrams = 4 (~124 keys at that density),
    which bounds the burst a joining node receives, and logs held_back when it truncates — a bound that
    silently truncates reads as "everything was sent".
  • The joiner records each entry through recordAnnouncement, so the self-claim refusal, per-node
    replacement, map bound, local timestamp and empty-ETag refusal all apply unchanged; batching is not a way
    around any of them. The envelope's sender overrides each entry's NodeID, so one member cannot populate
    a joiner's whole ownership map with fabricated holders.

Acceptance Criteria

  • A real join over loopback UDP warms the joiner: it learns holders it was never told about
    individually, with NodeID, ETag, Size and Length all asserted. The joiner is removed from the sender's
    memberlist before anything is announced, so the join is the only channel by which it could learn
    — the first version cleared the map after announcing and passed with recordSelfHolding deleted
    entirely, because delivery is asynchronous
  • Every chunk fits a sealed datagram, measured — 256 candidates packed, the sealed message compared
    to max_gossip_packet, and the payload unmarshaled to confirm it carries what was counted
  • The bound holds at a non-default max_gossip_packet (halved after construction)
  • The entries-per-datagram count varies with key length, which is why no constant would be right
  • An announcement too large to fit alone is reported (Warn — a misconfiguration, not a lost packet) and
    the rest are still attempted
  • A node holding nothing sends no warmup message
  • A burst of 2000 held keys produces at most maxWarmupDatagrams datagrams, and not zero
  • recentHoldings excludes peers' claims, orders freshest-first, excludes expired claims, and replaces
    an earlier version of the same key; the map is bounded; the sweep clears both maps
  • The envelope's sender wins over an entry's own NodeID; unusable entries and a malformed payload are
    discarded
  • go test -race ./internal/distributed/... passes, with and without -tags=distributed; every guard
    mutation-verified

Activity

  1. added
    type: enhancement
    priority: high
    area: distributed
    on Apr 7, 2026
  2. scttfrdmn commented on Jul 30, 2026

    @scttfrdmn
    OwnerAuthor

    Note from the v0.10.0 review — two blockers in the current design

    1. The gossip packet is far too small for the proposed announcement batch.
    MaxGossipPacket defaults to 1024 bytes (internal/distributed/cluster.go). A batch of 256
    KeyAnnouncements cannot fit — S3 keys alone can be up to 1024 bytes each. Either the default
    needs raising (with MTU fragmentation considered, since gossip is UDP), or announcements need
    chunking across multiple packets, or key digests should be sent instead of full keys.

    2. The acceptance criterion contradicts what Warmup does. The criterion "100% hit rate
    before any S3 request" cannot hold, because MultiLevelCache.Warmup
    (internal/cache/multilevel.go) populates the cache by fetching from the backend:

    data, err := c.backend.GetObject(ctx, key, 0, -1)

    One S3 GetObject per key. It also no-ops entirely when no backend is configured. So Warmup
    is the S3 traffic the criterion is trying to avoid.

    For warming to avoid S3 it would have to pull cached bytes from a peer over the network — which
    is a different feature than the one Warmup implements today, and a larger one. Worth deciding
    which is intended before starting: peer-to-peer cache transfer, or accept the S3 fetches and
    restate the criterion as "warm before first user request."

    Note also that NodeInfo's cache statistics fields are never populated (see #132), so a
    warming implementation has no data to make peer-selection decisions from yet.

  3. scttfrdmn commented on Aug 2, 2026

    @scttfrdmn
    OwnerAuthor

    Correction: the 256-entry bound overflows the default packet, and the acceptance criterion contradicts Warmup

    Re-verified against main. Two problems, one of which makes the headline acceptance criterion unachievable.

    1. MaxGossipPacket defaults to 1024 bytes (internal/distributed/cluster.go:158-159), and that is the size of the read buffer: gossip.go:272 does make([]byte, gp.config.MaxGossipPacket). A 256-entry CacheWarmupMessage cannot fit. Even at an implausibly small 20 bytes of JSON per announcement — a key, a node ID, a timestamp, and the surrounding {}/quotes/commas — 256 entries is >5 KB, and realistic S3 keys (genomics/sample-42/reads.bam) put it above 15 KB. The receive path does not reassemble, so an oversized datagram is silently truncated to 1024 bytes and then fails to unmarshal. The issue's own bullet says the 256 cap exists "to bound UDP payload"; it does not bound it to anything the receiver will accept.

    Options, in order of preference:

    • Bound by serialized bytes, not entry count: fill until the encoded message would exceed MaxGossipPacket minus envelope overhead, and send what fits. This is correct at any configured packet size and needs no new default.
    • Raise MaxGossipPacket to something above the practical MTU story (a 1024-byte default is small even for membership gossip) and keep a byte-based fill. Note that raising it past ~1472 means IP fragmentation on standard Ethernet, which is a reliability regression for the messages that already work.
    • Send warmup over TCP instead of gossip. Cache warmup is a one-shot bulk transfer on join, which is not what a fixed-size datagram protocol is for.

    2. "cache.Stats().HitRate for warmed keys is 100% before any S3 request" is contradicted by the implementation. MultiLevelCache.Warmup (internal/cache/multilevel.go:301-320) is:

    for _, key := range keys {
        data, err := backend.GetObject(ctx, key, 0, -1)
        ...
        c.Put(key, 0, data)
    }

    Warmup is one full-object S3 GET per key. So the criterion as written can never pass, and worse, the feature as specified does the opposite of what the issue claims: a joining node handed 256 keys issues 256 whole-object GETs at join time — a cold-start cost spike, not an avoided one, and on a large-object workload potentially gigabytes of egress before the node serves a single read.

    That does not sink the feature, but it changes what it is. Either:

    • Warm from peers, not S3. The point of knowing which peer holds a key is to fetch it from that peer. That makes warmup genuinely cheaper than a miss and is the same mechanism A2-4: Cache-warming read: try peers before S3 on cache miss #142 needs. It also means warmup must be a peer-fetch path, not a Warmup(keys) call.
    • Or make warmup metadata-only — populate the announcement map so subsequent misses route to a peer instead of S3, and drop the claim that the cache is pre-populated. Rewrite the criterion as "a read of a warmed key is served from a peer, asserted by S3 request count == 0".

    Either way the acceptance criterion should assert where the bytes came from (S3 request count, peer request count), not a hit-rate number. A hit rate of 100% is also what you get from a cache that was warmed by 256 S3 GETs, which is the outcome this issue exists to avoid.

    3. GetRecentAnnouncements does not exist yet — zero hits for it or KeyAnnouncement repo-wide. Correctly listed as a dependency on #140; noting it so nobody reads cluster.Get... as an existing call.

    Accurate as written: Warmup does exist on multilevel.go with the assumed signature; the empty-map-sends-nothing criterion is good; bounding the message is the right instinct even though the stated bound is wrong.

  4. added
    effort: large
    on Aug 3, 2026
  5. scttfrdmn commented on Aug 9, 2026

    @scttfrdmn
    OwnerAuthor

    "Max 256 entries per warmup message to bound UDP payload" does not bound it. 256 KeyAnnouncements do not fit a gossip datagram — not at the default limit, and not within a factor of seven of it.

    Measured with the real seal path (auth.go:199) and representative entries — a plausible S3 key, a hostname-shaped NodeID, a quoted ETag, a size, a timestamp, an offset and a length — against defaultMaxGossipPacket = 8192 (cluster.go:189):

    • 256 entries seal to 62191 bytes — 7.6× the limit
    • the largest count that fits: 32 entries (8003 bytes sealed)

    So a 256-entry warmup message is refused outright by the MaxGossipPacket guard at gossip.go:1246. Not truncated, not fragmented — sendMessage returns an error and nothing goes on the wire. A node joining a cluster would warm nothing at all, and the only trace would be whatever the caller does with that error.

    And 32 is not a constant to write down instead. It is a function of key length: these keys were ~50 characters, and a deployment with long prefixes gets fewer, while one with short keys gets more. Any fixed number is either wasteful or wrong depending on the bucket, which is the real lesson — a count cannot bound a byte limit.

    syncChunkFits is the mechanism to reuse

    gossip.go:1460 already solves exactly this shape for node sync, and solves it the right way:

    // The same message sendMessage would build, so the measurement includes the envelope, the MAC, and
    // the message ID rather than a guess at their combined size.

    It seals a candidate chunk and measures it, rather than estimating from a size ratio. Chunk the warmup announcements the same way: add entries until the sealed message would exceed MaxGossipPacket, then start a new one. That is correct at any key length, correct if MaxGossipPacket is reconfigured, and correct if a field is ever added to KeyAnnouncement — none of which a 256 survives.

    There is also a precedent for asserting the bound rather than trusting it: TestNewClusterManager_DefaultMaxGossipPacketHoldsAThreeNodeSync (cluster_test.go:143) exists because a limit of 1024 could not carry the smallest cluster needing a quorum, and its comment notes that a test comparing the constant to 8192 would have passed on the broken value. The equivalent here is a test that chunks a realistic announcement set and asserts every chunk seals under the limit.

    Related: #399 measures the same guard from the other side — a remote operation's response can carry only 5802 bytes of object before the sealed datagram is refused (38.9% inflation from base64 plus envelope plus MAC, not the ~33% base64 alone suggests). Same guard, same lesson: measure the sealed length, never estimate it.

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: distributedeffort: largepriority: hightype: enhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions