Repository navigation
Preserve transaction lookahead when a cluster pin is released - #583
Conversation
|
🤖 Automated first-pass review — a human maintainer's review is still required before merge. Thanks for this. I went through the pin-release and re-pin paths and it looks right to me. The old code pushed a bare key index into a queue of It's also good to see a deterministic unit test that fails on master. It checks both the routed-pair queue staying intact (including the small key index that would quietly pass as a valid command index) and the sequential iterator not being advanced twice. That's stronger than relying only on the shard-kill integration test, which depends on timing. Just checking one thing: as far as I can tell, the only place an unconsumed staged key still gets dropped is the reset when This is cluster and transaction routing, so it may be worth a second look from whoever owns that code. Otherwise this looks good to me. |
|
Reconnect and pin release do not themselves advance the command rotation ( There is a separate pre-existing edge case, so I would not claim that a staged key can never be dropped: losing the pin after the final keyed command can make circular lookahead stage a future key while sending a trailing keyless command such as EXEC. The subsequent rotation reset then drops that key. Both the circular lookahead and the wrap reset are unchanged from master. This PR fixes the routed-pair queue corruption and preserves the already-staged unsent key; it does not fix that existing tail case. Seven independent high-effort reviewers inspected this candidate before opening the PR, including the transaction lifecycle and queue invariants. Human maintainer review remains for the next session. |
|
Adversarial review summary: 7 independent reviewers each took one area (semantics, output compatibility, test discrimination, build/packaging, lifetime/state machine, interactions with #574–#576/#582/#578, maintainer standards). All 7 gave MERGE. The bug is fixed:
Transaction behaviour is unchanged:
Tests catch the bug:
Builds and packaging pass:
Works alongside the other fixes: combined with #582 and the #578 fix, the cluster suites pass 46/46 on plaintext and on TLS. Non-blocking follow-ups:
Pre-existing, not caused by this PR:
🤖 Generated with Claude Code |
Mutation testing during the review of #582 and #583 found faults that the merged tests did not catch. This change only touches tests. test_cluster_redirect_stats.py (#582, #579): - Check the Totals Time-Serie Count, Bytes RX and Bytes TX as well as the per-command series. Dropping m_total_cmd.update_op() in update_moved_set_op() used to pass. - Delay every terminal reply from the scripted peer by 20 ms, and check Min/Average/p50 latency and each per-second Min Latency against that delay in every mode. A zero latency on a completed redirect (for example an ASK reply with retries disabled) used to pass the default-backoff cases. - Report Ops/sec == 0 as an assertion instead of letting the redirect-rate division raise ZeroDivisionError and skip the remaining cases. - Check the final errors/retries/retried_ops progress counters on the success, refused and transaction paths. cluster_transaction_test.cpp (#583, #580): - Add a two-shard test with a populated slot map. After txn_release_pin(), the next send must re-pin to the owner of the retained lookahead key. Generating the key after it used to pass. - After releasing a pin whose round key was already consumed, check that the round key and the pin are both cleared. The existing "pin and old round key released" check runs before any round key is set, so it cannot fail. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Mutation testing during the review of #582 and #583 found faults that the merged tests did not catch. This change only touches tests. test_cluster_redirect_stats.py (#582, #579): - Check the Totals Time-Serie Count, Bytes RX and Bytes TX as well as the per-command series. Dropping m_total_cmd.update_op() in update_moved_set_op() used to pass. - Delay every terminal reply from the scripted peer by 20 ms, and check Min/Average/p50 latency and each per-second Min Latency against that delay in every mode. A zero latency on a completed redirect (for example an ASK reply with retries disabled) used to pass the default-backoff cases. - Run the success mode with a 50 ms backoff too, and require each sample to cover both backoffs. Timing the reply from the last send instead of the first (m_sent_time in client::handle_response) used to pass. - Check the final errors/retries/retried_ops progress counters on the success, refused and transaction paths. The stderr progress line is the only output that carries them. cluster_transaction_test.cpp (#583, #580): - Add a two-shard test with a populated slot map. After txn_release_pin(), the next send must re-pin to the owner of the retained lookahead key. Generating the key after it used to pass. - After releasing a pin whose round key was already consumed, check that the round key and the pin are both cleared. The existing "pin and old round key released" check runs before any round key is set, so it cannot fail. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Mutation testing during the review of #582 and #583 found faults that the merged tests did not catch. This change only touches tests. test_cluster_redirect_stats.py (#582, #579): - Check the Totals Time-Serie Count, Bytes RX and Bytes TX as well as the per-command series. Dropping m_total_cmd.update_op() in update_moved_set_op() used to pass. - Delay every terminal reply from the scripted peer by 20 ms, and check Min/Average/p50 latency and each per-second Min Latency against that delay in every mode. A zero latency on a completed redirect (for example an ASK reply with retries disabled) used to pass the default-backoff cases. - Run the success mode with a 50 ms backoff too, and require each sample to cover both backoffs. Timing the reply from the last send instead of the first (m_sent_time in client::handle_response) used to pass. - Check the final errors/retries/retried_ops progress counters on the success, refused and transaction paths. The stderr progress line is the only output that carries them. cluster_transaction_test.cpp (#583, #580): - Add a two-shard test with a populated slot map. After txn_release_pin(), the next send must re-pin to the owner of the retained lookahead key. Generating the key after it used to pass. - After releasing a pin whose round key was already consumed, check that the round key and the pin are both cleared. The existing "pin and old round key released" check runs before any round key is set, so it cannot fail. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Mutation testing during the review of #582 and #583 found faults that the merged tests did not catch. This change only touches tests. test_cluster_redirect_stats.py (#582, #579): - Check the Totals Time-Serie Count, Bytes RX and Bytes TX as well as the per-command series. Dropping m_total_cmd.update_op() in update_moved_set_op() used to pass. - Delay every terminal reply from the scripted peer by 20 ms, and check Min/Average/p50 latency and each per-second Min Latency against that delay in every mode. A zero latency on a completed redirect (for example an ASK reply with retries disabled) used to pass the default-backoff cases. - Run the success mode with a 50 ms backoff too, and require each sample to cover both backoffs. Timing the reply from the last send instead of the first (m_sent_time in client::handle_response) used to pass. - Check the final errors/retries/retried_ops progress counters on the success, refused and transaction paths. The stderr progress line is the only output that carries them. cluster_transaction_test.cpp (#583, #580): - Add a two-shard test with a populated slot map. After txn_release_pin(), the next send must re-pin to the owner of the retained lookahead key. Generating the key after it used to pass. - After releasing a pin whose round key was already consumed, check that the round key and the pin are both cleared. The existing "pin and old round key released" check runs before any round key is set, so it cannot fail. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Losing a cluster transaction pin before its lookahead key was consumed put a bare key index into a queue of
(command_index, key_index)pairs. Pipelined reconnects could then interpret that key as a command index, throwvector::_M_range_check, or silently choose the wrong command for a small index.Keep the unsent key in transaction lookahead state across pin release. When choosing a replacement pin, reconstruct the same key and resolve its owner using the current topology without advancing the iterator again.
Validation:
Fixes #580.
Note
Medium Risk
Changes cluster transaction pin release and re-pin key selection in
cluster_client, which affects reconnect/MOVED paths; regression coverage is strong but the behavior is easy to get wrong.Overview
Fixes #580: when a cluster
--transactionrotation loses its pin before the lookahead key is sent, the old path pushed that key index into the per-connection routed queue. That queue is pairs of(command_index, key_index), so a lone index—especially a small one—could be treated as a command index and crash or mis-route under pipelined workloads and shard connection kills.txn_release_pin()no longer returns the staged key to the pool; it keeps the unsent lookahead inm_txn_staged_key_index/m_txn_has_staged_keyand only clears pin and round-key state. On re-pin,create_arbitrary_requestreuses that staged index viagenerate_keyinstead of callingget_key_for_connagain, so the sequential iterator is not advanced twice.Adds a deterministic
cluster_transaction_testunit harness (wired intomake check) and a cluster integration test that kills shard connections during pipelinedMULTI/SET/EXECwith multiple clients.Reviewed by Cursor Bugbot for commit 3d75433. Bugbot is set up for automated code reviews on this repo. Configure here.