Skip to content

Back off CLUSTERDOWN topology refreshes per client - #877

Merged
fcostaoliveira merged 5 commits into
masterfrom
fix/clusterdown-refresh-backoff
Oct 26, 2026
Merged

fcostaoliveira merged 5 commits into
masterfrom
fix/clusterdown-refresh-backoff

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #834.

Since #799, a -CLUSTERDOWN reply makes each cluster_client refresh its topology with CLUSTER SLOTS, at most once per second. Each client keeps its own map, so -t 8 -c 50 sent up to 400 refreshes per second for the whole outage.

This takes option 1 from the issue, per-client exponential backoff:

  • While a client receives only CLUSTERDOWN replies, the gap between its refreshes doubles from 1 s to 8 s (refreshes at 0, 1, 3 and 7 s, then every 8 s). A sustained outage at -t 8 -c 50 drops from 400 refreshes per second to 50.
  • A successful reply to a keyed request resets the gap to 1 s. During CLUSTERDOWN Redis still answers keyless commands (PING, MULTI, WAIT), so their replies don't reset it, and neither do other errors (TRYAGAIN, LOADING, MASTERDOWN) or redirects. Without this, --transaction runs and keyless --command mixes would still poll once a second.
  • The 1 s floor is kept, so polling is never faster than on master.
  • The 8 s cap means a new map is seen at most 8 s after it's published, which is less than Redis's own failure detection (cluster-node-timeout, 15 s by default).

The decision lives in a small clusterdown_refresh_backoff struct in retry_backoff.h, next to the existing retry backoff. The README paragraph that stated the 400/s figure now states the schedule.

Tests

  • tests/unit/retry_backoff_test.cpp gets a case for the schedule, the cap, the reset and the 1 s floor. Against master's fixed 1 s logic it fails 13 checks: a 60 s outage gives 61 refreshes instead of 10.
  • The scripted-peer CLUSTERDOWN test in tests/test_cluster_unowned_slots.py gets a case that counts CLUSTER SLOTS during a sustained CLUSTERDOWN, for a plain workload, --transaction, and a SET+PING --command mix. Master's logic sends 14 against a bound of 8 to 10, and so does a reset on any successful reply for the two keyless-reply workloads. With the fix it passed 4/4 runs.

Results (Ubuntu 24.04 container, libevent 2.1.12):

  • make check passes, plain and ASan+UBSan.
  • test_cluster_unowned_slots.py passes 24/24, plain and sanitized.
  • With OSS_CLUSTER=1, 7 cluster test files pass 70/72. The 2 failures (test_transaction_connection_kills_do_not_hang, test_transaction_lost_multi_is_not_continued) fail the same way on unmodified master in this container.

Limitation (same as master): if only some slots are down and the workload mixes keys, successful replies keep resetting the gap, so each client still refreshes about once a second. Removing that needs option 2 from the issue: one shared refresh per thread.

🤖 Generated with Claude Code


Note

Medium Risk
Changes cluster-mode error handling and topology refresh timing during outages; behavior is well-tested but affects all CLUSTERDOWN paths in production benchmarks.

