Repository navigation
Never send CLUSTER SLOTS inside an open --transaction MULTI (#569) - #576
Conversation
In --cluster-mode --transaction, a slot map refresh could be written on the
pinned connection between MULTI and EXEC: after a MOVED/ASK mid-rotation
(handle_moved re-arms CLUSTER SLOTS on that connection), or when
cluster_client::reconnect() requests a refresh on the main connection while
it holds the pin. The server queues it and answers +QUEUED, the reply handler
reports "cluster slot failed", m_cluster_slots never reaches setup_done and
the run hangs past --test-time.
- shard_connection tracks m_multi_open, set when a MULTI is written and
cleared on EXEC/DISCARD or (re)connect.
- fill_pipeline() defers a pending CLUSTER SLOTS refresh while the
connection still drives the pinned rotation inside an open MULTI; it is
sent right after the rotation's EXEC/DISCARD.
- A MOVED/ASK on the pin connection inside an open MULTI no longer releases
the pin: the rest of the rotation (EXEC) still goes to the connection
holding the MULTI and the server answers EXECABORT, instead of EXEC being
sent to another shard ("EXEC without MULTI") and this MULTI left open.
- Defensively, if a refresh is due on a connection whose MULTI was
abandoned by its rotation, a DISCARD is sent before CLUSTER SLOTS.
Adds a regression test that kills one shard's connections during a
--transaction run; it hung on master 5/5 and passes 10/10 with the fix.
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. The root-cause write-up is clear, and both new tests are the kind we want: the first hangs on master and passes here, and the second actually exercises the DISCARD fallback instead of just claiming it can be reached. Moving the MULTI/EXEC/DISCARD role into
Cluster transaction pinning is subtle enough that this may also be worth a second look from whoever knows the cluster routing code best. The fix itself looks solid to me. I'd mainly like an answer on (1) before this merges. |
send_arbitrary_command_end() compared command_type against "MULTI", "EXEC" and "DISCARD" on every --transaction request. The role is static per --command, so resolve_command_meta() now records it from argv[0] in arbitrary_command::multi_effect and the request path only checks an enum. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The DISCARD sent before CLUSTER SLOTS is reachable: a --transaction rotation that opens a MULTI and never closes it (--command=MULTI --command="SET __key__ __data__", no EXEC) leaves the MULTI open once the rotation wraps and pins another shard, and the next refresh on that connection would otherwise be queued (+QUEUED) and hang the run. Add test_transaction_abandoned_multi_is_discarded_before_refresh, which kills a non-main shard's connections under that rotation and checks the run exits cleanly and the servers saw DISCARD. Without the fallback it hangs past --test-time. The existing kill test now also asserts that a well-formed MULTI/SET/EXEC rotation never needs the DISCARD. Spell out in the code comment when the fallback runs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks for the review. I pushed two commits: f7c9e18 (MULTI/EXEC/DISCARD role resolved at config time) and 828e8a8 (test for the DISCARD fallback, plus a clearer code comment). I didn't rebase: the branch still merges cleanly on top of #571, #572 and #573. 1. Yes, and keeping the pin is still right there. The pin decides where future writes go, so write-side state is the right input. Take rotation N (MULTI/SET/EXEC), all written on connection A. Rotation N+1 has also pinned A and written its MULTI. Then the MOVED for N's SET arrives:
A 2. Can the defensive DISCARD ( Yes, so I added a test. Here's the path: a
Without the DISCARD, CLUSTER SLOTS is queued ( Evidence on a local 3-shard cluster, with the kill loop from the existing test running against a non-main shard:
New test The existing kill test now also asserts 0 DISCARDs for MULTI/SET/EXEC. So a well-formed rotation never needs the fallback: there, the refresh just waits for the EXEC. I rewrote the code comment to say exactly when the fallback runs. 3. Per-request string compares in Done in f7c9e18. Tests (head 828e8a8, local 3-shard OSS cluster via RLTest)
I've updated the PR description to match. 🤖 Generated with Claude Code |
|
Split out as a follow-up: #580. |
Fixes #569
Problem
--cluster-mode --transactionruns can hang past--test-timewhen connections get dropped (for exampleCLIENT KILL TYPE normalon one node). memtier logs "pin connection (id=N) received MOVED mid-rotation", then "cluster slot failed", and never exits.Root cause
A CLUSTER SLOTS refresh was written on the pinned transaction connection between MULTI and EXEC. The server queues it and answers
+QUEUED. The CLUSTER SLOTS reply handler treats that as a failed refresh, som_cluster_slotsnever reachessetup_done,fill_pipeline()keeps waiting for setup, and the run wedges. There are two ways in:-MOVED, andhandle_moved()re-arms CLUSTER SLOTS on that same connection, which still has the MULTI open.MAIN_CONNECTION->set_cluster_slots()incluster_client::reconnect(). An unrelated shard drops while the main connection is pinned inside a MULTI.On the MOVED path, the pin was also released mid-rotation, so the rotation's EXEC went to a different shard ("EXEC without MULTI") and the MULTI on the original connection stayed open.
Fix
shard_connectiontracksm_multi_open. It is set when a--transactionMULTI is written, and cleared on EXEC/DISCARD and on connect/disconnect.fill_pipeline()defers a pending CLUSTER SLOTS refresh while the connection still drives the pinned rotation inside an open MULTI (connections_manager::is_transaction_pinned()). The refresh goes out right after the rotation's EXEC/DISCARD is written.EXECABORT: the interrupted transaction is aborted atomically on one connection, not split across two. Outside a MULTI the pin is released as before.--command=MULTI --command="SET __key__ __data__", no EXEC) leaves that MULTI open after the rotation wraps and pins another shard. If a refresh is then due on that connection, memtier sends an internalDISCARD(new setup-only request typert_discard) before CLUSTER SLOTS. This path is reachable and has its own test; without it that workload hangs.rt_discardis excluded from workload stats and read classification. A well-formed MULTI ... EXEC rotation never reaches it.--command's MULTI/EXEC/DISCARD role is resolved once at config time (arbitrary_command::multi_effect), so the request path does no string compares.Test evidence
New test:
test_cluster_transaction.py::test_transaction_connection_kills_do_not_hang. It runs MULTI/SET/EXEC with--transaction -t1 -c1 --pipeline=1 --test-time=8 --reconnect-on-errorwhile it repeatedly runsCLIENT KILL TYPE normalon a non-main shard. It asserts that the run:--test-time + 30s;timeout 40, 12 kills)--test-timeWith this PR, every MOVED inside a MULTI now yields exactly one
EXECABORTon the same connection (for example 11821 MOVED → 11821 EXECABORT). The only "EXEC without MULTI" errors left (0–5 per run) come from the pinned connection itself being killed mid-rotation, an existing path this PR doesn't change.New test:
test_cluster_transaction.py::test_transaction_abandoned_multi_is_discarded_before_refresh. It uses the same kill workload with a MULTI/SET rotation (no EXEC) and asserts a clean exit, no "cluster slot failed", and that the servers sawDISCARD(INFO commandstats). It passed 3/3 on this branch. With the DISCARD fallback compiled out it failed 2/2 (hung past--test-time, "cluster slot failed"). The kill test above also asserts 0 DISCARDs for the well-formed MULTI/SET/EXEC rotation.Also run on the head commit, all passing:
test_cluster_transaction.py(16/16, twice),test_transaction_pipeline.py(3/3). Earlier revision:test_reconnections.py(9/9).Not fixed here (pre-existing, separate issue)
With
--pipeline > 1the same kill workload can crash a worker withvector::_M_range_checkinclient::create_arbitrary_requeston master as well.txn_release_pin()pushes a lone staged key index into the old pin'sm_key_index_pools, andcluster_client::create_request()later pops it as a command index. This PR makes that path rarer (MOVED inside a MULTI no longer releases the pin) but doesn't fix it. It will be filed separately.Affected versions
Affected versions: 2.4.0–2.5.2 and master (introduced by f7f8983 / #390; widened by #560 / 6f15854); hang confirmed on 2.5.2 and 2.4.0
🤖 Generated with Claude Code