Skip to content

Count retried cluster redirects once in completion statistics - #582

Merged
fcostaoliveira merged 2 commits into
masterfrom
fix/redirect-retry-stats-579
Oct 13, 2026
Merged

fcostaoliveira merged 2 commits into
masterfrom
fix/redirect-retry-stats-579

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

With --cluster-mode --retry-on-error, a request receiving MOVED or ASK contributed an operation, bytes, and a latency sample both for the redirect and for its final reply. A deterministic 12-request run with two redirects per request reported 36 operations and histogram samples.

Record every MOVED/ASK event, but count completion statistics only when the redirect is terminal or the retried request receives its final reply. Disabled retries, exhausted retries, and transaction redirects retain terminal accounting. Terminal redirect latency spans the first send through the final outcome, including retries and backoff, consistent with successful requests. READONLY handling is unchanged.

Validation:

  • The original regression matrix fails 16 of 28 cases on master. The final 36-case matrix passes under ASan, checking operation counts, histogram sample counts, byte totals, redirect rates, and end-to-end terminal latency.
  • Eight additional MOVED/ASK × built-in/arbitrary GET/SET cases reproduce terminal latency below 1 ms despite 50 ms retry backoff before the timestamp correction; all pass afterward.
  • General failover regression: a real three-primary/three-replica Redis run completes exactly 1,000,000 requested operations. That run emits no redirects; reproduction is established by the deterministic matrix.
  • All 11 real-Redis TLS retry and HDR regression tests pass. The scripted redirect fixture itself uses plaintext RESP.
  • Formatting and the staged C++ format hook pass.

Fixes #579.


Note

Medium Risk
Changes benchmark accounting and latency semantics for cluster redirects under retry, which can shift reported ops/sec and histograms for existing cluster workloads.

Overview
Fixes double-counting of cluster MOVED/ASK responses when --retry-on-error is enabled: each redirect used to add an operation, byte totals, and a latency sample in addition to the final successful reply.

Cluster client now routes redirect accounting through update_redirect_stats, which always increments MOVED/ASK counters but only records completion stats (Count, bytes, histograms) when the redirect is terminal (completed)—i.e. retry disabled, retry refused/exhausted, --transaction drop, or no retry queued. Terminal latency uses m_first_sent_time through the final outcome (including backoff). handle_moved is limited to topology refresh; handle_ask is removed in favor of the shared stats path.

run_stats gains a completed flag on all moved/ask updaters and drops the separate update_moved_op / update_ask_op helpers. A deterministic integration test (test_cluster_redirect_stats.py) validates counts, histogram samples, bytes, and redirect rates; failover retry test expects an exact op total. ASan/TSan/UBSan workflows include the new test.

Reviewed by Cursor Bugbot for commit d7aa2c6. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

🤖 Automated first-pass review — a human maintainer's review is still required before merge.

Thanks for this. I went through the stats changes and the new fixture. The core change looks right to me: every MOVED/ASK still increments the redirect counter, but bytes, latency and Count only land once, either on the terminal redirect or on the final reply via client::handle_response with m_first_sent_time. A refused retry still gets both the op and the inc_error() from finalize_dropped_redirect, same as before. The scripted RESP peer is a nice way to make this deterministic. It checks histogram sample counts and byte totals, not only Count, and the description says the matrix fails on master. That's the bar PR#364 set. Tightening test_cluster_failover_retry.py from >= to == is a good catch too.

A few comments:

  • I wonder about the "Totals currently omits arbitrary-command redirect rates" note in the test. run_stats.cpp:1214 still builds Totals MOVED/sec/ASK/sec from m_set_cmd + m_get_cmd only. This PR now increments m_total_cmd.m_moved/m_ask for all three request types, so I think Totals could just read those counters and close the gap. Fine as a follow-up, but the test is currently locking in the omission rather than flagging it.
  • update_redirect_stats() now runs after retry_after_redirect(), so it depends on enqueue_retry() never replaying or freeing the request synchronously. The comment says so, and the deferral only landed in c9a65a0. I may be wrong, but that coupling seems easy to break later. Did you consider an assert, or a note at enqueue_retry() itself, so whoever changes that side sees the dependency?
  • The JSON schema doesn't change, but Count/Ops/sec and per-second Count/bytes will drop for any --cluster-mode --retry-on-error run that sees redirects. Set and Get MOVED/sec/ASK/sec were previously the per-command rates, and they now also exclude retried redirects from the denominator. Since it's a correctness fix I don't think a compat switch is warranted, but it probably deserves a line in the release notes so people comparing against older runs aren't surprised.
  • Nitpicking: the moved and ask branches in update_redirect_stats() are the same dispatch twice, apart from the stats method called. Not worth changing unless you're touching it anyway.

