Repository navigation
Keep keyless commands off replica connections unless replica reads are allowed - #887
Conversation
…e allowed A keyless --command has no slot to route by, so cluster mode sends it on whichever connection is filling its pipeline. Since --read-preference added replica connections, that includes replicas: about half of the keyless commands went to replicas even with --read-preference primary (the default) and for writes, which then got -READONLY and each forced a CLUSTER SLOTS refresh (#676). A replica connection now holds its pipeline when the next command is keyless, unless the command is a read and the read preference allows replica reads. The primaries produce those commands instead, as in 2.4. Pooled keys and staged --monitor-input lines are still drained, and keyed routing is unchanged. The scripted CLUSTER SLOTS node now counts the commands it receives, so a test can check that a one-shard cluster's replica gets no keyless commands under primary preference or for writes, and does get keyless reads under a replica-allowing preference. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🤖 Automated first-pass review — a human maintainer's review is still required before merge. Thanks for this. I went through the
Since this is cluster routing and pipeline scheduling, a second look from whoever owns the cluster client would still be good. The fix looks solid to me otherwise. None of the above blocks it. (Would file this as a comment, not a formal block.) |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.
❌ 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 ef994a7. Configure here.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Holding a replica off keyless commands left two ways for a run to stall with nothing left to drive the event loop, so the thread ended before --requests: - A keyless read produced on a primary and routed to the replica was written to the replica's bufferevent, which had been disabled when the replica went idle. The bytes were never flushed, so a mixed keyless write/read workload lost the read. Schedule a fill on the destination, which re-enables it, as the keyed path does after pushing to a pool. - A primary parked by the in-flight budget with nothing of its own in flight was only woken by a producer, and the held replica was that producer. Keyed reads to the replica mixed with a keyless write (e.g. GET __key__ plus PING under secondary) stopped after a few requests. Wake a primary when the replica holds. The new test runs each mixed workload with the default pipeline depth and checks the exact command counts on the primary and the replica. Each of the two wakeups is needed for a different case. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Holding a replica off every keyless command that is not flagged as a read was stricter than #676 needs. The harm is a keyless write reaching a replica, which rejects it with -READONLY, and any keyless command reaching a replica under --read-preference primary. A PING under secondaryPreferred could no longer be answered by the replica when the primary was down, and test_cluster_unowned_slots expected that. The command table only recorded READONLY, so a command was either a read or "not a read", and PING counted as a write. The generator now also records may_write: the WRITE or MAY_REPLICATE flag. MAY_REPLICATE is what EVAL and FCALL carry, since a script can write. Regenerated from the vendored command JSON; only the new field changes. Under primary, a replica still produces no keyless commands. Under the other preferences it holds only those that are not reads and may write, or that are unknown (the table's safe default is "write"). --command-is-read still overrides the table. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks. On both questions, plus a CI failure the first version caused:
Results (ASan + UBSan):
|
They carry no WRITE or MAY_REPLICATE flag, yet a replica answers them
with an error ("WAIT cannot be used with replica instances"), so hold
them on replicas like keyless writes.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
A review of 67c300d found one more replica rejection, fixed in 1100c51: |
|
Thanks. On (3): agreed. The proposed release-notes line now says that unknown or module commands count as possible writes, so keyless module reads need |
A held replica wakes only one primary. With two shards that is enough: the woken primary produces the whole command rotation, keyless commands on itself and keyed ones into the owning connection's pool with a fill scheduled there, so a second primary parked with nothing in flight never needs a wake of its own. The test now runs two of the mixed workloads on a scripted two-shard cluster and checks the exact totals per role. Also rename primary_only to replica_rejects and put the keys_count comment back above the condition it explains. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
On (1): I checked it, and with several shards a second primary can't be left parked with nothing to wake it. I added 2-shard coverage in b547b46. Experiment: a 2-shard scripted cluster (two primaries, each with a replica) and four workloads (
Why one woken primary is enough:
Two 2-shard cases are now in The same commit renames Sanitized |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
With the only primary unreachable, a replica held off a keyless write wakes nobody. The run does not end as a silent short run: the reconnect timer keeps the loop alive, and when the thread ends early the end of run check reports it and the exit code is 1, exactly as for a keyed write to the dead primary. Master instead sent the writes to the replica, which a real server rejects with -READONLY. The test pins this down with the replica as the seed and the primary's port refusing connections. Also say that the literal-key comment applies only where the hold does: a literal-key read such as "GET foo" under secondary still goes to a replica. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks. On the no-primary case: it doesn't become a silent short run. A held keyless write now behaves like a keyed write to the dead primary already does on master. I checked this on a scripted 1-primary + 1-replica cluster seeded on the replica, with the primary's port refusing connections from the start (
The scripted replica answers The thread can't run dry silently. Without reconnect, the refused connection ends the thread and the end-of-run check reports it with exit 1. With reconnect, the reconnect timer keeps the loop alive. The one rc=0 / count 0 row is how keyed writes already behave on master. f8709c8 adds The same commit rewords the On the per-call work and the help text: the block only runs on replica connections, after the pool, staged-command and budget checks. The two Sanitized |
|
Thanks. Taking the open points in turn.
|

