Skip to content

ring: honor the heartbeat timeout in shuffle-sharding subrings - #7976

Open
HudsonHumphries wants to merge 1 commit into
cortexproject:masterfrom
HudsonHumphries:ring-subring-heartbeat-timeout
Open

HudsonHumphries wants to merge 1 commit into
cortexproject:masterfrom
HudsonHumphries:ring-subring-heartbeat-timeout

Conversation

@HudsonHumphries

Copy link
Copy Markdown

What this PR does:

Health checks compare an instance's heartbeat with the KV store's last update time, r.KVClient.LastUpdateTime(r.key) (#5026). shuffleShard builds the subring without the parent ring's key, so a subring asks the KV store for a key it has no timestamp for. The DynamoDB client returns the zero time in that case, and IsHeartbeatHealthy then always returns true. So with the DynamoDB KV store, an instance with a stale heartbeat passes health checks in any tenant subring that contains it, while the full ring treats it as unhealthy after the heartbeat timeout. Consul, etcd, memberlist, and the in-memory client return time.Now() for any key, so only a DynamoDB primary is affected. The test MockClient also returns time.Now(), which is why the existing tests pass.

Copying key into the subring is not enough. A subring copies its instances from the parent, and the DynamoDB client's last update time moves forward at each poll. A subring that a caller keeps across the next poll would compare heartbeats from the previous poll with the new time, and could reject every instance. So this PR records the KV store's last update time in the subring when it copies the instances, both when shuffleShard builds it and when the subring cache refreshes it. A subring compares its heartbeats with that time, and the full ring keeps reading the KV store. Subrings now also share one existing timing window of the full ring. The DynamoDB client updates its last update time just before the ring applies a poll, and after each successful CAS from the same process, such as its own lifecycler's heartbeat, which the ring sees only at the next poll. A check in that window compares the previous heartbeats with the newer time. The full ring recovers when it applies the poll; a subring built or refreshed in the window keeps that pair until its next cache lookup. This PR does not change the window.

This affects every caller of shuffle sharding: distributor writes and queries to ingesters, ingester ownership, querier and store-gateway, compactor, ruler, and parquet converter. With Consul, etcd, and memberlist, a subring that a caller keeps now judges health as of the time it copied its instances. Before, its copied heartbeats aged against the wall clock, so the ruler's subrings, which it keeps while it lists rule groups, reported every instance as unhealthy when the listing took longer than the heartbeat timeout. Now an instance that times out while the caller keeps the subring stays in it until the caller's next lookup.

TestRing_ShuffleShard_ShouldHonorHeartbeatTimeout uses a KV client that, like the DynamoDB client, returns a last update time only for its own key. It checks that ShuffleShard and ShuffleShardWithLookback subrings exclude an instance with a stale heartbeat. Then the KV store polls again: that instance recovers and another one misses the poll. A subring that the caller kept still uses the heartbeats and the time it copied, and a subring from the cache uses the new ones. The test fails without this change, with only key copied into the subring, and without the cache refresh.

This change was prepared with AI assistance; I reviewed and tested every line.

Which issue(s) this PR fixes:
None filed.

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]
  • docs/configuration/v1-guarantees.md updated if this PR introduces experimental flags

@HudsonHumphries
HudsonHumphries requested a review from a team as a code owner November 27, 2026 23:00
Health checks compare heartbeats with the KV store's last update time
for the ring key. shuffleShard built subrings without the key, so with
the DynamoDB KV store, which returns the zero time for an unknown key,
every instance in a subring passed the heartbeat check.

Record the KV store's last update time in the subring when it copies
the instances, when it is built and at each cache refresh, and compare
the subring's heartbeats with that time.

Signed-off-by: Hudson Humphries <hudsohum@amazon.com>
@HudsonHumphries
HudsonHumphries force-pushed the ring-subring-heartbeat-timeout branch from e03b493 to bafcfe3 Compare November 27, 2026 23:01

This branch has not been deployed

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant