Repository navigation
Resend -MOVED retries to the node the reply names (#621) - #622
Conversation
|
🤖 Automated first-pass review — a human maintainer's review is still required before merge. Thanks for this. I went through the routing change and the two new tests. The diagnosis checks out: on A few small things, none blocking:
Both tests fail on the old code: 10/10 on master for the redirect-target test, 3/3 on a mutant without the (would file this as a comment, not a formal block) |
With --retry-on-error, retry_after_redirect() picks the target of a request redirected by -MOVED from the slot map. handle_moved() has only just asked for a CLUSTER SLOTS refresh, so until that reply lands the map still names the connection that sent -MOVED. The retry goes straight back there and is redirected again: every redirected request takes at least two -MOVED replies, and a refresh that is slow to land repeats the bounce for as long as it takes (unbounded with the default --max-retries=-1). With --max-retries=1 the request is dropped although its owner is known. Resend the retry to the primary connection the -MOVED reply names. Share the address lookup with retry_after_ask() (redirect_target_conn()), so a target that is still connecting or waiting on its reconnect timer holds the retry as it does for -ASK, and the accounting through enqueue_redirect_retry(). Clear m_asking on that path: a request that got -ASK and then -MOVED must not be resent with ASKING, or a node importing the slot would serve a key it does not own. Fall back to the slot map when there is no such connection (e.g. a node not in the map yet) and for reads under a --read-preference other than primary, which may belong on a replica. Tests (scripted A/B peers in test_cluster_failed_keys.py): - test_moved_retry_goes_to_redirect_target: A answers -MOVED to B and takes 0.3 s to send the new map, with --max-retries=1. Before: the retry goes back to A and is dropped (10/10 fail). After: 10/10 pass. - test_moved_after_ask_is_resent_without_asking: A answers -ASK to B, B answers -MOVED back to A; A must get no ASKING. Fails 3/3 without the m_asking reset, passes with it. Fixes #621 Co-Authored-By: Claude Opus 5.5 <[email protected]>
2714e71 to
8be8d5e
Compare
|
Thanks. Point by point, as of 8be8d5e (rebased on master after #600):
Test runs after the rebase:
🤖 Generated with Claude Code |
Problem
In cluster mode with
--retry-on-error, a request that gets-MOVEDis resent to the node that just redirected it, not to the node the reply names. It bounces at least once more. With a small--max-retriesit is dropped although its owner is known. See #621.Root cause
On
-MOVED,handle_response()does two things:handle_moved()only marks the connection to send CLUSTER SLOTS.retry_after_redirect()routes the retry by the slot map.Until the refresh reply lands, the map still names the connection that sent
-MOVED, so the retry goes back into that connection's retry queue. The<host>:<port>in the reply is never read.Fix
Rebased on master after #600.
The
-MOVEDbranch now calls a newretry_after_moved(). It resends the retry to the primary connection named by the reply.The address lookup moves out of Send ASKING before resending a request after -ASK #600's
retry_after_ask()intoredirect_target_conn(), and both functions use it. A target that is still connecting, or waiting on its reconnect timer, holds the retry just as it does for-ASK.The retry accounting reuses Send ASKING before resending a request after -ASK #600's
enqueue_redirect_retry().retry_after_moved()clearsm_asking. Without that, a request that got-ASKand then-MOVEDwould be resent with ASKING, and a node importing the slot would serve a key it does not own.It falls back to
retry_after_redirect()(slot map routing, unchanged) in two cases:--read-preferenceother than primary, since it may belong on a replica.Under
rp_primarya read goes to the-MOVEDtarget like a write, without waiting for the target's CLUSTER SLOTS ladder. The address is authoritative, and Route --read-preference=primary reads to a still-connecting primary (fixes cluster seed stall) #612 already routes primary reads that way.-READONLY, the replay hand-off and--transaction(which never retries a redirect) are unchanged.Tests
Two new tests in
tests/test_cluster_failed_keys.py, both using its scripted A/B peers:test_moved_retry_goes_to_redirect_target(modemoved-slow):-MOVEDto B. A takes 0.3 s to send the new map.--retry-on-error --max-retries=1 --failed-keys-file, for SET and--command.Count== 20, and one redirect per SET sent to A.test_moved_after_ask_is_resent_without_asking(modeask-moved):-ASKto B. B answers the ASKING+SET with-MOVEDback to A.m_askingreset fails 3/3; this branch passes 3/3.After the rebase:
test_cluster_failed_keys.py: 6/6.test_cluster_ask_asking.py: 2/2.test_cluster_redirect_stats.py: 9/9.Countequals the servers' SET+GETcmdstatcalls in all three:--ratio 1:0 --test-time 5: 623642 = 623642.--ratio 1:1 --test-time 5 --retry-on-error: 666934 = 666934.-n 2000 --retry-on-error: 20000 = 20000.Real cluster (before the rebase; 3 primaries, Redis 8.6.0):
-t 2 -c 5 --test-time 10 --key-maximum 20000 --ratio 1:1 --retry-on-error, withredis-cli --cluster reshardmoving 500 slots from one primary to another and back. Servererrorstat_MOVEDagainst memtier'sretried_ops:Notes
get_address(). A seed given by hostname won't match a-MOVEDthat names an IP, and neither will the empty-host:portform. Both fall back to the slot map as before, the same as Send ASKING before resending a request after -ASK #600's-ASKpath.Fixes #621
Affected versions
2.4.0 through 2.5.2 and master. The routing dates from 08cfc24 (#381,
--retry-on-error), first tag 2.4.0. I confirmed it by running the test on master 4d97c8b and on 2.5.2; the versions in between are derived from history.The much larger MOVED storms reported in the #616/#594 reviews (171k–212k MOVED, 0 SETs on the new owner) were
--commandrequests without a key on bases before 4d97c8b. #599 (4d97c8b) already fixed those; details are in #621.🤖 Generated with Claude Code