Repository navigation
Hold a --transaction rotation while its key's shard reconnects - #606
Conversation
|
🤖 Automated first-pass review — a human maintainer's review is still required before merge. Thanks for this. I went through the cluster_client changes and the test rework, and I have a couple of comments below. The fix looks right to me. A rotation pinned to a non-owner can only end in MOVED/EXECABORT, so waiting for the owner costs no committed work. Clearing
Nitpicking: The core change looks solid to me. I'd mainly like to see the long-outage behavior in (1) acknowledged before this merges. (would file this as a comment, not a formal block) |
When the shard that owns a rotation's key was disconnected, the lookahead fell back to pinning the rotation on the current connection, which belongs to another shard. MULTI is accepted there, the keyed command is rejected with -MOVED and EXEC returns -EXECABORT. This repeats for every such rotation until the shard has reconnected, about 1s per CLIENT KILL. A 3-shard run that killed one shard's clients 5 times hit 1.4k-2.2k MOVED/EXECABORT pairs, and the topology never changed. Wait for the owner instead. Keep the staged key and record its slot. hold_pipeline() then parks every connection while that slot's primary connection is disconnected. The owner resumes the rotation from its own fill_pipeline() once it reconnects. A slot map refresh that moves the slot to a live connection releases the hold too: update_slot_map() wakes every live connection while a rotation waits, so one of them re-runs hold_pipeline() against the new owner. The fallback to the current connection stays for rotations without a keyed command or without a slot map. The misrouted rotations never committed, so holding costs no committed throughput: 19.1k-21.6k committed transactions per run, against 18.8k-21.4k before. Kills no longer produce a MOVED, so the #569 kill test could no longer rely on "received MOVED mid-rotation", which made it flaky. It now puts every key on the main node, so the main connection is inside a MULTI whenever a kill makes it refresh the slot map, and asserts that no DISCARD and no ERR reply were needed. With the #569 hold removed it fails (3 DISCARD, 3 "EXEC without MULTI"). Fixes #603 Co-Authored-By: Claude Opus 5.5 <[email protected]>
b9d8c2a to
4317558
Compare
|
Thanks for the review. Pushed 4317558, rebased on master ade1d56. Answers in order:
🤖 Generated with Claude Code |
Problem
With
--cluster-mode --transaction, while a shard connection is reconnecting (for example afterCLIENT KILL TYPE normal), every rotation whose key belongs to that shard is pinned to another shard. The keyed command gets-MOVED, andEXECreturns-EXECABORT. This happens for every such rotation for about 1s per kill. With--command-key-pattern=Seach aborted rotation also leaves a hole in the key range (#603).Root cause
The lookahead in
cluster_client::create_arbitrary_request()pins a rotation to the owner of its first keyed command. When that owner wasconn_disconnected, the fallback pinned the rotation to the current connection (target_conn = conn_id), which belongs to a different shard. The fallback was there so that no rotation pins to a dead connection and stalls every other connection inhold_pipeline().Fix
Wait for the owner instead of falling back:
m_txn_wait_slot, and returns without pinning.hold_pipeline()parks every connection while that slot's primary connection is disconnected.fill_pipeline()once it has reconnected. A slot map refresh that moves the slot to a live connection releases the hold too, because the owner is looked up again on each check.disconnect(), like the other pin state.handle_cluster_slots()(the slot map refresh) wakes every live connection while a rotation waits (m_txn_wait_slot != -1), so a refresh that moves the slot to a live connection always gets some connection to re-runhold_pipeline()and resume the rotation.test_transaction_connection_kills_do_not_hang(#569) used to requirereceived MOVED mid-rotationin stderr. That MOVED only came from this misroute, so kills no longer produce it (and on master it was already flaky, since it depended on a kill landing mid-rotation). The test is now deterministic about the #569 path:{tag}__key__with a hash tag owned by the main node, so the main connection drives every rotation and sits inside a MULTI whenever a kill of another shard makes it refresh the slot map;cluster slot failed, and that the server saw 0 DISCARD and 0errorstat_ERR. Sent inside the MULTI, the refresh would DISCARD it and the rotation's EXEC would fail withEXEC without MULTI.test_transaction_waits_for_reconnecting_key_owneralso uses--command-key-pattern=Son the SET and asserts the holes in the sequential key range are at mostkills * pipeline(only transactions in flight on a killed connection may be lost).Test evidence
New test
test_transaction_waits_for_reconnecting_key_owner: MULTI/SET/EXEC with one non-main shard's clients killed every 0.5s for 8s. It asserts that the server'serrorstat_MOVEDanderrorstat_EXECABORTare 0.Other checks on this branch:
test_cluster_transaction.pypasses 18/18 (3-shard cluster).setup_held_for_transaction()returning false): the rewrittentest_transaction_connection_kills_do_not_hangfails with 3 DISCARD and 3EXEC without MULTI(1/1 run).test_transaction_pipeline.pypasses 3/3.make checkpasses 5/5.Manual repro from #603 (local 3-primary cluster,
-t 1 -c 1 --pipeline 1,--command-key-pattern=Son the SET, 5 kills over 12s), with server stats summed over the primaries:The 2 keys still missing per run come from a separate bug, #604 (PR #607): a MULTI lost on a killed connection is continued on another socket and ends in
EXEC without MULTI. Together with that PR, the same runs had no error replies at all, and server SET calls equaled EXEC calls.Throughput: the rotations that were misrouted never committed, so waiting for the owner costs no committed work. I ran 4 interleaved master/PR pairs (the same repro,
-t 1 -c 1, 5 kills in 12s). Committed transactions/sec (memtier's Execs Hits/sec) were 2209 / 1748 / 2641 / 4427 on master and 1144 / 2876 / 3408 / 3707 with this PR. The host was shared and under load (loadavg about 20), so the spread is mostly noise, and the medians (about 2.4k vs 3.1k) show no regression. Without kills, the new code is never reached.A permanently stopped shard (
SHUTDOWN NOSAVE2s into an 8s run, no failover) does not hang the run. It ends at--test-timewith rc 0, as master does.Affected versions
2.4.0 through 2.5.2 (latest) and master. The fallback was introduced by f7f8983 (#390), which is first in 2.4.0.
Fixes #603
Found during the review of #583.
🤖 Generated with Claude Code
Note
Medium Risk
Changes cluster transaction pinning and global pipeline hold behavior during reconnects; incorrect wait/clear logic could stall or mis-route MULTI/EXEC, though coverage is added for kill/reconnect scenarios.
Overview
Cluster
--transactionmode no longer misroutes rotations when the key owner’s shard is reconnecting. Instead of pinning the rotation to the current connection (which caused-MOVED/EXECABORTand sequential key gaps under--command-key-pattern=S), the client now records the staged key’s slot inm_txn_wait_slot, skips pinning, and parks all connections inhold_pipeline()until that slot’s primary is connected again—or a slot-map refresh moves the slot to a live connection (with an extraschedule_fillwake on topology commit).The disconnected-owner fallback to
conn_idremains only when there is no keyed command or the slot map is not ready yet. Wait state is cleared on disconnect, rotation wrap, and alongside other pin state.Tests:
test_transaction_connection_kills_do_not_hangis retargeted to keys on the main shard (hash tag) and asserts slot-map refresh mid-run instead of MOVED; helpers and_run_with_shard_killsgainextra_args/ per-command--options. Newtest_transaction_waits_for_reconnecting_key_ownerchecks zero MOVED/EXECABORT and bounded sequential key holes during shard kills.Reviewed by Cursor Bugbot for commit 4317558. Bugbot is set up for automated code reviews on this repo. Configure here.