Repository navigation
Send CLUSTER SLOTS after MOVED even when the pipeline is full (#590) - #591
Conversation
|
🤖 Automated first-pass review — a human maintainer's review is still required before merge. Thanks for this, and for the detailed root-cause write-up in #590. I went through the
The (I'd file this as a comment, not a formal block.) |
574ed4c to
56abf93
Compare
|
Thanks for the review. Point by point: 1. Is 2.
3. Timing windows.
Also added, from the build review:
🤖 Generated with Claude Code |
With --retry-on-error, a node that gives up its slots answers MOVED. handle_moved() then asks for a CLUSTER SLOTS refresh on that connection, but fill_pipeline() only sends setup commands from inside its "pipeline below --pipeline" loop. Retries are resent by replay_request() beyond --pipeline, and retry_after_redirect() routes them by the stale slot map back to the same node. Once that connection holds --pipeline or more requests, every MOVED pops one request and the replay pushes it back, so the depth never drops, the refresh is never sent and later MOVED replies are ignored by handle_moved(). With the default --max-retries=-1 the run loops on MOVED forever. Check for pending setup commands before the pipeline-depth check, so the refresh goes out behind the requests already in flight. Nothing changes for a pipeline below --pipeline, and the deferral for a pinned --transaction rotation inside an open MULTI is kept. The test drives a scripted two-node peer: one node answers batches with -TRYAGAIN until its connection is deeper than --pipeline, then answers MOVED one reply at a time. Before this change the run never finished; now it completes. Fixes #590 Co-Authored-By: Claude Opus 5.5 <[email protected]>
fill_pipeline() only ran its loop while the run was not finished. With --test-time, a MOVED that arrives after the deadline still asks for a CLUSTER SLOTS refresh, but the loop never ran, so the refresh was never sent and the retries in flight kept bouncing on MOVED forever, just as with a full pipeline. Once finished, keep running the loop for setup commands while responses are pending, and stop it before any new request is created. Tests: - test_moved_after_test_time_refreshes_slots: MOVED starts after --test-time=1 is up. It hung on the previous commit. - test_pipeline_depth_stays_at_cap: a batching peer checks that each connection holds exactly --pipeline requests, which catches a "size() > pipeline" off-by-one in the moved depth check. - The overfull-connection test also runs a burst variant, where the node answers CLUSTER SLOTS and everything queued behind it in one write (needs #584). It now checks Totals Count == --requests and bounds the MOVED count. Refs #590 Co-Authored-By: Claude Opus 5.5 <[email protected]>
56abf93 to
a0cae16
Compare
Problem
In cluster mode with
--retry-on-error, a connection whose node has given up its slots can loop on-MOVEDforever. CLUSTER SLOTS is never sent on that connection, so every retry goes back to the node that just answered MOVED. With the default--max-retries=-1:--requestsrun never ends;--test-timerun whose MOVED arrives after the deadline never ends either.This was found during the build review of #584: about 2% of TLS runs of its slot-move test hung, and node
errorstat_MOVEDreached 29M. Details and gdb state are in #590.Root cause
handle_moved()callsset_cluster_slots()on the connection that got the MOVED.fill_pipeline()only sent setup commands from insidewhile (!finished() && m_pipeline->size() < m_config->pipeline).retry_after_redirect()routes the retry by the stale slot map, back to the same connection.replay_request()then resends it beyond--pipeline, up to the cluster in-flight budget of--pipeline× connections.--pipelineor more requests. Each MOVED pops one request and the replay pushes it back, so the depth never drops.--test-timeis up (finished()), but the retries in flight are still being answered with MOVED.handle_moved()because a refresh is already "pending".Fix
fill_pipeline()now checks for pending setup commands before it checks pipeline depth. Once the run is finished, the loop still runs for setup commands while responses are pending, and it stops before any new request is created:A requested CLUSTER SLOTS goes out behind the requests already in flight. Once its reply arrives, the retries route to the new owner.
--pipeline, nothing changes.--transactionrotation inside an open MULTI is unchanged.retry_after_redirect()still ignores the MOVED address, andreplay_request()still ignores the--pipelinecap. Neither is needed to break the loop, so this PR leaves both alone.--commandworkloads also need #599. Without a recordedm_key,retry_after_redirect()cannot hash an arbitrary request to its new owner, so even after the refresh those retries go back to the same shard until--max-retries.Tests
All tests are in
tests/test_cluster_redirect_stats.pyand use scripted peers on ephemeral ports, with no real cluster._SlotMoveClusterhas two nodes:-TRYAGAINuntil its connection is deeper than--pipeline.-MOVED, one reply at a time, waiting for each resend.test_moved_refreshes_slots_on_overfull_connection--requests=2000. Run twice: MOVED one at a time, and a burst variant where the node answers CLUSTER SLOTS plus everything queued behind it in one write (needs #584, now in master). Checks exit 0, TotalsCount == 2000, 0 < MOVED < 1000, and the depth >--pipelinepremise.test_moved_after_test_time_refreshes_slots--test-time=1. MOVED starts no sooner than 1.5 s, after the deadline (asserted). Checks exit 0 and 0 < MOVED < 1000.test_pipeline_depth_stays_at_cap--pipelinerequests (1 and 4), so an off-by-one in the moved depth check cannot pass.Results (local runs under RLTest):
--test-time>off-by-one mutant2 == 1,5 == 4)With the reviewer's own
peer_tt2.py(--test-time=1, nb=25 and nb=40), f7c3038 times out with 282k and 307k MOVED, and 56abf93 exits 0 with 9 and 8 MOVED. v2.5.2 and v2.4.0 hang on the overfull scenario too (checked with the first version of the test).Locally on a 3-shard OSS cluster with 56abf93, these test files all pass:
test_cluster_redirect_stats.py,test_cluster_transaction.py,test_retry_on_error.py,test_reconnections.py,tests_oss_simple_flow.pyandtest_mget_cluster.py. CI covers the full matrix.Fixes #590
Affected versions
2.4.0 through 2.5.2 (latest) and master.
--retry-on-error:retry_after_redirect()/replay_request()), first tagged in 2.4.0.🤖 Generated with Claude Code
Note
Medium Risk
Changes core cluster request pumping and setup ordering in fill_pipeline(); behavior during MOVED retries and run shutdown is sensitive, though guarded by new integration tests and existing MULTI deferral logic is preserved.
Overview
Fixes an infinite
-MOVEDloop in cluster mode with--retry-on-error: when a connection’s pipeline stays at or above--pipeline(retries replay beyond the cap) or the run has ended (--test-time) but retries are still in flight,CLUSTER SLOTSwas never sent becausefill_pipeline()only ran inside the “not finished and pipeline not full” guard.fill_pipeline()now keeps looping afterfinished()while setup is pending and responses are outstanding, and sends connection setup (including slot refresh) before enforcing pipeline depth—soCLUSTER SLOTScan go out behind in-flight work without issuing new workload requests once the run is done.Adds scripted two-node slot-move tests in
test_cluster_redirect_stats.py(overfull pipeline, post---test-timeMOVED, burst vs trickle replies) plustest_pipeline_depth_stays_at_capto lock normal pipeline sizing.Reviewed by Cursor Bugbot for commit a0cae16. Bugbot is set up for automated code reviews on this repo. Configure here.