Repository navigation
feat(cluster): peers learn which keys are cached elsewhere (#140) - #402
Merged
Merged
Conversation
AnnounceKey and QueryKeyOwnership were stubs returning ErrNotSupported. Both are real: a node broadcasts a cache_announce gossip message naming the key, its ETag, its size and the byte range it holds; receivers record the claim against the sending peer, expire it after cluster.announcement_ttl (default five minutes), and answer a local lookup freshest-first. Metadata only. No object bytes cross gossip, because a datagram cannot carry a 128 KiB read (#399), so what this buys is knowing *which* keys are worth warming — the bytes still come from S3. Three departures from the issue's written spec, each for a reason the code records: - A node does not record its own announcements. QueryKeyOwnership is called because a read missed this node's own cache, so a self-entry is a holder guaranteed not to hold, returned in place of a peer that might. - Expiry uses a locally stamped recordedAt, never the wire's CachedAt, whose own contract forbids comparison against a local deadline. A peer whose clock runs an hour behind would otherwise have every announcement expire on arrival, and one running fast would sort itself to the front of every key in the cluster. CachedAt is still carried, for a recipient comparing two holders of one ETag. - No applied-once ledger, unlike handleCacheInvalidate. An invalidation is an action, so applying a retransmission of an older one throws away bytes legitimately re-cached since. An announcement is a fact about a (key, node) pair, and recordAnnouncement replaces that node's entry rather than appending — a retransmission overwrites an identical value. An announcement missing its ETag is refused rather than sent, with the field named. That is the integrity boundary: an invalidation with no version is safe, since "evict whatever you hold" cannot serve wrong bytes, while a peer that fetches bytes it cannot place against an object version hands them to a reading process as file content. Announcing with gossip not running returns ErrNotSupported rather than nil, which is the defect #284 deleted a CacheReplicator for. The receiver credits the envelope's sender over the payload's NodeID, so a member cannot send the cluster to fetch bytes a third node never cached. announced_keys joins the coordinator's statistics, counting keys retained rather than queryable, so the gap between it and a query is how far behind the expiry sweep is running. TestCoordinatorWrapper_UnimplementedMethodsRefuse asserted both stubs refuse and is rewritten as TestCoordinatorWrapper_CacheCoordinationOnAnUnstartedCluster, where the two now answer differently: announcing with no socket is a lie if it succeeds, while querying a cluster that has heard from nobody honestly holds nothing, which is the documented empty answer rather than a failure. Twenty mutations verified against the new tests, each killed: a removed dispatch arm, local self-recording, append-instead-of-replace, dropped field validation, an admitted self-claim, ordering by CachedAt, a missing read-side expiry filter, an unbounded map, eviction skipping its expired pass, a nil slice for a miss, an inert sweep, absent stats, an accepted empty ETag, a nil answer with gossip down, a removed envelope-sender override, a recorded malformed payload, and both wrapper nil guards. internal/distributed coverage 81.8%.
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 #140.
AnnounceKeyandQueryKeyOwnershipwere stubs returningErrNotSupported. Both are real now: a node broadcasts acache_announcegossip message naming the key, its ETag, its size and the byte range it holds; receivers record the claim against the sending peer, expire it aftercluster.announcement_ttl(default five minutes), and answer a local lookup with the holders freshest-first.Metadata only. No object bytes cross gossip, because a datagram cannot carry a 128 KiB read (#399). What this buys is knowing which keys are worth warming — a peer holding a key at the current ETag is evidence it is hot in this cluster, which a cold node cannot learn on its own. The bytes still come from S3, which is #142.
Three departures from the issue's written spec
Each is recorded in the code, not just here.
A node does not record its own announcements. The spec says to. But
QueryKeyOwnershipis called because a read missed this node's own cache, so a self-entry is a holder guaranteed not to hold, returned in place of a peer that might. The local cache is already the authority on what this node has.Expiry uses a locally stamped
recordedAt, never the wire'sCachedAt. That field's own documentation forbids comparing it against a local deadline: clocks across nodes are not synchronized, so a peer running an hour behind would have every announcement expire on arrival, and one running fast would sort itself to the front of every key in the cluster.CachedAtis still carried, for a recipient comparing two holders of one ETag — advisory for that, unusable for expiry.No applied-once ledger, unlike
handleCacheInvalidate, which was otherwise the precedent followed closely. An invalidation is an action, so applying a retransmission of an older one throws away bytes legitimately re-cached since. An announcement is a fact about a (key, node) pair, andrecordAnnouncementreplaces that node's entry rather than appending — a retransmission overwrites an identical value.The integrity boundary
An announcement missing its ETag is refused rather than sent, with the field named in the error. An invalidation with no version is still safe, since "evict whatever you hold" cannot serve wrong bytes; an announcement with no version is not, because a peer that fetches bytes it cannot place against an object version hands them to a reading process as file content.
Announcing with gossip not running returns
ErrNotSupportedrather than nil — a caller told nil believes the cluster knows something it was never sent, which is exactly the defect #284 deleted aCacheReplicatorfor. And the receiver credits the envelope's sender over the payload'sNodeID: both are authenticated by the same MAC, so this is not a defense against an outsider but against a member announcing that some third node holds a key, which would send peers to fetch bytes that node never cached and has no way to correct.Also
cluster.announcement_ttlondistributed.ClusterConfig, with nointernal/configkey — tuning for a subsystem whose defaults are measured, like the gossip triple beside it. Its default is applied at the point of use rather than inapplyConfigDefaults, because a zero TTL there is not a slower cluster but a silently inert one.announced_keysin the coordinator's statistics, counting keys retained rather than queryable, so the gap between it and a query is how far behind the expiry sweep is running.TestCoordinatorWrapper_UnimplementedMethodsRefuseasserted both stubs refuse, and is rewritten asTestCoordinatorWrapper_CacheCoordinationOnAnUnstartedCluster— where the two now answer differently, which is the point: announcing with no socket open is a lie if it succeeds, while querying a cluster that has heard from nobody honestly holds nothing, and that is the documented empty answer rather than a failure.Verification
go build/gofmt/go vetclean;go test -race -count=1 ./...green;go test -race -tags=distributed ./internal/distributed/...green.golangci-lint run --new-from-merge-base=origin/main: 0 issues.internal/distributedcoverage 81.8%.startGossipPairharness rather than a second one.CachedAt, a missing read-side expiry filter, an unbounded map, eviction skipping its expired pass, a nil slice for a miss, an inert sweep, absent stats, an accepted empty ETag, a nil answer with gossip down, a removed envelope-sender override, a recorded malformed payload, an error that drops the key it names, and both wrapper nil guards.