Skip to content

feat(transaction): allow --pipeline > 1 with --transaction - #400

Merged
fcostaoliveira merged 3 commits into
redis:masterfrom
filipecosta90:feat/transaction-pipeline
May 29, 2026
Merged

fcostaoliveira merged 3 commits into
redis:masterfrom
filipecosta90:feat/transaction-pipeline

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented May 28, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

--transaction previously rejected --pipeline > 1 at startup whenever a MULTI/EXEC/WATCH/DISCARD/UNWATCH command was present, on the assumption that depth > 1 would interleave MULTI/EXEC blocks on the pinned connection. In practice it does not. The per-rotation pin holds for the entire rotation and advance_arbitrary_command_index() advances strictly, so EXEC is always emitted before the next MULTI — each rotation is sent contiguously on its pinned connection at any pipeline depth, and multiple whole transactions can be in flight (across the shards their keys map to) without interleaving.

This PR removes the guard, updates the --transaction help text, and adds tests.

Verification (3-node OSS cluster)

  • redis MONITOR at --pipeline=8 → clean MULTI / INCR cnt / EXEC / MULTI / INCR cnt / EXEC … stream, no nesting, no interleaving.
  • Commit correctness: a fixed-key counter incremented inside MULTI/EXEC commits exactly 50 at --pipeline 1, 2, 4 and 8 — no lost or double-counted transactions.
  • WATCH: WATCH/GET/MULTI/SET/EXEC/UNWATCH at --pipeline=8 runs with zero server-side transaction errors.
  • Throughput scales ~9x from pipeline 1 to 8.
  • Standalone (--transaction is a no-op there) is unaffected — single connection already serializes in order.

Note for reviewers

