Skip to content

Name the cause when strict secondary has no replica to read from - #901

Merged
fcostaoliveira merged 2 commits into
masterfrom
fix/strict-secondary-no-replicas
Oct 27, 2026
Merged

fcostaoliveira merged 2 commits into
masterfrom
fix/strict-secondary-no-replicas

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #888.

In cluster mode with strict --read-preference=secondary, if CLUSTER SLOTS lists no replicas, no read can be routed. For --command reads (keyless, or keyed like GET __key__), the run ended at once with 0 ops and only the generic "client(s) stopped before reaching their stop condition". The built-in GET-only workload (--ratio=0:1) already went through a stall branch in cluster_client::hold_pipeline() that warns "all replicas unreachable". Arbitrary-command reads never reached it.

Fix (cluster_client::hold_pipeline()):

  • --command reads now take that same branch.
  • When no shard lists any replica, the message names the cause and the way out: error: --read-preference=secondary: CLUSTER SLOTS lists no replicas, so no read can be routed; use --read-preference=secondaryPreferred or --read-preference-fallback=primary.
  • When replicas are listed but unreachable, the existing warning is printed as before.
  • There's no new flag and no new wait. memtier doesn't refresh CLUSTER SLOTS on its own in this state, so waiting wouldn't let replicas appear, and the run ends as it did, now with exit 1 and the reason.

Test: test_strict_secondary_without_replicas_names_the_cause in tests/test_cluster_slots_bad_reply.py. It covers --command=PING --command-is-read, --command="GET __key__" and --ratio=0:1, each with the default fallback and with --read-preference-fallback=queue, against a scripted one-node cluster with no replicas. Each case must exit 1, print the new message, and send no data. With the fix reverted, all 6 cases fail: the PING and GET runs print no reason, and the built-in run only shows the old warning.

Not covered: a mixed built-in workload (--ratio=1:1) with strict secondary and no replicas also ends at once with only the generic message, before and after this change.

Results (ASan + UBSan, Ubuntu 24.04 container):

  • make check passes.
  • With 3 shards plus replicas, the read-preference (modes, failover, mget, resp3) and transaction tests pass 27/27.
  • Unowned-slots and read-preference validation pass 36/36.
  • The bad-reply file passes 22/22.
  • clang-format is clean.

🤖 Generated with Claude Code


Note

Low Risk
Targeted diagnostics and stall-path widening in cluster read routing; no new flags or topology refresh behavior.

Overview
Fixes #888: cluster runs with --read-preference=secondary and a topology that lists no replicas (typical right after redis-cli --cluster create) could finish with 0 ops and only a generic stop message for --command reads; built-in GET-only workloads already hit a stall path in hold_pipeline().

cluster_client::hold_pipeline() now treats arbitrary-command reads like pure read workloads when there is no routable target, so they enter the same stall/warning path. When strict secondary applies and no shard has any replica, it logs a once-per-process error: explaining that reads cannot be routed and suggesting secondaryPreferred or --read-preference-fallback=primary; if replicas exist but are unreachable, the existing rate-limited warning remains (text slightly clarified).

Test: test_strict_secondary_without_replicas_names_the_cause covers PING --command-is-read, keyed GET, and --ratio=0:1, with default and queue fallback, expecting exit 1, the new message, and no data commands sent.

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

With --read-preference=secondary and fallback error (or queue, which acts
as error), a CLUSTER SLOTS reply that lists no replicas leaves no target for
any read, as right after `redis-cli --cluster create`. The run then ends at
once with 0 ops. Only the built-in GET-only workload printed a warning
(hold_pipeline's no-route stall was limited to ratio.a == 0); keyless and
keyed --command reads ended with nothing but "client(s) stopped before
reaching their stop condition" (#888).

Hold arbitrary-command reads in the same no-route branch, so they behave
like the built-in GET-only workload, and when the topology has no replica
at all print an error that says so and points at secondaryPreferred or
--read-preference-fallback=primary, instead of the "all replicas
unreachable" warning. The run still fails as before; no wait is added,
since memtier does not refresh the slot map on its own here.

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

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

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

Thanks, this looks right to me. Letting --command reads use the same !any_route hold as ratio.a == 0 makes sense. A read at m_executed_command_index can't advance the rotation anyway, so the writes behind it were already stuck, and holding doesn't change what a mixed --command list does. The test covers all three read styles with both fallbacks, and you showed it fails with the fix reverted, which is the bar we want here.

A couple of small things:

  • Nitpicking: cluster_client.h:148 still describes m_last_no_replica_warning_ts as the timestamp of the "all replicas unreachable under read-only workload" warning. The second commit rewords that message, so the header comment should probably change with it. The block comment just above the branch (around cluster_client.cpp:1804) also still says "Keep the ratio.a==0 precondition for this branch only" before the new sentence about --command reads. I'd fold the new case into that sentence so it doesn't read like two different rules.
  • The no-replicas error is now printed once per process through the static std::atomic<bool>, while the "replicas listed but unreachable" warning still goes through the per-client 60s rate limit. I think that split is right, because the topology is shared and the unreachable case can recover. I just wanted to say it was a deliberate choice and not an accident.
  • You already called out --ratio=1:1 with strict secondary and no replicas as not covered. Is it worth opening a follow-up issue for it so it doesn't get lost? Those runs still end with only the generic "stopped before reaching their stop condition" message.

None of this blocks the merge. The fix and the test look good to me.

@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.

Stale Bugbot comment from a previous run.

Comment thread cluster_client.cpp
benchmark_error_log("warning: [thread %lu] all replicas unreachable under read-only workload "
"(--read-preference=%s); benchmark stalled -- check cluster health or set "
"--reconnect-on-error.\n",
(unsigned long) pthread_self(), rp_str);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Mixed-command stall drops queued writes

Medium Severity

The new stall treats the next --command as if the whole workload were read-only. When that command is a read and no replica is routable, hold_pipeline parks every connection, including ones that still have cross-shard writes sitting in m_key_index_pools. Mixed SET/GET --command runs can therefore drop already-routed writes and fail instead of sending them to the primary. Nearby holds skip this when a pool is non-empty, and mixed built-in --ratio traffic is still excluded from this branch.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit d5540f4. Configure here.

The topology is the same for every client, so -t 4 -c 50 printed the
error 200 times: print it once. The warning now also covers --command
reads and runs with --reconnect-on-error, so drop "read-only workload"
and say what --reconnect-on-error does. Update the comment that named
ratio.a==0 only.

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.

There are 2 total unresolved issues (including 1 from previous review).

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 f46698d. Configure here.

Comment thread cluster_client.cpp
benchmark_error_log("warning: [thread %lu] all replicas unreachable for reads "
"(--read-preference=%s); benchmark stalled -- check cluster health "
"(--reconnect-on-error lets it recover when they return).\n",
(unsigned long) pthread_self(), rp_str);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Read stall parks queued writes

Medium Severity

The new --command read stall in hold_pipeline() parks the connection whenever the next arbitrary command is a read and no replica is live, without checking for pooled or staged work. m_executed_command_index is shared across shards, so a mixed write-then-read --command list can queue a SET on another shard and then immediately hold every connection, leaving that write unsent.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f46698d. Configure here.

@fcostaoliveira
fcostaoliveira merged commit 417cfa5 into master Oct 27, 2026
168 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: strict --read-preference=secondary ends at once with 0 ops and no reason when CLUSTER SLOTS lists no replicas

1 participant