The fix itself looks solid. I'd mainly like the Totals rate question answered, either here or as a tracked follow-up.

@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Checked these points against the current code:

  • Reported Totals MOVED/ASK rates are unchanged: run_stats::summarize() calculates them directly from SET + GET counters, so GET was already included. Normalizing m_total_cmd.m_moved does not change those output rates. Arbitrary-command redirects remain absent from that aggregate because of the existing summarization logic; their per-command rates are covered by the regression test.
  • Successful retries already use request->m_first_sent_time in client::handle_response(), so their final histogram sample includes redirects and backoff. This fix removes the intermediate samples. Terminal redirects with retry disabled/refused still use the existing m_sent_time behavior.
  • Refused retries intentionally retain an error count plus one completed operation/sample. Accepted retries retain redirect counters without completion accounting.
  • enqueue_retry() only queues and arms a deferred timer; the request remains valid through the stats update. The two old one_sec_cmd_stats redirect helpers are now unused. The suggested lifetime comment and helper removal are optional cleanup, left for the subsequent review session so this correctness patch retains the exact commit approved by all seven independent reviewers.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3a32c8c. Configure here.

Comment thread cluster_client.cpp Resolved
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Adversarial review summary. 7 independent reviewers looked at correctness, output compatibility, test discrimination, build and sanitizers, lifetime, interactions with #574/#575/#576/#583/#578, and maintainer standards. All 7 gave MERGE.

Non-blocking follow-ups (test gaps found by mutation testing):

  1. The Time-Serie checks in test_cluster_redirect_stats.py cover the per-command entries but not Totals. Deleting m_total_cmd.update_op(...) in update_moved_set_op survives, and the Totals series then reports 0 ops.
  2. Latency values are only checked on the exhausted path. Forcing latency = 0 in update_ask_get_op on the completed path survives. A fixed delay on the terminal reply, asserted against the histogram minimum, would catch it.
  3. If a regression drives Ops/sec to 0, entry[redirect + "/sec"] / entry["Ops/sec"] raises ZeroDivisionError and the remaining cases are skipped.
  4. The tightened assertEqual in test_cluster_failover_retry.py never sees a redirect, so it passes on master too. A graceful CLUSTER FAILOVER variant would cover Cluster --retry-on-error --requests: requests retried after MOVED/ASK are counted twice in ops #579 end to end on a real cluster.

Pre-existing, out of scope:

  • Totals MOVED/sec and ASK/sec leave out arbitrary commands (run_stats.cpp:1232).
  • No ASKING is sent before retrying after ASK.
  • The READONLY drop path never counts the op.

🤖 Generated with Claude Code

@fcostaoliveira
fcostaoliveira merged commit b69568a into master Oct 13, 2026
143 of 145 checks passed
fcostaoliveira added a commit that referenced this pull request Oct 14, 2026


Mutation testing during the review of #582 and #583 found faults that the
merged tests did not catch. This change only touches tests.

