Repository navigation
Enhance handling of loading replicas when replying LOADING ... - #3382
lamoboos223 wants to merge 7 commits into
Conversation
- Introduced logic to suppress loading replicas from selection until they are confirmed to be ready to serve traffic again. - Added methods to manage loading suppression and clear it when a command proves the server is no longer loading. - Implemented a mechanism to reissue commands away from loading replicas to ensure commands are routed to available servers. - Added unit tests to validate behavior when all replicas are loading and ensure proper rerouting to the primary server. This change improves the reliability of command execution in scenarios where replicas are temporarily unable to serve requests due to loading states.
mgravell
left a comment
There was a problem hiding this comment.
Concept looks good; will look in more depth after weekend - a few nits, but: heading in the right direction
…ng states, allowing certain commands to be processed while replicas are loading
…Exchange for setting the loading suppression state, ensuring that the latest observed value is respected
Thank you @mgravell for the valuable comments and code review! |
IServer messages are now marked CommandServerSpecific ("tied to a specific
endpoint, never retry elsewhere"), and the LOADING reissue skips any message
carrying that flag. So e.g. IServer.DatabaseSize() against a loading replica
surfaces the LOADING error instead of quietly returning another node's answer;
resumed SCAN cursors, which already carry the flag, are covered too.
This is deliberately not NoRedirect: a keyed command should still follow MOVED.
The flag's other reader, RetryPolicy, is not reachable from IServer.
mgravell
left a comment
There was a problem hiding this comment.
Thanks for the updates — the earlier nits are all sorted (the CEX is exactly what I was after). I've done a deeper pass:
-
Server-targeted commands could be answered by a different node.
IServermessages don't carryNoRedirect(andFixFlagsturns them intoPreferReplicawhen the target is a replica), soconn.GetServer(replica).DatabaseSize()against a loading replica was re-selected and returned the primary's (or the other replica's) count as the replica's. The underlying gap — nothing marked those messages as tied to their endpoint — predates this PR, so I've taken it on and pushed 32d3756 to your branch:IServermessages now carryCommandServerSpecific, and the LOADING reissue skips anything with that flag (which also covers resumed SCAN cursors). There's a regression test with it. -
The "accepted while loading" list is a lot shorter than Redis's. Going by the
LOADINGflag in upstreamsrc/commands/*.json, ECHO, SELECT, SUBSCRIBE/PSUBSCRIBE/SSUBSCRIBE/UNSUBSCRIBE, PUBLISH/SPUBLISH, CLIENT SETNAME/SETINFO, ROLE, CLUSTER NODES, TIME, READONLY, MULTI/EXEC/DISCARD/WATCH/UNWATCH, RESET, QUIT, LATENCY and SLOWLOG are all served while loading (PING isn't). Several of those reach a replica routinely — the handshake tracer is ECHO, the subscription connection SUBSCRIBEs, topology refresh is CLUSTER NODES — so suppression gets cleared early. The cost is bounded (one wasted round trip, then LOADING suppresses it again), but a hand-maintained list mirrored in two places will drift. I'd prefer to drop the early clear and let the 2s expiry do the work, which also takes the switch off the success path. If you'd rather keep it, it needs to key off something positive (a successful non-internal data command) rather than an exclusion list. Either way the toy's copy has the same gaps, so it currently rejects SUBSCRIBE/ECHO/SELECT while loading, which real Redis doesn't. -
DemandReplicawhen every replica is loading. The first call surfaces LOADING, but for the next 2s selection finds nothing and callers get "no connection available" even though the connections are healthy — less informative than today's LOADING error. Making that error say why servers were skipped is a broader, pre-existing issue and doesn't belong here, but I'd like a test that pins the behaviour down so it's a deliberate choice.
Smaller:
- There's no test for "one replica loading, the other healthy → reads go to the healthy one", which the description claims.
IsLoadingSuppressed()sits ahead of everything inIsSelectable, including primaries; a replica promoted while suppressed stays skipped for up to 2s. Fine, but worth a comment.- The toy now lets the handshake through while loading, which makes the comment in
MultiGroupTests/LoadingRerouteTests.cs("every reconnect fails during the handshake") stale. - The Windows CI failure (
ConfigTests.GetClients, net481) looks unrelated.
…hat certain commands can be answered while the server is still loading and adjusted the logic in ResultProcessor to prevent premature clearing of loading suppression based on successful replies to commands that are allowed during loading
This change improves the reliability of command execution in scenarios where replicas are temporarily unable to serve requests due to loading states.
closes #1913
Checklist