Repository navigation
Route --read-preference=primary reads to a still-connecting primary (fixes cluster seed stall) - #612
Conversation
|
🤖 Automated first-pass review — a human maintainer's review is still required before merge. Thanks for the thorough write-up and the gdb trace, it made this easy to follow. The fix looks right to me: with this change A couple of questions, nothing blocking:
Nice that the test runs Overall this looks good to me. I'd just like the steady-state question answered before merge. |
In cluster mode the -p seed connects first, and its CLUSTER SLOTS reply creates the other shard connections. If every read key belongs to another shard, select_target_conn() returned UINT_MAX for it under rp_primary, because that primary was still connecting. get_key_for_conn() then returned not_available, and hold_pipeline() didn't yield: the no-route gate skips rp_primary, and the write-side gate needs no live primary at all. So the seed's fill_pipeline() looped forever without returning to libevent. The other connections never finished connecting, and the run sat at 0 ops and 100% CPU. --test-time and the connection-stage abort couldn't stop the thread either. Writes already go to the slot's primary while it connects: they wait in its key index pool, which its fill_pipeline() only drains after the setup ladder is done. Route rp_primary reads the same way. The other read preferences keep their own bootstrap holds and are unchanged. Fixes #610 Co-Authored-By: Claude Opus 5.5 <[email protected]>
With --requests alone the run stops generating by itself, so the test passed even with hold_pipeline()'s in-flight budget disabled. Add a --test-time run with the default threads and clients: with the budget gate disabled it times out. Also cover --command=GET __key__, which stalled the same way, and check that no request was answered with MOVED. Update the comments that still said reads always need a live target: rp_primary reads now go to the slot's primary like writes, and a slot map refresh that retires a connection uncounts its queued requests. Co-Authored-By: Claude Opus 5.5 <[email protected]>
6018f0d to
0f97f5f
Compare
|
Thanks for the review. Point by point:
Also added in 0f97f5f:
Results: master 0/3 (all four cases time out), this branch 5/5, gate mutant 0/3. 🤖 Generated with Claude Code |
The test seeded memtier at the slot owner to avoid the first-shard stall (#610). #612 fixed that, so seed at the first primary as the other cluster tests do. That also covers routing from a seed that owns none of the keys. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test seeded memtier at the slot owner to avoid the first-shard stall (#610). #612 fixed that, so seed at the first primary as the other cluster tests do. That also covers routing from a seed that owns none of the keys. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test seeded memtier at the slot owner to avoid the first-shard stall (#610). #612 fixed that, so seed at the first primary as the other cluster tests do. That also covers routing from a seed that owns none of the keys. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test seeded memtier at the slot owner to avoid the first-shard stall (#610). #612 fixed that, so seed at the first primary as the other cluster tests do. That also covers routing from a seed that owns none of the keys. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test seeded memtier at the slot owner to avoid the first-shard stall (#610). #612 fixed that, so seed at the first primary as the other cluster tests do. That also covers routing from a seed that owns none of the keys. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test seeded memtier at the slot owner to avoid the first-shard stall (#610). #612 fixed that, so seed at the first primary as the other cluster tests do. That also covers routing from a seed that owns none of the keys. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test seeded memtier at the slot owner to avoid the first-shard stall (#610). #612 fixed that, so seed at the first primary as the other cluster tests do. That also covers routing from a seed that owns none of the keys. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test seeded memtier at the slot owner to avoid the first-shard stall (#610). #612 fixed that, so seed at the first primary as the other cluster tests do. That also covers routing from a seed that owns none of the keys. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test seeded memtier at the slot owner to avoid the first-shard stall (#610). #612 fixed that, so seed at the first primary as the other cluster tests do. That also covers routing from a seed that owns none of the keys. Co-Authored-By: Claude Opus 5.5 <[email protected]>
* Route cluster --command requests by the full key argument
A --command key argument can put text around __key__, for example
'{ask}-__key__' or 'user:__key__'. Redis hashes that whole argument (only
the tag when there is one), but get_key_for_conn() hashed the generated
key alone. Outside --transaction, most such requests went to the wrong
shard and came back -MOVED (110 of 200 for 'SET {ask}-__key__ v', 134 of
200 for 'SET test1:__key__ v').
The --transaction lookahead already rebuilt data_prefix + key +
data_suffix and hashed it with the hash-tag rule. Move that into
calc_arbitrary_key_hslot() and use it in get_key_for_conn() whenever
arbitrary commands are defined. Cluster mode allows only one key argument
per command, so the first key argument is the one that is sent.
Add an OSS cluster test that runs tagged prefix, tagged suffix and
untagged prefix key arguments, for SET and GET, and asserts that no
server replied -MOVED.
Fixes #614
Co-Authored-By: Claude Opus 5.5 <[email protected]>
* Run the --command key affix test from the default seed
The test seeded memtier at the slot owner to avoid the first-shard stall
(#610). #612 fixed that, so seed at the first primary as the other
cluster tests do. That also covers routing from a seed that owns none of
the keys.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
* Cover more --command key shapes in the key affix test
Add cases from the review: two --command lines with different key
affixes in one run, keys that are not the first argument (OBJECT
ENCODING, EVAL with numkeys 1), and --read-preference=secondary with
--command-is-read. The last one needs replicas, so it also asserts that
reads reached them, and it skips without replicas. Run the file in the
"OSS-CLUSTER + replicas: read-preference (modes)" CI cell as well.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---------
Co-authored-by: Claude Opus 5.5 <[email protected]>
Problem
In cluster mode with the default
--read-preference=primary, a run stalls with 0 ops and 100% CPU when the-pseed owns none of the keys being read (#610):With the default
-t 4 -c 50, memtier prints the 30 s "connection-stage failures" abort but still doesn't exit, because every worker is stuck at ~98% of a core.--ratio 1:1stalls the same way. Seeding on the owning shard works.This also blocks #609: once hash tags in
--key-prefixare honoured, a tag whose slot isn't on the seed hits this stall instead of a MOVED.Root cause
It is a busy loop inside one
fill_pipeline()call, not a fill/schedule ping-pong (confirmed with gdb:fill_pipeline←process_responseof the CLUSTER SLOTS reply, looping oncreate_get_request→get_key_for_conn).conn_in_progress) and then callsfill_pipeline()on the seed.rp_primary,select_target_conn()returnedUINT_MAXfor a read unless the slot's primary passedis_ready_for_reads(). The owner is still connecting, soget_key_for_conn()returnsnot_available.hold_pipeline()doesn't yield. The no-route gate skipsrp_primary. The write-side gate needs no live primary at all, and the seed is live. The in-flight budget never fills.fill_pipeline()never returns to libevent, and the other connections never handle their connect events.Writes don't stall:
select_target_conn()already returns a write's slot primary while it is connecting. The write waits in that connection's key index pool, and the pool is only drained after the target's setup ladder is done.Fix
Route
rp_primaryreads the same way as writes:select_target_conn()returns the slot's primary even while it is connecting. One line incluster_client.cpp.schedule_fill()and counted inm_reqs_generated, like a cross-shard write. The in-flight budget inhold_pipeline()bounds the producer while the owner connects, and the producer pauses instead of spinning.nearestandsecondaryPreferredalready complete on master.rp_primaryis unaffected: its slot list is built per primary, sorouted == conn_id.retry_after_redirect()still checks target readiness itself.Behaviour change (release notes)
This is not limited to bootstrap. When a primary goes down mid-run under
--read-preference=primary, reads for its slots used to be skipped silently. A read-only run kept going at full rate on the other shards (about 100k ops/sec in review), and the dead shard's keys were simply never read.Now those reads wait in that primary's pool until it reconnects or a slot map refresh moves its slots. In the meantime the in-flight budget stalls every shard, at about 100 ops/sec. Writes already behaved this way. The new behaviour is arguably more correct, because it no longer quietly skews the keyspace, but users can see the difference, so it belongs in the release notes.
If a slot map refresh retires the connection, its queued reads are uncounted, exactly like queued writes (
connect_shard_connection()and the retire path inhandle_cluster_slots()).Test
tests_oss_simple_flow.py:test_cluster_seed_owns_no_keysis cluster only. It looks up the owner ofmemtier-4, seeds on a different master, and runs four cases with a 20 s timeout:--ratio 0:1,--ratio 1:1and--command="GET __key__", each with-t 1 -c 1 --requests 200. These assertTotals.Count == 200.--ratio 0:1 --test-time 3with the default threads and clients. This assertsCount > 0. Without--requests, only the in-flight budget inhold_pipeline()bounds what the seed queues for the owner.Every case also asserts
MOVED/sec == 0.Latest runs on 0f97f5f:
if (false && in_flight >= in_flight_budget))get_test_timefails, with a timeout. The--requestscases pass, which is why the case was added.Earlier runs of the two-case version on 6018f0d:
Local 3-shard OSS cluster, Redis 8.6.0:
Manual repro with default
-t 4 -c 50 --test-time 5: master is still running at 60 s (killed), this branch finishes in 6.1 s with ~94k ops/sec.Regression suites on this branch, all passing:
tests_oss_simple_flow.py28/31 in the full run, and the other 3 pass when run on their own (see below);test_mget_cluster.py9/9,test_cluster_redirect_stats.py4/4,test_cluster_transaction.py17/17,test_reconnections.py10/10,test_read_preference_modes.py6/6.--use-slaves:test_read_preference_modes.py6/6,test_read_preference_failover.py2/2,test_read_preference_mget.py5/5,test_read_preference_transaction.py4/4,test_cluster_failover_retry.py1/1.In the first full
tests_oss_simple_flow.pyrun, 3 SET tests failed on key counts. I had accidentally started a second RLTest cluster on the same ports. Run on their own, those tests pass with both this branch and master.Merge order
Merge this PR first, then #609 and #616. Once this lands, they can drop their seed pins.
Fixes #610
Affected versions
2.5.0 through 2.5.2 (latest) and master. Introduced by ee757e7, "feat: --read-preference" (#456). That change added the
rp_primaryreadiness gate inselect_target_conn(). First tag: 2.5.0.🤖 Generated with Claude Code