Repository navigation
Don't continue a --transaction block after its MULTI is lost - #607
Conversation
|
🤖 Automated first-pass review. A human maintainer still needs to review this before merge. Thanks for this. I went through the diff and the surrounding
The integration test fails 8/8 on master and passes here, and the unit check fails with the source fix reverted. That's the fails-then-passes bar this repo has accepted before (PR#364). It's good to see standalone (I'd 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 1 potential issue.
❌ 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 9c14747. Configure here.
Nothing checked that the connection sending the rest of a rotation was still the one holding the rotation's MULTI. When the pinned connection dropped mid-block, the server discarded the MULTI with the socket, but memtier still sent the rest of the block. Either the pin survived and the reconnected socket sent it, or another connection released the pin in hold_pipeline() and the lookahead re-pinned the tail elsewhere. The SET then ran outside any transaction and the EXEC failed with "EXEC without MULTI". With -t 2 -c 4 --pipeline 8 and one shard's clients killed every 0.5s, that was 4-17 -ERR replies per run. Remember which connection carries the rotation's open MULTI. If a later command of the block would go to another connection, or to one that no longer has the MULTI open, skip it up to and including the EXEC/DISCARD and advance the rotation without sending it. The server already discarded what was queued, so memtier's counts keep matching the server's. A skipped block may not have sent its lookahead key yet. Keep that key for the next rotation instead of clearing it when the rotation wraps, so --key-pattern=S has no gap. Fixes #604 Co-Authored-By: Claude Opus 5.5 <[email protected]>
9c14747 to
20778b5
Compare
|
Thanks. I rebased onto 38fae5d (#606, #615 and the rest are in). Answers point by point:
Also found while checking this: standalone 🤖 Generated with Claude Code |
…ps its MULTI With --transaction against a single endpoint, a connection killed after it sent a rotation's MULTI reconnects with the rotation index still on the next command of the block. The rest of the block (SET, EXEC) then went out on the new socket: the SET ran outside any transaction and the EXEC failed with "EXEC without MULTI", while the run still exited 0. client::create_request() (the standalone path) now remembers that this rotation's MULTI was sent. If the connection no longer has the MULTI open, it skips the rest of the block up to and including the EXEC/DISCARD, without sending or counting it. The server already discarded what was queued. This is the same rule #607 adds for cluster mode in cluster_client::create_arbitrary_request(). Fixes #633 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ps its MULTI With --transaction against a single endpoint, a connection killed after it sent a rotation's MULTI reconnects with the rotation index still on the next command of the block. The rest of the block (SET, EXEC) then went out on the new socket: the SET ran outside any transaction and the EXEC failed with "EXEC without MULTI", while the run still exited 0. client::create_request() (the standalone path) now remembers that this rotation's MULTI was sent. If the connection no longer has the MULTI open, it skips the rest of the block up to and including the EXEC/DISCARD, without sending or counting it. The server already discarded what was queued. This is the same rule #607 adds for cluster mode in cluster_client::create_arbitrary_request(). Fixes #633 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ps its MULTI With --transaction against a single endpoint, a connection killed after it sent a rotation's MULTI reconnects with the rotation index still on the next command of the block. The rest of the block (SET, EXEC) then went out on the new socket: the SET ran outside any transaction and the EXEC failed with "EXEC without MULTI", while the run still exited 0. client::create_request() (the standalone path) now remembers that this rotation's MULTI was sent. If the connection no longer has the MULTI open, it skips the rest of the block up to and including the EXEC/DISCARD, without sending or counting it. The server already discarded what was queued. This is the same rule #607 adds for cluster mode in cluster_client::create_arbitrary_request(). Fixes #633 Co-Authored-By: Claude Opus 5.5 <[email protected]>
#634) With --transaction against a single endpoint and --reconnect-on-error, a connection killed after sending a rotation's MULTI resumed the block on the new socket. The SET ran outside any transaction and EXEC failed with "EXEC without MULTI", while the run still exited 0. client::create_request() now tracks whether the rotation's MULTI was sent (m_txn_multi_sent). Outside cluster mode, if the connection no longer has the MULTI open, the rest of the block through its EXEC/DISCARD is skipped and not sent. The next rotation starts with a fresh MULTI, and commands after the EXEC are sent as normal. Cluster mode keeps its own check in cluster_client::create_arbitrary_request() (#607). Docs: --help and the man page's --transaction entry (regenerated from usage()) now say a reconnect inside a MULTI block skips the rest of it uncounted, that replies already received stay counted, and that the same-key behavior applies in every mode. Adds test_retry_on_error.py::test_transaction_lost_multi_is_not_continued. Fixes #633 Refs #673 Co-Authored-By: Claude Opus 5.5 <[email protected]>

Problem
With
--cluster-mode --transaction, if the connection holding a rotation'sMULTIdrops mid-block, memtier still sends the rest of the block. It goes either on the reconnected socket or on another shard's connection. TheSETruns outside any transaction, and theEXECfails with-ERR EXEC without MULTI. With-t 2 -c 4 --pipeline 8and one shard's clients killed every 0.5s, that was 3–17-ERRreplies per run on master (#604).Root cause
The pin decides which connection sends the next command of a rotation. Nothing checked that this is still the socket that holds the rotation's open MULTI. Instrumenting master showed two ways in, and every
EXEC without MULTImatched one of them:shard_connection::disconnect()clearsm_multi_open, and the server drops the MULTI with the socket. If no other connection released the pin meanwhile, the reconnected socket sendsSETandEXEC.hold_pipeline()sees the pin disconnected and callstxn_release_pin(). The lookahead then re-pins the tail of the block (SET,EXEC) on another connection.The #583 review also described a variant where a MOVED on an earlier pipelined rotation releases the pin. On current master that release is gated by
is_multi_open()(#569), and only the two disconnect paths above showed up.Fix
m_txn_multi_conn_idrecords the connection that sent the rotation's MULTI opener. It is cleared when the EXEC/DISCARD is sent, when the rotation wraps, and on a fulldisconnect().is_multi_open(), is skipped up to and including the EXEC/DISCARD. The rotation advances (advance_arbitrary_command_index()), nothing is sent, and nothing is counted. The server has already discarded what was queued, so memtier's per-command counts keep following the server's.m_txn_has_staged_key, so that key goes to the next rotation and--command-key-pattern=Shas no gap. A staged key can only be left at a wrap when its block was cut short.Still needed after #606 and #615
Rebased onto master 38fae5d, which has #598, #606, #613 and #615.
--transactionrequests.disconnect()now drops the in-flight requests. That covers commands that were already written when the socket died. It does not cover the commands of the block that were not generated yet. The rotation index keeps going, and the nextfill_pipeline()generates the block'sSET/EXECon the reconnected socket or on a new pin. That is the path fixed here.SET/EXECwent out on the new socket without a MULTI. With this PR,m_txn_multi_conn_idis still that connection butis_multi_open()is false, so the tail is skipped.!is_multi_open()on the MULTI's connection means the MULTI really is gone. Before Don't retry or replay --transaction requests (#611) #615, a replayedMULTIdid not setm_multi_open(Bugbot's comment). That case no longer exists.Conflicts were only adjacent lines:
m_txn_wait_slot(#606) andm_txn_multi_conn_id(this PR) are both kept in the constructor,disconnect(), the rotation-wrap reset and the header. The tests are the union of both PRs.Test evidence
New integration test
test_transaction_lost_multi_is_not_continued: MULTI/SET/EXEC at-t 2 -c 4 --pipeline 8, with one non-main shard's clients killed every 0.5s for 8s. It asserts noEXEC without MULTIin stderr anderrorstat_ERR == 0on every primary.-ERR EXEC without MULTIper run-ERR EXEC without MULTINew unit check in
tests/unit/cluster_transaction_test.cpp: drop the connection right after MULTI. Then SET, GET and EXEC must not be written to the output buffer, and the unsent staged key must be the one the next rotation sends. Rebased on 38fae5d:On the rebased branch (3-shard cluster):
test_cluster_transaction.pypasses 19/19, including Hold a --transaction rotation while its key's shard reconnects #606'stest_transaction_waits_for_reconnecting_key_owner.make checkpasses 6/6.Out of scope: standalone
--transactionStandalone
--transactionhas the same split, and this PR does not change it.client::create_arbitrary_request()never checksis_multi_open(), so after a--reconnect-on-errorreconnect the rest of the block goes out on the new socket. Test setup: standalone redis, MULTI/SET/EXEC,-t 2 -c 4 --pipeline 8 --reconnect-on-error,CLIENT KILL TYPE normalevery 0.3s for 6s, no--retry-on-error. Result: 40 kills, 30-ERR EXEC without MULTI, and memtier exits 0. That needs its own fix and test, so it is left as a follow-up.Affected versions
2.4.0 through 2.5.2 (latest) and master. The pin, its release on disconnect, and the mid-rotation re-pin come from f7f8983 (#390), which is first in 2.4.0.
EXEC without MULTIper run before the Cluster --transaction: CLUSTER SLOTS sent inside an open MULTI wedges the main connection #569 hang. Some of those come from the pre-Cluster --transaction: CLUSTER SLOTS sent inside an open MULTI wedges the main connection #569 MOVED release path.Fixes #604
Found during the review of #583. Related: #569, #576, #580, #583.
🤖 Generated with Claude Code