test_cluster_redirect_stats.py (#582, #579):
- Check the Totals Time-Serie Count, Bytes RX and Bytes TX as well as the
  per-command series. Dropping m_total_cmd.update_op() in
  update_moved_set_op() used to pass.
- Delay every terminal reply from the scripted peer by 20 ms, and check
  Min/Average/p50 latency and each per-second Min Latency against that
  delay in every mode. A zero latency on a completed redirect (for example
  an ASK reply with retries disabled) used to pass the default-backoff
  cases.
- Report Ops/sec == 0 as an assertion instead of letting the redirect-rate
  division raise ZeroDivisionError and skip the remaining cases.
- Check the final errors/retries/retried_ops progress counters on the
  success, refused and transaction paths.

cluster_transaction_test.cpp (#583, #580):
- Add a two-shard test with a populated slot map. After txn_release_pin(),
  the next send must re-pin to the owner of the retained lookahead key.
  Generating the key after it used to pass.
- After releasing a pin whose round key was already consumed, check that the
  round key and the pin are both cleared. The existing "pin and old round
  key released" check runs before any round key is set, so it cannot fail.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 14, 2026


Mutation testing during the review of #582 and #583 found faults that the
merged tests did not catch. This change only touches tests.

test_cluster_redirect_stats.py (#582, #579):
- Check the Totals Time-Serie Count, Bytes RX and Bytes TX as well as the
  per-command series. Dropping m_total_cmd.update_op() in
  update_moved_set_op() used to pass.
- Delay every terminal reply from the scripted peer by 20 ms, and check
  Min/Average/p50 latency and each per-second Min Latency against that
  delay in every mode. A zero latency on a completed redirect (for example
  an ASK reply with retries disabled) used to pass the default-backoff
  cases.
- Run the success mode with a 50 ms backoff too, and require each sample
  to cover both backoffs. Timing the reply from the last send instead of
  the first (m_sent_time in client::handle_response) used to pass.
- Check the final errors/retries/retried_ops progress counters on the
  success, refused and transaction paths. The stderr progress line is the
  only output that carries them.

cluster_transaction_test.cpp (#583, #580):
- Add a two-shard test with a populated slot map. After txn_release_pin(),
  the next send must re-pin to the owner of the retained lookahead key.
  Generating the key after it used to pass.
- After releasing a pin whose round key was already consumed, check that the
  round key and the pin are both cleared. The existing "pin and old round
  key released" check runs before any round key is set, so it cannot fail.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 14, 2026


Mutation testing during the review of #582 and #583 found faults that the
merged tests did not catch. This change only touches tests.

test_cluster_redirect_stats.py (#582, #579):
- Check the Totals Time-Serie Count, Bytes RX and Bytes TX as well as the
  per-command series. Dropping m_total_cmd.update_op() in
  update_moved_set_op() used to pass.
- Delay every terminal reply from the scripted peer by 20 ms, and check
  Min/Average/p50 latency and each per-second Min Latency against that
  delay in every mode. A zero latency on a completed redirect (for example
  an ASK reply with retries disabled) used to pass the default-backoff
  cases.
- Run the success mode with a 50 ms backoff too, and require each sample
  to cover both backoffs. Timing the reply from the last send instead of
  the first (m_sent_time in client::handle_response) used to pass.
- Check the final errors/retries/retried_ops progress counters on the
  success, refused and transaction paths. The stderr progress line is the
  only output that carries them.

cluster_transaction_test.cpp (#583, #580):
- Add a two-shard test with a populated slot map. After txn_release_pin(),
  the next send must re-pin to the owner of the retained lookahead key.
  Generating the key after it used to pass.
- After releasing a pin whose round key was already consumed, check that the
  round key and the pin are both cleared. The existing "pin and old round
  key released" check runs before any round key is set, so it cannot fail.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 14, 2026


Mutation testing during the review of #582 and #583 found faults that the
merged tests did not catch. This change only touches tests.

test_cluster_redirect_stats.py (#582, #579):
- Check the Totals Time-Serie Count, Bytes RX and Bytes TX as well as the
  per-command series. Dropping m_total_cmd.update_op() in
  update_moved_set_op() used to pass.
- Delay every terminal reply from the scripted peer by 20 ms, and check
  Min/Average/p50 latency and each per-second Min Latency against that
  delay in every mode. A zero latency on a completed redirect (for example
  an ASK reply with retries disabled) used to pass the default-backoff
  cases.
- Run the success mode with a 50 ms backoff too, and require each sample
  to cover both backoffs. Timing the reply from the last send instead of
  the first (m_sent_time in client::handle_response) used to pass.
- Check the final errors/retries/retried_ops progress counters on the
  success, refused and transaction paths. The stderr progress line is the
  only output that carries them.

cluster_transaction_test.cpp (#583, #580):
- Add a two-shard test with a populated slot map. After txn_release_pin(),
  the next send must re-pin to the owner of the retained lookahead key.
  Generating the key after it used to pass.
- After releasing a pin whose round key was already consumed, check that the
  round key and the pin are both cleared. The existing "pin and old round
  key released" check runs before any round key is set, so it cannot fail.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cluster --retry-on-error --requests: requests retried after MOVED/ASK are counted twice in ops

1 participant