Overview
Replaces fixed 1 s CLUSTER SLOTS polling on -CLUSTERDOWN with per-client exponential backoff (1 → 8 s) so large -t/-c runs no longer hammer the cluster during sustained outages (#834).

Each cluster_client now uses a clusterdown_refresh_backoff helper in retry_backoff.h: refresh gaps double after each CLUSTERDOWN-triggered topology poll until they cap at 8 s, while a 1 s floor remains. A successful reply to a keyed workload resets the streak; keyless successes (PING, MULTI, monitor lines without keys, etc.) do not, via new request_carries_key() and arbitrary_command::has_keys(). README documents the revised refresh schedule.

Tests add unit coverage for the backoff schedule and integration cases that bound CLUSTER SLOTS calls under sustained CLUSTERDOWN, transactions, and monitor replay.

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

Since #799, a -CLUSTERDOWN reply refreshes the topology with CLUSTER SLOTS
at most once per second per client. Each client keeps its own map and there
was no backoff, so -t 8 -c 50 sent up to 400 refreshes per second for the
whole outage, adding control-plane load to the failure being measured.

While a client sees only CLUSTERDOWN replies, the gap between its refreshes
now doubles: 1 s, 2 s, 4 s, then 8 s. At the 8 s cap the same run sends at
most 50 refreshes per second, and a new map is still seen sooner than the
cluster's own failure detection (cluster-node-timeout, 15 s by default)
completes. Any other workload reply means the cluster serves requests again
and resets the gap to 1 s; the 1 s floor stays, so a flapping or partially
covered cluster is never polled faster than before. The refresh's own
CLUSTER SLOTS reply is a setup reply that never reaches handle_response, so
it cannot reset the backoff while the cluster is still down.

The decision lives in clusterdown_refresh_backoff in retry_backoff.h, next
to the --retry-on-error backoff, and retry_backoff_test checks the sequence,
the cap, saturation and the reset. A scripted-peer test counts CLUSTER
SLOTS during a sustained CLUSTERDOWN with two clients: 8 with the backoff,
14 with the old fixed interval.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Oct 25, 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 it and it looks solid to me. The arbitrary_request m_keys rewrite is equivalent to the old ternary chain. The 0/1/3/7/15 schedule matches gap_us(), and the saturation guard on streak covers the wrap. The unit case and the scripted-peer counts that fail on the old fixed interval are the kind of test I'd want here. You've already called out the partial-coverage limitation, so I won't bring it up again.

One question about the --monitor-input path in request_carries_key(). For the stats-only slot you treat the command as keyed when its spec has num_key_specs > 0 || movable_keys. That's a spec-level answer, not one based on the actual line's arguments. Isn't a line like EVAL "..." 0 (or EVALSHA/FCALL with zero keys) then counted as keyed? As far as I remember, Redis's getNodeByQuery() returns myself before it checks cluster health when the command ends up with no keys, so that line succeeds during CLUSTERDOWN. That would reset the backoff the same way PING used to. The --command path doesn't have this problem, because spec_key_positions is evaluated against the real argv there. It's probably rare in real monitor captures, so I'm fine with leaving it as a known gap. I may be wrong about the server side, so a second look from whoever owns the monitor replay code would help.

Nitpicking: the long comment block above CLUSTERDOWN_MSG_PREFIX in handle_response now repeats most of what's in retry_backoff.h. I think a pointer to the struct would be enough.

Neither of these blocks the change.

…est's timevals portably

TRYAGAIN, LOADING or MASTERDOWN during a failover do not show the cluster
serves requests again, but any non-CLUSTERDOWN reply reset the backoff,
so a mix of them put each client back on the 1 s cadence. Reset only on a
successful reply.

The unit test built timevals with braces and a suseconds_t cast, which
MSYS2 does not declare (tv_usec is long there): set the members instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Thanks. Agreed on the reset. Fixed in e04a7af: the backoff now resets only on a successful (non-error) workload reply. TRYAGAIN, LOADING, MASTERDOWN and other errors during a failover leave it where it is. I didn't make MOVED/ASK reset it either. A redirect means the slot map is wrong, but not that the cluster is serving again, and the request's eventual success after the redirect resets it anyway. The comment, the struct comment and the README now say "a successful reply".

The same commit fixes the MSYS2 failure on 40ac69f ('suseconds_t' was not declared in retry_backoff_test.cpp). The test now builds its timevals by assigning the members, since tv_usec is a long there and suseconds_t doesn't exist.

On the boolean checks: I've left CHECK_MS on due(). It's the file's one comparison macro, and a failure prints the value.

Sanitized make check passes, test_cluster_unowned_slots.py passes 24/24, and clang-format is clean.

During CLUSTERDOWN Redis still answers keyless commands: PING, MULTI and
WAIT succeed (checked on Redis 7.0.15), while a keyed command, also inside
MULTI at queue time, gets -CLUSTERDOWN and EXEC gets EXECABORT. With
--transaction, or a --command mix that includes a keyless command, every
such reply reset the backoff, so those workloads went back to one refresh
per second per client for the whole outage.

Reset only on a successful reply to a request that carries a key: rt_set,
rt_get, or rt_arbitrary whose command metadata lists key positions or
__key__ placeholders. request::m_keys cannot tell, since arbitrary_request
sets it to 1 for keyless commands. --transaction sends MULTI and EXEC as
keyless rt_arbitrary requests, so their replies no longer reset it.

The scripted-peer test now also runs a --transaction workload and a
SET+PING --command mix: both sent 14 CLUSTER SLOTS before this change,
against bounds of 10 and 8.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@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 dc4945c. Configure here.

Comment thread cluster_client.cpp Resolved
…ckoff

Random --monitor-input replay sends each line with the stats-only slot of
its command type as metadata. That slot has no argv, so it has no key
positions or __key__ placeholders, and request_carries_key() treated
every such reply as keyless. A successful keyed monitor line never reset
the backoff, so after a CLUSTERDOWN episode the workload stayed at the
8 s gap. Specific-line __monitor_lineN__ replay was not affected.

The stats-only slot does carry the command spec looked up for its type,
so also count it as keyed when that spec has key specs or movable keys.

arbitrary_command::has_keys() now holds the key-position or placeholder
test that the arbitrary_request constructor and request_carries_key()
both used, so the two cannot drift. The backoff comments in
retry_backoff.h now name a keyed request's success as the reset.

The scripted peer replays a CLUSTERDOWN SET mixed with SET foo, and with
PING as a control. With the keyed mix the client must stay near one
refresh per second: 8 CLUSTER SLOTS before this change against a lower
bound of 10.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

On the duplicated key check: done in eb42f5e. arbitrary_command::has_keys() (config_types.h) holds !spec_key_positions.empty() || keys_count > 0, and both the arbitrary_request constructor (same m_keys as before) and request_carries_key() use it. The same commit fixes the Bugbot finding that __monitor_line@__ replay never reset the backoff (thread replied and resolved), and updates the retry_backoff.h comments to "a successful reply to a keyed request". make check passes plain and sanitized, and test_cluster_unowned_slots.py + test_monitor_input.py pass 51/51.

@fcostaoliveira
fcostaoliveira merged commit f527dbf into master Oct 26, 2026
58 of 59 checks passed
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 mode: sustained CLUSTERDOWN makes every client poll CLUSTER SLOTS once a second with no backoff (400/s at -t 8 -c 50)

1 participant