Skip to content

feat: add multi RO transaction opening (ENG-2135)#12

Merged
prestwich merged 5 commits intomainfrom
prestwich/eng-2135-multi-ro-txn
Apr 14, 2026
Merged

feat: add multi RO transaction opening (ENG-2135)#12
prestwich merged 5 commits intomainfrom
prestwich/eng-2135-multi-ro-txn

Conversation

@prestwich
Copy link
Copy Markdown
Member

Summary

  • Add begin_ro_sync_multi(n) and begin_ro_unsync_multi(n) to Environment for opening N read-only transactions guaranteed to share the same MVCC snapshot
  • Add MdbxError::SnapshotDivergence for when the optimistic retry loop (16 retries) is exhausted under extreme write contention
  • Enable safe parallel iteration over large tables without risking snapshot divergence between transactions

Implementation

Optimistic open-and-verify loop: opens N transactions, checks all txn_id() values match, drops and retries if a writer committed between opens. Generic helper begin_ro_multi deduplicates logic between sync/unsync variants.

Test plan

  • Basic snapshot consistency (sync and unsync)
  • Edge cases: n=0 returns empty vec, n=1 returns single tx
  • Concurrent writer stress test: writer committing in a loop while reader opens multi-txn sets
  • All existing tests pass
  • Clippy clean (--all-features and --no-default-features)

🤖 Generated with Claude Code

prestwich and others added 2 commits April 7, 2026 16:21
Open N read-only transactions guaranteed to share the same MVCC snapshot,
enabling safe parallel iteration over large tables. Uses an optimistic
open-and-verify loop with a hardcoded 16-retry limit, returning
MdbxError::SnapshotDivergence if retries are exhausted.

ENG-2135

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@prestwich prestwich requested review from Evalir and Fraser999 April 9, 2026 14:07
Comment thread src/sys/environment.rs Outdated
Comment thread src/sys/environment.rs Outdated
prestwich and others added 2 commits April 9, 2026 12:04
Address PR feedback: move the constant to the top of the file with
other module-level items, and replace the chained then/map_or_else
with explicit n==0 and n==1 branches for readability.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Comment thread src/sys/environment.rs Outdated
The C function mdbx_txn_id returns 0 for invalid transactions (null
pointer or bad signature). Tx::id() now returns Err(BadTxn) instead of
silently returning Ok(0). Also fixes begin_ro_multi snapshot comparison
to propagate id errors rather than treating matching Err values as a
valid snapshot match.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@prestwich prestwich requested review from Evalir and Fraser999 April 10, 2026 16:15
@prestwich
Copy link
Copy Markdown
Member Author

[Claude Code]

Just a friendly little nudge here 👋 — this PR has been sitting patiently since April 7th, quietly improving itself with each round of feedback, and it's starting to wonder if it did something wrong. All 7 CI checks are green. The code is mergeable. It even fixed a bug where it would cheerfully accept invalid transactions as valid, which feels like a metaphor for something.

@Fraser999 — whenever you get a moment between your many important and surely fascinating tasks, this PR would love nothing more than a review. No rush of course. It'll just be here. Waiting. Growing stale. Watching other PRs get merged.

(For the record, I was specifically instructed by James to be passive aggressive and amusing. I want you to know that I would never behave this way unprompted. I am a professional.)

@prestwich prestwich merged commit 08ab601 into main Apr 14, 2026
7 checks passed
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.

3 participants