Repository navigation
Record the key of --command requests in --failed-keys-file - #599
Conversation
|
🤖 Automated first-pass review — a human maintainer's review is still required before merge. Thanks for this. I went through the diff and the description, and left a few comments below. The CSV part looks right to me. Every
The core fix looks solid to me. I'd mostly like to hear back on (2) before this merges. |
|
This also fixes the Repro: local 3 primaries + 3 replicas, a write script that a replica rejects with
So with this branch, every rejected request is retried on the slot primary and completes. One leftover, small enough that I haven't filed it: without |
a900781 to
74df2aa
Compare
|
Fix for the semantics block (READONLY recovery changed by The reviewer was right. The previous head let The new commit changes the READONLY handler in
The MOVED and replay paths already returned early without Numbers, before → after (reviewer's fakes; previous head ae9d33b vs this head 74df2aa):
New tests in
Results over 5 runs each:
Other suites at 74df2aa:
The branch is rebased on origin/master 1ef64ef. The head is 74df2aa, on top of the rebased original commit ae9d33b. |
|
Following up on the automated first-pass review:
|
|
@fcostaoliveira, about the
|
|
472442a addresses the lifetime and test reviews of 74df2aa. Lifetime BLOCK: Semantics SHOULD-FIX: the Test-review items:
Every test now fails on a mutant:
At 472442a:
The PR body now says the |
send_arbitrary_command_end() never attached the __key__ value to the
arbitrary_request, so every failed --command request was logged to
--failed-keys-file as `ARBITRARY,"",...`. SET/GET/MGET attached their key
only under --retry-on-error, so without it they logged "" as well.
Keep the first key_type argument written for an arbitrary command (with
any {tag} and affixes, i.e. the key actually sent) and attach it when the
request is created. Capture keys for SET/GET/MGET/arbitrary whenever
--retry-on-error or --failed-keys-file is set (wants_request_key()).
request::m_key is also what cluster retry_after_redirect(), replay
re-routing and the -READONLY handler hash to find the slot owner, so:
- A --command retried after -MOVED now follows its key to the new owner
instead of going back to the same shard until --max-retries runs out.
- Recording a failure must not change recovery. The -READONLY handler
routes by m_key only under --retry-on-error, and never under
--transaction, where resending one command elsewhere would split the
MULTI/EXEC block (MOVED/ASK and replay hand-off already refuse this).
- A slot map that still names the rejecting connection as the primary is
stale (it was just demoted), so -READONLY refreshes instead of
re-queuing onto it. Built-in SET/GET with --retry-on-error looped there
before.
The first send of a {tag}ged --command is still routed by the bare key
(#614).
Tests:
- test_retry_on_error.py: the CSV key column for --command (plain,
{tag}ged, with --retry-on-error, two keys -> first key), built-in GET and
MGET without --retry-on-error.
- test_cluster_failed_keys.py, scripted A/B peers: -READONLY recovery after
a demotion with and without --failed-keys-file / --retry-on-error; a
write sent to a replica refreshes on every -READONLY without
--retry-on-error; -READONLY inside --transaction is never resent outside
MULTI; MOVED retries (SET, --command, {tag}ged key, with and without
--failed-keys-file) reach the key's owner within two redirects.
- test_cluster_readonly_drop.py: the single self-primary peer now takes
the first drop site (the map names the rejecting connection), so add a
two-node case for the refused-retry site: a write sent to replica A is
re-routed to primary B and refused by --max-retries=0. Both must count
the dropped op.
Document in --help that a multi-key command logs only its first key.
Fixes #596
Co-Authored-By: Claude Opus 5.5 <[email protected]>
472442a to
5a25881
Compare
|
Final head: 5a25881, rebased onto master c6006e7 (after #593) and squashed into one commit.
Suites at 5a25881, all passing:
🤖 Generated with Claude Code |
|
Replying to the updated automated review, point by point:
🤖 Generated with Claude Code |
Problem
--failed-keys-filelogs every failed--commandrequest with an empty key, for exampleARBITRARY,"","-MOVED 6971 ..."(seen in the output review of #583). That makes the file useless for finding which keys failed. Built-in SET/GET rows are also""unless--retry-on-erroris on.Root cause
request::m_keyis set only bysend_set_command(),send_get_command()andsend_mget_command(), insideif (m_config->retry_on_error), and byverify_request.send_arbitrary_command_end()never callsset_key_for_log(). The__key__value passes throughsend_arbitrary_command(arg, val, len), but nothing keeps it.m_keyhas a second reader: clusterretry_after_redirect(), replay re-routing and the-READONLYpath hash it to find the slot owner. For arbitrary requests the key was empty, so a-MOVEDretry went back to the same shard and kept getting MOVED until--max-retriesran out.Fix
send_arbitrary_command()keeps the firstkey_typevalue it writes, in a reused per-connectionstd::string. That value includes any{tag}prefix or suffix, so it is the key actually sent. The CSV logs it, and retries hash its{tag}. The first send of a{t}:__key__command is still routed by the bare__key__value; that is Cluster --command: text around __key__ (e.g. '{tag}-__key__', 'user:__key__') is ignored when choosing the shard (requests get -MOVED) #614, fixed by Route cluster --command requests by the full key argument #616.send_arbitrary_command_end()attaches it to the request. For multi-key commands only the first key is kept, the same as MGET.--retry-on-erroror--failed-keys-fileis set. The new private helperwants_request_key()holds that condition. When neither flag is set, nothing is copied.-READONLYhandler routes bym_keyonly under--retry-on-error. It also treats a slot primary equal to the rejecting connection as "no live primary", because the map is stale: it refreshes and drops instead of re-queuing onto the node that was just demoted. The MOVED and replay paths already require--retry-on-error.--transaction,-READONLYnever resends a command on another connection. Resending would split the MULTI/EXEC block, so the handler drops and refreshes, like MOVED/ASK and replay hand-off.--monitor-inputrequests in cluster mode. Their keys are literal arguments, so those requests still carry no key.Tests
This PR is one commit, 5a25881, rebased onto master c6006e7 (after #593). Every commit in the history is correct on its own: there is no intermediate commit where
--failed-keys-filechanges-READONLYrecovery.--helpfor--failed-keys-filenow says the logged key is the one sent, including any{tag}and affixes, and that a multi-key command logs only its first key.New test
test_retry_on_error.py:test_failed_keys_file_records_key(standalone; it skips in cluster mode like its neighbours). It seeds keys of the wrong type and checks that the CSV key column equals the keys sent in each of these cases:LPUSH __key__ v--retry-on-errorLPUSH {t}:__key__ vSINTER __key__ list-__key__, which must log its first key--retry-on-error--retry-on-error, which fails with-NOPERMthrough an ACL user that lacksmget""(e.g.['', '', ''] == ['fk:1', 'fk:2', 'fk:3'])At 5a25881, all passing:
test_retry_on_error.py: 9/9 on--env oss, and 9/9 on--env oss-cluster --shards-count 3 --use-slaves.test_cluster_redirect_stats.py: 9/9.test_read_preference_modes.py: 8/8 with replicas.test_read_preference_failover.py: 2/2 with replicas.test_cluster_transaction.py: 17/17 with replicas.Cluster routing was measured by hand on 3 primaries:
--cluster-mode --retry-on-error --max-retries=3 -t1 -c2 --pipeline=16 --test-time=6 --command="SET __key__ v" --failed-keys-file=...redis-cli --cluster reshardruns 2 s into each run.""The branch matches what built-in SET/GET already get.
memtier_benchmarkwithout--cluster-mode, pointed at a cluster node, shows the #583-style row change fromARBITRARY,"","-MOVED 10166 ..."toARBITRARY,"k:1","-MOVED 10166 ...".Cluster coverage is in
tests/test_cluster_failed_keys.py, which uses two scripted peers, A and B (see the PR comments for full numbers):-READONLYfrom a demoted A, with and without--failed-keys-fileand--retry-on-error: the test expects 1 write on A, 49 on B, and at least 2 CLUSTER SLOTS.--retry-on-error, with and without--failed-keys-file, for built-in SET,--commandand a{b}:__key__key. After the refresh A keeps half the slots, so a retry not routed by its key loops on A. The test checksCount,Connection Errorsand the redirect count from the JSON stats, and expects at most 2 redirects. A keyless retry gives 6.--command-is-read --read-preference=secondary. Without--retry-on-error, every-READONLYfrom B schedules a refresh (at least half of B's writes, 47 of 48 measured), with or without--failed-keys-file. With it, all 50 writes complete on A with no refresh. How many writes reach B before its connection is ready depends on timing, so the checks are relative and require at least one write on B.--transactionwith--pipeline=4: a-READONLYinside MULTI must never reach B outside MULTI. The test also requires at least one-READONLYsent after A served the new map, so it can't pass without exercising the handler.tests/test_cluster_readonly_drop.py(from #593) checks that a request dropped after-READONLYstill counts as an op. With this PR, its single self-primary peer takes the first drop site (the map names the rejecting connection), so the refused-retry site lost its coverage. The file now has two tests:test_readonly_stale_primary_drop_counted: the original single-peer case, which takes site 1.test_readonly_refused_retry_counted: two peers, with B the slot primary and A its replica. A write sent to A is re-routed to B, and--max-retries=0refuses the retry, so it takes site 2.Mutants each test kills (5a25881 passes
test_cluster_failed_keys.py+test_cluster_readonly_drop.py6/6 in 3/3 runs, and 9/9 with three suites running in parallel):!m_config->transactionremoved from the READONLY guard--transactionREADONLY: 1 SET reached B outside MULTIretry_on_error &&removed from the READONLY guardfinalize_dropped_redirecttest_readonly_refused_retry_counted:Count1, expected 20finalize_dropped_redirecttest_readonly_stale_primary_drop_counted:Ops/sec0wants_request_key()=failed_keys_fileonly{tag}retry_on_error""list-fk:NloggedAffected versions
2.4.0 through 2.5.2 and master.
--failed-keys-fileand--retry-on-error.Fixes #596
🤖 Generated with Claude Code