The original guard (#390) was added defensively; this PR is backed by empirical evidence (MONITOR + commit-count parity) that the existing per-rotation-pin already keeps transactions intact under pipelining. The one nuance — WATCH under multi-client contention will show more aborted EXECs — is correct optimistic-concurrency behavior, not a regression.

Test plan

  • tests/test_transaction_pipeline.py (OSS-CLUSTER): no transaction-breakage at --pipeline=8; commit-count parity between pipeline 1 and 8; minimal MULTI/SET/INCR/EXEC at pipeline 4.
  • Standalone suites unaffected: test_cluster_transaction.py passes.

🤖 Generated with Claude Code


Note

Medium Risk
Changes cluster transaction routing and MOVED/ASK pin semantics under pipelining; mitigated by new integration tests but mid-topology redirect paths are not exercised in CI.

Overview
Allows --pipeline > 1 with --transaction in cluster mode by removing the startup check that blocked MULTI/EXEC/WATCH-style command lists when pipeline depth exceeded 1, and updating --transaction help to describe contiguous per-rotation sends and multiple in-flight whole transactions.

Tightens cluster redirect handling in cluster_client.cpp for --transaction: on MOVED/ASK, the pin is released and sibling connections refilled only when the error is on the current pin connection; errors on stale (non-pin) connections drop the command and leave the active pin alone—important when several pipelined rotations overlap.

Adds tests/test_transaction_pipeline.py (OSS cluster): no transaction-breakage stderr at high pipeline, commit-count parity between pipeline 1 and 8, and exact {mx}-counter after MULTI/SET/INCR/EXEC at pipeline 4.

Reviewed by Cursor Bugbot for commit 373d1ac. Bugbot is set up for automated code reviews on this repo. Configure here.

The startup guard rejected --transaction + --pipeline > 1 whenever a
MULTI/EXEC/WATCH/DISCARD/UNWATCH command was present, on the assumption that
depth > 1 would interleave MULTI/EXEC blocks on the pinned connection. In
practice it does not: the per-rotation pin holds for the entire rotation and
advance_arbitrary_command_index() advances strictly, so EXEC is always emitted
before the next MULTI. Each rotation is therefore sent contiguously on its
pinned connection at any pipeline depth, and multiple whole transactions can be
in flight (across the shards their keys map to) without interleaving.

Verified on a 3-node OSS cluster:
- redis MONITOR at --pipeline=8 shows a clean MULTI/INCR/EXEC/MULTI/... stream
  with no nesting.
- A fixed-key counter incremented inside MULTI/EXEC commits the exact same
  value (50) at --pipeline 1, 2, 4 and 8 — no lost or double-counted
  transactions.
- WATCH/GET/MULTI/SET/EXEC/UNWATCH at --pipeline=8 runs with zero server-side
  transaction errors.
- Throughput scales ~9x from pipeline 1 to 8.

Remove the guard and update the --transaction help text. Add
tests/test_transaction_pipeline.py covering no-breakage at depth and
commit-count parity between pipeline=1 and pipeline=8.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
paulorsousa
paulorsousa previously approved these changes May 28, 2026
…line > 1

Code review found that the MOVED/ASK transaction handling only dropped the
redirected command (instead of retrying it on the new owner, which would split
the MULTI/EXEC block across connections) when the redirect arrived on the
*current* pin connection. At --pipeline > 1 a later rotation may already hold
the pin on a different connection while an earlier rotation's command gets a
MOVED on a now-stale connection — that fell through to the retry path and split
the block.

Fix: in --transaction mode always drop the redirected command (never retry it
elsewhere), and reset the pin only when the redirect is on the current pin so a
concurrent in-flight rotation on another connection isn't disturbed. Behavior
at --pipeline=1 is unchanged (conn_id always equals the pin there).

Also strengthen tests/test_transaction_pipeline.py: the no-breakage and minimal
MULTI/SET/INCR/EXEC tests now assert committed side effects (cluster DBSIZE > 0
and {mx}-counter > 0) so a silently-dropped transaction with no stderr error
cannot pass.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…erage

Second review round follow-ups:
- Tighten the minimal MULTI/SET/INCR/EXEC test: assert the shared {mx}-counter
  equals the exact number of committed rotations (800) instead of just > 0, so
  a dropped/duplicated/split transaction moves it off the expected value.
- Document in the module docstring that the MOVED/ASK redirect-drop path is not
  exercised by these static-topology tests (inducing a mid-rotation slot
  migration is inherently flaky in this harness); it is validated by review and
  accounting reasoning.
- Add a --debug log line when a MOVED/ASK is dropped on a stale (non-pin)
  connection at --pipeline > 1, making that otherwise-silent path observable.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@fcostaoliveira
fcostaoliveira merged commit f411e19 into redis:master May 29, 2026
65 checks passed
@fcostaoliveira fcostaoliveira added this to the 2.4 milestone Jun 1, 2026
fcostaoliveira added a commit that referenced this pull request Jun 2, 2026
…sed (#448)

2.4 regression flagged by micro-bench: ~4% ops/sec drop on canonical
SET/GET vs 2.3.1. Root cause: bufferevent_enable at the top of
fill_pipeline was added in #390/#400 to recover from --transaction's
hold_pipeline disable, but it fires every fill_pipeline invocation
(per response received) -- taking libevent's BEV_LOCK in the hot
path even when no pause/resume is needed.

Track pause state with bool m_bev_paused; only call bufferevent_enable
when the flag indicates the bufferevent was actually paused. Set the
flag at the disable site, clear it at the existing enable sites
(handle_event, schedule_fill, fill_pipeline's resume branch) and on
bev (re)creation/teardown (setup_event, disconnect). Invariant:
m_bev_paused == true iff bufferevent is in EV_READ|EV_WRITE disabled.

Local micro-bench: server-bound runs against a single localhost Redis
on this box stay within noise (~+0.3% on pipeline=32 clients=50
threads=4 ratio=1:1 300K reqs, 3 runs each) because Redis is the
bottleneck. Forcing the client to be the bottleneck (taskset -c 0,1
clients=100 threads=2 pipeline=32 ratio=1:1 200K reqs, 3 runs each)
shows +12.81% ops/sec recovery (322,237 -> 363,517). Functional
parity verified with --transaction MULTI/SET/EXEC against a manual
3-node cluster (1:1:1 Multis:Sets:Execs ratio, no errors).

Refs: 2.4 review #28 (Review 18 MED finding).

Co-authored-by: Claude Sonnet 4.6 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Jun 2, 2026
…sed (#448)

2.4 regression flagged by micro-bench: ~4% ops/sec drop on canonical
SET/GET vs 2.3.1. Root cause: bufferevent_enable at the top of
fill_pipeline was added in #390/#400 to recover from --transaction's
hold_pipeline disable, but it fires every fill_pipeline invocation
(per response received) -- taking libevent's BEV_LOCK in the hot
path even when no pause/resume is needed.

Track pause state with bool m_bev_paused; only call bufferevent_enable
when the flag indicates the bufferevent was actually paused. Set the
flag at the disable site, clear it at the existing enable sites
(handle_event, schedule_fill, fill_pipeline's resume branch) and on
bev (re)creation/teardown (setup_event, disconnect). Invariant:
m_bev_paused == true iff bufferevent is in EV_READ|EV_WRITE disabled.

Local micro-bench: server-bound runs against a single localhost Redis
on this box stay within noise (~+0.3% on pipeline=32 clients=50
threads=4 ratio=1:1 300K reqs, 3 runs each) because Redis is the
bottleneck. Forcing the client to be the bottleneck (taskset -c 0,1
clients=100 threads=2 pipeline=32 ratio=1:1 200K reqs, 3 runs each)
shows +12.81% ops/sec recovery (322,237 -> 363,517). Functional
parity verified with --transaction MULTI/SET/EXEC against a manual
3-node cluster (1:1:1 Multis:Sets:Execs ratio, no errors).

Refs: 2.4 review #28 (Review 18 MED finding).

Co-authored-by: Claude Sonnet 4.6 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants