Skip to content

feat(transaction): break out EXEC aborts and surface live miss/abort rates - #486

Merged
fcostaoliveira merged 5 commits into
masterfrom
txn-abort-column
Jun 22, 2026
Merged

fcostaoliveira merged 5 commits into
masterfrom
txn-abort-column

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Jun 22, 2026 •

Copy link
Copy Markdown
Collaborator

Overview

Follow-up to #485. In a WATCH/MULTI/EXEC unit, EXEC returns a null array when the optimistic lock fails (a watched key changed) — a transaction abort, not a cache miss. Reporting it under "misses" conflated it with key-existence misses. This surfaces aborts as their own concept under --transaction, and fixes live miss/abort visibility in --realtime-latencies.

What changed

Under --transaction:

  • Stats table gains an Aborts/sec column (EXEC's optimistic-lock abort rate), broken out alongside the generic Misses/sec.
  • The per-command miss-rate warning for EXEC now reads abort rate instead of miss rate.
  • JSON output gains Aborts/sec for the EXEC command block and Totals.

--realtime-latencies fix (independent of --transaction):

  • The live miss % was wired to the SET/GET hit/miss counters, which stay zero in --command (arbitrary) mode — so it always printed -. It now sources misses from the arbitrary-command counters.
  • Adds a live abort % field under --transaction.

Design

Display-only reinterpretation:

  • EXEC nulls still increment the per-command miss counter, so global miss totals are unchanged; aborts are a labeled subset of misses.
  • Abort-semantics commands are detected by command type (EXEC). No new counter or reply-shape.
  • The column, JSON field, and warning wording change only under --transaction, so default arbitrary-command output is untouched (no Aborts column without the flag — verified).

Example (Execs row, heavy WATCH contention):

Type        Ops/sec   Hits/sec  Misses/sec  Aborts/sec ...
Execs      35497.97    3283.56    32214.41    32214.41 ...
warning: EXEC abort rate 90.75% above target 1.00% (1452 aborts / 1600 ops)

Live line:

... miss 90.83% (avg: 90.86%)   abort 90.83% (avg: 90.86%)

Live abort %: a note

The live abort % is a blended indicator over all arbitrary commands (same lookup denominator as the live miss %, of which aborts are a subset). The authoritative per-command abort rate is in the final table and the abort rate warning. A true per-command live rate would need the per-command committed-EXEC denominator, which isn't cheaply available in the live aggregate.

Test plan

tests/test_cluster_transaction.py (OSS-CLUSTER, 3 shards):

  • New test_transaction_abort_column_and_warning — asserts the Aborts/sec column (table + JSON for the EXEC block) and that EXEC is never reported as miss rate. Uses a hash-tag prefix + narrow key range so concurrent rotations contend and exercise the abort path on a single slot.
  • test_realtime_latencies (3 tests) pass unchanged — confirms the realtime rewiring is safe.
  • All pre-existing transaction tests still pass.

🤖 Generated with Claude Code


Note

Medium Risk
Changes arbitrary-command key generation for transactional standalone runs and several stats/output code paths; cluster mode deliberately bypasses the new client fast path, but proxy/single-endpoint transaction workloads will behave differently than before.

Overview
Extends --transaction so one full --command rotation reuses a single key for every __key__ in standalone mode (not only --cluster-mode), via cached rotation state in client::create_arbitrary_request. That keeps WATCH/MULTI/EXEC on one slot for single-endpoint sharded proxies; cluster routing still uses cluster_client.

Under --transaction, EXEC optimistic-lock failures are surfaced as aborts (display-only subset of existing miss counters): Aborts/sec in the results table and JSON, live abort % in --realtime-latencies, and threshold warnings that say abort rate for EXEC instead of miss rate. Default arbitrary-command output without --transaction is unchanged.

--realtime-latencies now drives live miss % from arbitrary-command hit/miss totals when using --command, fixing the always-- behavior from empty SET/GET counters.

Help text and validation drop the standalone “no effect / keys not collapsed” warning; tests add standalone same-key verification and cluster abort-column coverage.

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


Also in this PR: same-key-per-rotation without --cluster-mode

--transaction's same-key behavior previously only ran under --cluster-mode. Against a single endpoint fronting a sharded backend (e.g. a Redis Enterprise proxy accessed without --cluster-mode), each keyed --command still drew an independent key, so a WATCH/GET/SETEX rotation spanned multiple slots and the server rejected it with CROSSSLOT (context='within WATCH').

This lifts the per-rotation key reuse into the base client::create_arbitrary_request, so every __key__ in a rotation resolves to one key/slot in every mode. cluster_client overrides that method and keeps its own pin-aware path, so cluster behavior is unchanged.

Consequence: --transaction is no longer a no-op without --cluster-mode — it still doesn't pin (a single connection needs none) but it now collapses keys. The --help text is updated and the standalone "keys are NOT collapsed" warning (added earlier in this PR) is dropped.

New test: test_transaction_standalone_same_key_per_rotation (SET aa / APPEND bb in one MULTI/EXEC against a standalone server → every key holds aabb).

Comment thread run_stats.cpp Resolved
@jit-ci

jit-ci Bot commented Jun 22, 2026 •

Copy link
Copy Markdown

🛡️ Jit Security Scan Results

CRITICAL HIGH MEDIUM

✅ No security findings were detected in this PR


Security scan by Jit

fcostaoliveira added a commit that referenced this pull request Jun 22, 2026
The Aborts column, JSON Aborts/sec, and live abort tail are all gated on
--transaction, but the miss-rate warning relabeled EXEC to "abort rate"
whenever the command was EXEC, regardless of the flag. A default (non
--transaction) arbitrary-command run containing EXEC would then print
"abort rate" with no Aborts column, diverging from the documented contract
and from log scrapers' expectations. Gate the warning wording on
config->transaction too, so without the flag EXEC keeps "miss rate".

Reported by Cursor Bugbot on #486.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Comment thread run_stats.cpp Resolved
fcostaoliveira added a commit that referenced this pull request Jun 22, 2026
print_aborts_sec_column always iterated the arbitrary-command rows, unlike
its sibling print_missess_sec_column which also handles the SET/GET/Wait
layout. The Aborts column is only added under --transaction (which requires
--command), so the non-arbitrary branch isn't reachable today, but the
asymmetry meant the column would misalign if that gating ever changed. Guard
on print_arbitrary_commands_results() and mirror the sibling's row layout.

Reported by Cursor Bugbot on #486.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
fcostaoliveira and others added 3 commits June 22, 2026 15:04
…rates

In a WATCH/MULTI/EXEC unit, EXEC returns a null array when the optimistic
lock fails (a watched key changed) — a transaction abort, not a cache miss.
Reporting it as a "miss" conflated it with key-existence misses.

Under --transaction:
- The stats table gains an "Aborts/sec" column (EXEC's abort rate), broken
  out alongside the generic Misses/sec column.
- The miss-rate warning for EXEC now reads "abort rate" instead of "miss rate".
- JSON output gains "Aborts/sec" for the EXEC command block and Totals.

This is a display-only reinterpretation: EXEC nulls still increment the
per-command miss counter (so global miss totals are unchanged), and aborts
are a labeled subset of misses. Abort-semantics commands are detected by
command type (EXEC). No new counter or reply-shape is introduced. The column,
JSON field, and warning wording only change under --transaction, so default
arbitrary-command output is untouched.

Separately, fix --realtime-latencies in --command (arbitrary) mode: the live
"miss %" was wired to the SET/GET hit/miss counters, which stay zero for
arbitrary commands, so it always showed "-". It now sources misses from the
arbitrary-command counters, and adds a live "abort %" field under
--transaction (a blended live indicator over all arbitrary commands; the
authoritative per-command abort rate is in the final table / warning).

Test: test_transaction_abort_column_and_warning asserts the Aborts/sec column
(table + JSON) and that EXEC is never reported as "miss rate".

Co-Authored-By: Claude Opus 4.8 <[email protected]>
The Aborts column, JSON Aborts/sec, and live abort tail are all gated on
--transaction, but the miss-rate warning relabeled EXEC to "abort rate"
whenever the command was EXEC, regardless of the flag. A default (non
--transaction) arbitrary-command run containing EXEC would then print
"abort rate" with no Aborts column, diverging from the documented contract
and from log scrapers' expectations. Gate the warning wording on
config->transaction too, so without the flag EXEC keeps "miss rate".

Reported by Cursor Bugbot on #486.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
print_aborts_sec_column always iterated the arbitrary-command rows, unlike
its sibling print_missess_sec_column which also handles the SET/GET/Wait
layout. The Aborts column is only added under --transaction (which requires
--command), so the non-arbitrary branch isn't reachable today, but the
asymmetry meant the column would misalign if that gating ever changed. Guard
on print_arbitrary_commands_results() and mirror the sibling's row layout.

Reported by Cursor Bugbot on #486.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
--transaction's same-key behavior previously lived only in the --cluster-mode
path (cluster_client), so against a single endpoint that fronts a sharded,
slot-enforcing backend (e.g. a Redis Enterprise proxy accessed without
--cluster-mode) each keyed --command still drew an independent key. A
WATCH/GET/SETEX rotation then spanned multiple slots and the server rejected
it with CROSSSLOT ("within WATCH").

Lift the per-rotation key reuse into the base client::create_arbitrary_request
so every __key__ in a rotation resolves to one key (and therefore one slot) in
every mode. cluster_client overrides that method and keeps its own pin-aware
equivalent, so the cluster path is unchanged; only the non-cluster path gains
the reuse. The reuse is skipped on the data-import path (which streams a
distinct key per command) and never advances the per-iter key cursor more than
once per rotation.

--transaction is therefore no longer a no-op without --cluster-mode: it still
doesn't pin (a single connection needs no pinning) but it now collapses keys.
Update the --help text accordingly and drop the standalone "keys are NOT
collapsed" warning, which is now false.

Test: test_transaction_standalone_same_key_per_rotation runs SET aa / APPEND bb
in one MULTI/EXEC against a standalone server with bare __key__ and asserts
every key holds 'aabb' (one key per rotation). The old standalone no-op test is
renamed to reflect that it only asserts a clean run.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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 4fd88f6. Configure here.

Comment thread client.cpp Resolved
The base-client same-key reuse path added for single-endpoint --transaction
also ran in --cluster-mode: cluster_client::create_arbitrary_request delegates
to the base sender after pushing the rotation key onto m_key_index_pools, and
the new fast path regenerated the key via generate_key() without draining the
pool. The leftover pool entries then tripped the cluster pool-empty assertion
on the next rotation (the OSS-CLUSTER transaction tests failed under
ASAN/TSAN/UBSan).

Gate the base reuse on !cluster_mode. In --cluster-mode the base sender again
always goes through get_key_for_conn (popping the pool), so cluster_client's
own reuse mechanism is unchanged; the base reuse applies only to the
non-cluster path it was written for.

Reported by Cursor Bugbot on #486.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@fcostaoliveira
fcostaoliveira merged commit 2fdada0 into master Jun 22, 2026
123 checks passed
@fcostaoliveira
fcostaoliveira deleted the txn-abort-column branch June 22, 2026 21:36
fcostaoliveira added a commit that referenced this pull request Jun 22, 2026
…, #486) (#487)

* feat(transaction): reuse one key across a --command rotation in cluster mode (#485)

In --cluster-mode --transaction, every __key__ in a rotation now resolves
to the SAME key (taken from the first keyed command's --command-key-pattern),
so all keyed commands of a WATCH/MULTI/EXEC unit (e.g. WATCH/GET/SETEX) hash
to a single slot AND a single key. Previously each keyed --command generated
an independent key value; without a hash tag those keys landed in different
slots and the cluster rejected the transaction with CROSSSLOT/MOVED, and even
WITH a hash tag the WATCH guarded a different key than the SETEX wrote, making
the optimistic-lock transaction meaningless. Pinning the rotation to one shard
connection (the pre-existing --transaction behavior) fixes routing, not the
server-side single-slot requirement nor the WATCH/write key mismatch.

The first keyed command of a rotation adopts the lookahead-staged key as the
rotation key; subsequent keyed commands reuse it. The per-iter key counter
still advances exactly once per rotation. The rotation key is reset at the
rotation boundary, on mid-rotation pin loss (txn_release_pin), and on
disconnect.

Behavior change: rotations with multiple keyed commands that previously drew
distinct keys within a slot (via a hash tag) now collapse to one key. This is
cluster-mode only; in standalone --transaction remains a no-op and each keyed
command keeps its own key. The --help text and the standalone warning document
both the new behavior and the requirement that the literal text around __key__
(including any {tag}) be identical across keyed commands.

Tests: bare-__key__ no-hash-tag WATCH/GET/MULTI/SETEX/EXEC/UNWATCH asserting no
CROSSSLOT plus a committed-keys liveness floor, and a SET+APPEND rotation
asserting the value 'aabb' (proves both commands hit the same key, not just
last-write-wins).

Co-authored-by: Claude Opus 4.8 <[email protected]>

* feat(transaction): break out EXEC aborts and surface live miss/abort rates (#486)

* feat(transaction): break out EXEC aborts and surface live miss/abort rates

In a WATCH/MULTI/EXEC unit, EXEC returns a null array when the optimistic
lock fails (a watched key changed) — a transaction abort, not a cache miss.
Reporting it as a "miss" conflated it with key-existence misses.

Under --transaction:
- The stats table gains an "Aborts/sec" column (EXEC's abort rate), broken
  out alongside the generic Misses/sec column.
- The miss-rate warning for EXEC now reads "abort rate" instead of "miss rate".
- JSON output gains "Aborts/sec" for the EXEC command block and Totals.

This is a display-only reinterpretation: EXEC nulls still increment the
per-command miss counter (so global miss totals are unchanged), and aborts
are a labeled subset of misses. Abort-semantics commands are detected by
command type (EXEC). No new counter or reply-shape is introduced. The column,
JSON field, and warning wording only change under --transaction, so default
arbitrary-command output is untouched.

Separately, fix --realtime-latencies in --command (arbitrary) mode: the live
"miss %" was wired to the SET/GET hit/miss counters, which stay zero for
arbitrary commands, so it always showed "-". It now sources misses from the
arbitrary-command counters, and adds a live "abort %" field under
--transaction (a blended live indicator over all arbitrary commands; the
authoritative per-command abort rate is in the final table / warning).

Test: test_transaction_abort_column_and_warning asserts the Aborts/sec column
(table + JSON) and that EXEC is never reported as "miss rate".

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* fix(transaction): gate EXEC abort-rate warning on --transaction

The Aborts column, JSON Aborts/sec, and live abort tail are all gated on
--transaction, but the miss-rate warning relabeled EXEC to "abort rate"
whenever the command was EXEC, regardless of the flag. A default (non
--transaction) arbitrary-command run containing EXEC would then print
"abort rate" with no Aborts column, diverging from the documented contract
and from log scrapers' expectations. Gate the warning wording on
config->transaction too, so without the flag EXEC keeps "miss rate".

Reported by Cursor Bugbot on #486.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* fix(transaction): make Aborts column robust to non-arbitrary layout

print_aborts_sec_column always iterated the arbitrary-command rows, unlike
its sibling print_missess_sec_column which also handles the SET/GET/Wait
layout. The Aborts column is only added under --transaction (which requires
--command), so the non-arbitrary branch isn't reachable today, but the
asymmetry meant the column would misalign if that gating ever changed. Guard
on print_arbitrary_commands_results() and mirror the sibling's row layout.

Reported by Cursor Bugbot on #486.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* feat(transaction): enforce same-key-per-rotation in non-cluster mode too

--transaction's same-key behavior previously lived only in the --cluster-mode
path (cluster_client), so against a single endpoint that fronts a sharded,
slot-enforcing backend (e.g. a Redis Enterprise proxy accessed without
--cluster-mode) each keyed --command still drew an independent key. A
WATCH/GET/SETEX rotation then spanned multiple slots and the server rejected
it with CROSSSLOT ("within WATCH").

Lift the per-rotation key reuse into the base client::create_arbitrary_request
so every __key__ in a rotation resolves to one key (and therefore one slot) in
every mode. cluster_client overrides that method and keeps its own pin-aware
equivalent, so the cluster path is unchanged; only the non-cluster path gains
the reuse. The reuse is skipped on the data-import path (which streams a
distinct key per command) and never advances the per-iter key cursor more than
once per rotation.

--transaction is therefore no longer a no-op without --cluster-mode: it still
doesn't pin (a single connection needs no pinning) but it now collapses keys.
Update the --help text accordingly and drop the standalone "keys are NOT
collapsed" warning, which is now false.

Test: test_transaction_standalone_same_key_per_rotation runs SET aa / APPEND bb
in one MULTI/EXEC against a standalone server with bare __key__ and asserts
every key holds 'aabb' (one key per rotation). The old standalone no-op test is
renamed to reflect that it only asserts a clean run.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* fix(transaction): scope non-cluster key reuse to non-cluster mode

The base-client same-key reuse path added for single-endpoint --transaction
also ran in --cluster-mode: cluster_client::create_arbitrary_request delegates
to the base sender after pushing the rotation key onto m_key_index_pools, and
the new fast path regenerated the key via generate_key() without draining the
pool. The leftover pool entries then tripped the cluster pool-empty assertion
on the next rotation (the OSS-CLUSTER transaction tests failed under
ASAN/TSAN/UBSan).

Gate the base reuse on !cluster_mode. In --cluster-mode the base sender again
always goes through get_key_for_conn (popping the pool), so cluster_client's
own reuse mechanism is unchanged; the base reuse applies only to the
non-cluster path it was written for.

Reported by Cursor Bugbot on #486.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

---------

Co-authored-by: Claude Opus 4.8 <[email protected]>

* Release 2.4.3

---------

Co-authored-by: Claude Opus 4.8 <[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.

1 participant