fix(balance): clear cached P2C ready index after a discovery removal#874
Open
ameyypawar wants to merge 2 commits into
Open
fix(balance): clear cached P2C ready index after a discovery removal#874ameyypawar wants to merge 2 commits into
ameyypawar wants to merge 2 commits into
Conversation
`Balance::poll_ready` caches the P2C-selected endpoint as a numeric `ready_index`. When a later `poll_ready` processes a `Change::Remove`, it calls `ReadyCache::evict`, which removes from the ready set with `swap_remove` and can move a different endpoint into the slot the cached index points at. The stale index was then revalidated by `check_ready_index` and dispatched to by `call`, silently bypassing the P2C choice during endpoint churn. Clear `ready_index` whenever a removal evicts a service, so the next `poll_ready` re-runs P2C over the current ready set. Also correct the `poll_ready` comment that wrongly claimed discovery updates cannot disturb the order of existing ready services.
…s#856) Drive a balancer to cache a P2C selection, remove that endpoint so eviction swap-moves a different endpoint into the cached slot, and assert the next request is routed by a fresh P2C selection rather than to the swapped-in endpoint. Uses a fed-on-demand Discover (deterministic ready-set order) and a zero RNG (deterministic P2C sampling).
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.
Summary
Fixes #856.
p2c::Balancecaches the P2C-selected endpoint as a numericready_index. When a subsequentpoll_readyprocesses aChange::Remove,update_pending_from_discovercallsReadyCache::evict, which removes from the ready set withswap_remove_full. That can move a different endpoint into the slot the cachedready_indexpoints at.poll_readythen revalidates the stale index withcheck_ready_index(which succeeds for whatever now occupies that slot) andcalldispatches the request there — silently bypassing the P2C choice during endpoint churn.This matches the warning already in
ready_cache's own docs:Fix
Clear
ready_indexwhenever a removal evicts a service, so the nextpoll_readyre-runs P2C over the current ready set:I also corrected the
poll_readycomment that claimed "These updates cannot disturb the order of existing ready services" — they can, viaswap_remove.Why this minimal fix is sufficient
The only operation that reorders the existing ready set between caching
ready_indexand reusing it isevict'sswap_remove_full:ReadyCache::poll_pendingonlyinserts into the readyIndexMap(appends new keys / updates existing in place — existing indices stay put).Change::Insertpushes to the pending set, never the ready set.check_ready_index's not-ready/error arms andcall_ready_indexalsoswap_remove, but only afterready_indexhas been.take()n within the samepoll_readyloop, each immediately followed by a fresh P2C selection — so no stale index survives across calls.The issue notes a more robust alternative (cache the key instead of the index); that's a larger change and isn't required to close this bug, but happy to go that route if you'd prefer it.
Tests
Not included in this commit. A deterministic regression test needs a dynamic
Discover(to emitChange::Removebetweenpoll_readycalls) plus a seededRng, which the currentp2ctests don't have scaffolding for. Glad to follow up with that test (building the small testDiscover+ mockRng) if you'd like it in this PR.