Repository navigation
Count requests dropped after -READONLY as ops - #593
Conversation
|
🤖 Automated first-pass review — a human maintainer's review is still required before merge. Thanks for this. The root cause matches what I see in One question:
Nitpicking: The (I'd file this as a comment, not a formal block.) |
08233b7 to
d440157
Compare
|
Replying to the automated first-pass review, point by point. The new head is d440157, rebased onto master after #584, #594 and #601. 1. The 2. Only one of the two drop sites is covered.
The cluster test now also asserts Mutant results. Each column is the result with both tests together.
Stability with the fix: the scripted test passed 15/15 and the cluster test 8/8 after the bound change. Nit: I also replaced the dead 🤖 Generated with Claude Code |
In cluster mode with --read-preference other than primary, a request a replica rejects with -READONLY and that is not retried ended in finalize_dropped_redirect(), which only bumps the error counter. For MOVED/ASK the caller also counts the op through update_redirect_stats(), but the READONLY branch returns without it and never reaches client::handle_response(). The request was still counted as processed, so a --requests run ended on time, but Totals Count, latency and bytes left out every -READONLY reply. Add finalize_dropped_readonly(), which does what finalize_dropped_redirect() does and also records the op the way client::handle_response() does for any other error reply. Use it for both READONLY drop paths. The regression test runs a write script marked --command-is-read under --read-preference=secondary, so replicas answer -READONLY, and checks that Totals Count equals the requested total. Fixes #592 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The #592 regression test only reached the first finalize_dropped_readonly() call (no live primary for the slot) and only checked Totals Count, so reverting the second call, recording the op under Gets, or zeroing its bytes or latency all passed. Add test_cluster_readonly_drop.py: a scripted RESP peer names itself the only primary and answers every SET with -READONLY. memtier re-routes the request to that live primary, and --max-retries=0 makes enqueue_retry() refuse, so every request is dropped through the second call. The test checks Sets and Totals Count, the histogram count, a latency floor from a 5 ms reply delay, the exact bytes the peer saw, and one --failed-keys-file row per -READONLY. In the cluster test, also check that the ops land under Evals, that Totals Bytes TX covers at least the smallest request per op, and that the dropped requests are logged. A replica can count more -READONLY replies than memtier reads, since a slot map refresh may retire the connection first and replay the request on the primary, so that check is a bound. Skip on Redis older than 6.2, which has no INFO ERRORSTATS. The request && guards in the READONLY branch were dead: shard_connection pops a request for every reply it hands to handle_response(). Assert it. Refs #592 Co-Authored-By: Claude Opus 5.5 <[email protected]>
d440157 to
55184e6
Compare
Problem
With
--cluster-modeand--read-preferenceother thanprimary, a request that a replica rejects with-READONLYand that isn't retried is never counted as an op. A--requestsrun exits 0, but TotalsCount(plus latency and bytes) comes out below the requested total. In OSS cluster this happens when a write script without a shebang (EVAL "...redis.call('set',...)") is marked--command-is-read: the replica runs it and the write inside fails with-READONLY. With-t 2 -c 2 --requests 500(2000 requests), master reportsCount649–694.Root cause
The
-READONLYbranch ofcluster_client::handle_response()ends a dropped request infinalize_dropped_redirect(), which only logs the failed key and callsm_stats.inc_error(). MOVED/ASK also callupdate_redirect_stats(..., completed=true), which counts the op (#582). The READONLY branch returns without that, soclient::handle_response()'supdate_*_op()never runs.shard_connection::process_response()still callsinc_reqs_processed(), so the run ends on time and the #557/#559/#575 processed/generated accounting is consistent. Only the op stats are short.Fix
Add
cluster_client::finalize_dropped_readonly(). It callsfinalize_dropped_redirect(), then records the op the same wayclient::handle_response()records any other error reply:update_{get,set,wait,arbitrary}_op()with latency fromm_first_sent_time. Both READONLY drop sites use it. MOVED/ASK are unchanged. The deadrequest &&guards in the READONLY branch are nowassert(request != NULL).shard_connection::process_response()dereferences the popped request before it callshandle_response().Tests
tests/test_read_preference_modes.py::test_read_preference_readonly_reply_countedruns the EVAL write script with--command-is-read --read-preference=secondaryon a cluster with replicas (-t 1 -c 2 -n 100). It asserts that the replicas answered-READONLY(errorstat_READONLY> 0) and that TotalsCount== 200. It uses--read-preference-fallback=primaryto stay clear of a separate stall, #602.Local RLTest (
--env oss-cluster --shards-count 3 --use-slaves), 5 runs each:CountManual repro,
-t 2 -c 2 --requests 500on a local 3+3 cluster: masterCount649 / 663 / 694, this branch 2000 / 2000 / 2000. Exit 0 in all runs.tests/test_cluster_readonly_drop.py::test_readonly_refused_retry_countedcovers the second drop site, where a live primary refuses the retry. The cluster test above only reaches the first site, where there is no live primary for the slot. A scripted RESP peer names itself the only primary and answers every SET with-READONLY. It runs--cluster-mode --ratio 1:0 --retry-on-error --max-retries 0 -n 20, soenqueue_retry()refuses. The test asserts:Count== 20 and the histogram count == 20--failed-keys-filerow per-READONLYThe cluster test also asserts
Evals.Count == Totals.Count, Totals Bytes TX ≥ Count × the smallest possible request, and 0 < failed-keys rows ≤ replicaerrorstat_READONLY. That check is a bound, because a slot-map refresh can retire a replica connection before memtier reads its reply, and the request is then replayed on the primary. The test skips on Redis < 6.2, which has noINFO ERRORSTATS.Mutation results with both tests:
rt_arbitraryrecorded viaupdate_get_opStability with the fix: the scripted test passed 15/15 and the cluster test 8/8.
Behavior change (release notes)
Read-preference runs (
--read-preference!=primary) that hit-READONLYnow count those requests as ops. Totals and per-commandCount, latency (histograms and percentiles), Bytes RX/TX, KB/sec and Ops/sec all change for such runs. Results from those runs are not comparable with 2.5.0–2.5.2. Runs that never see-READONLYare unaffected.Fixes #592
Affected versions
2.5.0 through 2.5.2 and master. The branch was introduced by ee757e7 (#456,
--read-preference); its first tag is 2.5.0. Confirmed by running on master e4d14e8, 2.5.2 and 2.5.0 (3/3 runs undercount on each). 2.5.1 is derived from history.🤖 Generated with Claude Code
Note
Medium Risk
Touches cluster error/response accounting on the -READONLY path; behavior change for read-preference workloads that see READONLY, but logic mirrors existing error op recording.
Overview
Fixes under-counted benchmark stats when cluster mode drops a request after a
-READONLYreply and does not retry it (e.g. read-preference to replicas, or--max-retries=0).Previously those paths only used
finalize_dropped_redirect(), which logs failed keys and bumps errors but does not record an op like MOVED/ASK’s redirect stats or normal error handling inclient::handle_response(). TotalsCount, latency, and byte metrics could fall short of--requestseven though the run completed.The PR adds
finalize_dropped_readonly(), which keeps the redirect-style failure logging and then calls the appropriateupdate_{get,set,wait,arbitrary}_op()with latency fromm_first_sent_time. Both-READONLYterminal drop sites inhandle_response()use it. The READONLY branch alsoassert(request != NULL)aftershard_connectionalways pops a request per reply.Tests: a scripted RESP peer (
test_cluster_readonly_drop.py) for refused primary retry, and a cluster integration test (test_read_preference_modes.py) for EVAL misclassified as read on replicas.Reviewed by Cursor Bugbot for commit 55184e6. Bugbot is set up for automated code reviews on this repo. Configure here.