Fixes #676.
In
--cluster-mode, memtier opens a connection to every replica in CLUSTER SLOTS. A keyless--command(no__key__, e.g.PINGorEVAL ... 0) was sent on whichever connection produced it, replicas included. That happened even with--read-preference primary(the default) and for commands not marked--command-is-read. Roughly half the keyless commands reached replicas, and keyless writes got-READONLYthere, each followed by a CLUSTER SLOTS refresh. 2.4 never sent anything to replicas.Fix (
cluster_client::hold_pipeline()):--read-preference primary, a replica connection produces no keyless command.--command-is-read. Keyless reads and non-writes like PING still go to replicas.may_writeflag (WRITEorMAY_REPLICATE) fromscripts/gen_command_meta.py. Socommand_meta_data.his regenerated: all 425 rows gain one field, from the same Redis source.Unchanged:
--monitor-inputlines, which route themselvesI didn't reroute inside
create_arbitrary_request(). Under--read-preference primary, returning false there would makefill_pipelinespin, because the existing yield only covers non-primary preferences.Test. The scripted
_Nodepeer intests/test_cluster_slots_bad_reply.pynow counts the commands it receives. The newtest_read_preference_keyless_commands_skip_replicasintests/test_read_preference_modes.pybuilds a 1-primary + 1-replica cluster from it. That avoids the RLTest replica limitation in #462.On master, the replica received 370–407 of 800 keyless commands in each case that must be 0:
primarywith and without--command-is-readsecondary/secondaryPreferredWith the fix it receives 0, and it still receives keyless reads under
secondaryandsecondaryPreferred.Results (ASan + UBSan, Ubuntu 24.04 container):
make checkpasses, and the new test plus the files that reuse_Nodepass 57/57.test_cluster_transactionassertions, which master fails the same way in this container.Release notes (proposed)
🤖 Generated with Claude Code
Note
Medium Risk
Changes cluster read-preference and pipeline scheduling for keyless arbitrary commands; incorrect holds or wake logic could stall benchmarks or mis-route writes, though behavior is scoped and heavily tested.
Overview
Fixes cluster-mode behavior where keyless
--commandtraffic (no__key__) was issued from replica connections, causing-READONLYon writes and extra CLUSTER SLOTS churn (#676).Routing / pipeline:
hold_pipeline()now stops idle replica connections from producing keyless arbitrary commands when they must not run there: always under--read-preference primary, and under other preferences only for keyless commands that may write, are unknown to the command table, or areWAIT/WAITAOF(unless--command-is-read). Held replicas wake a primary; cross-connection arbitrary sends also callschedule_fill()on the destination so parked connections flush.Metadata:
CommandSpecgains a generatedmay_writeflag (WRITEorMAY_REPLICATEfrom Redis command docs), wired throughgen_command_meta.pyand the regeneratedcommand_meta_data.htable.Tests: The scripted cluster
_Nodepeer tracks per-command counts; new read-preference tests assert replica vs primary distribution and that holds do not stall runs or mask unreachable-primary failures.Reviewed by Cursor Bugbot for commit e092ce8. Bugbot is set up for automated code reviews on this repo. Configure here.