Repository navigation
feat: harden snapshot read transactions — refuse writes, expose lifetime, conformance-test the ReadOptions funnel - #833
Conversation
…ime, conformance-test the ReadOptions funnel Closes #832. Follow-up hardening for #831, whose primitive left three traps open for future callers. The transaction type returned by the storage layer is now a wrapper (storage Tx) around the raw RocksDB transaction, carrying the snapshot-read marker set by start_snapshot_read_transaction. The raw un-optioned accessors are private to the storage module, making the wrapper the single funnel for everything done through a transaction: 1. Read-only is enforced, not documented. Every write entry point — the immediate context's put/delete family, the batch apply (rebuild_from_writebatch), and commit — refuses a snapshot read transaction with a typed SnapshotReadOnlyTransaction error instead of leaving writes to fail nondeterministically with Busy at commit (set_snapshot arms commit-time conflict detection). Rollback stays allowed as the harmless cleanup path. 2. Snapshot lifetime is observable. The marker doubles as a creation timestamp: is_snapshot_read() and snapshot_age() are exposed on the transaction (and thus on grovedb's Transaction alias), and debug builds log loudly — once per transaction — when a read executes on a snapshot held longer than one second, three orders of magnitude above the intended millisecond-scoped holds. 3. The silent-regression channel on the read funnel is closed. Both prefixed transaction contexts now read exclusively through the wrapper's get/get_cf/raw_iterator, which inject the transaction's snapshot into every read's options; a read method added later cannot reach the raw un-optioned accessors from outside the storage module. A conformance test walks every read method of the storage-context trait (get/get_aux/get_root/get_meta and every raw-iterator navigation variant) on both context types under a snapshot transaction with a commit landed after creation, asserting pre-commit visibility per method — a forgotten new method surfaces as an obvious test-extension failure. Plain transactions are byte-for-byte unaffected: their snapshot handle is null, which RocksDB documents as reading latest-committed state. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Warning Review limit reachedNext included review available in 50 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (13)
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (11)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe storage layer now wraps RocksDB transactions to enforce snapshot read-only behavior, pin reads and iterators, track snapshot age, and report typed errors. Grovedb adds documentation and tests for rejected mutations, rollback, pinned reads, and snapshot metadata. ChangesSnapshot transactions
Estimated code review effort: 4 (Complex) | ~45 minutes Merge Risk: ⚪ Minimal · up to The change hardens snapshot-read transaction behavior without any identified merge-blocking risk; it is merge-ready after normal checks and review. Sequence Diagram(s)sequenceDiagram
participant Storage as RocksDbStorage
participant Context as StorageContext
participant Tx as Tx
participant RocksDB
Storage->>Tx: create snapshot-read transaction
Storage->>Context: execute reads and iterators
Context->>Tx: request snapshot-aware reads
Tx->>RocksDB: read pinned snapshot
Storage->>Tx: attempt write or commit
Tx-->>Storage: SnapshotReadOnlyTransaction
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #833 +/- ##
===========================================
+ Coverage 92.48% 92.53% +0.04%
===========================================
Files 292 292
Lines 90424 90484 +60
===========================================
+ Hits 83628 83727 +99
+ Misses 6796 6757 -39
🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
The wrapper hid every raw-transaction method it did not re-export, and set_savepoint / rollback_to_savepoint were not re-exported because nothing in-tree calls them — but platform's block processing does (per-state-transition savepoints in prepare/process proposal and process_raw_state_transitions), so the wrapper as first pushed would have broken the platform build with method-not-found. Pass them through with the same policy as rollback: allowed on a snapshot read transaction, since the savepoint family only ever unwinds writes, which such a transaction cannot accumulate. rollback_to_savepoint returns the storage Error like the rest of the wrapper surface; platform's three hand-wrapped RocksDBError sites become one-line compiler-caught fixes. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Reviewed |
Closes #832. Follow-up hardening for #831 (
start_snapshot_read_transaction). None of these were holes in what shipped — both existing callers are read-only and millisecond-scoped — but the primitive's API surface left three traps for future callers. All three are closed by one mechanism.The mechanism: the transaction type is now a recognizable wrapper
Storage::Transactionfor the RocksDB backend (and therefore grovedb'sTransactionalias) is now a wrapper struct (storage::rocksdb_storage::Tx) around the raw RocksDB transaction, carrying the snapshot-read marker set at creation. The raw un-optioned accessors are private to the storage module, so the wrapper is the single funnel for everything done through a transaction. This is the "recognizable wrapper" option from the issue — no registry, no keying problem, no lookup on the hot path.1. Read-only enforced instead of documented
Every write entry point refuses a snapshot read transaction with a new typed error,
Error::SnapshotReadOnlyTransaction(&'static str)(payload names the refused operation):put/put_aux/put_root/put_meta/delete*family (refused immediately),rebuild_from_writebatch, coveringcommit_multi_context_batchand the immediate context'scommit_batch),commit/commit_transaction.Previously such writes would fail nondeterministically with
Busy/TryAgainat commit time — or worse, commit — becauseset_snapshotarms commit-time conflict detection. Now the failure is deterministic and typed.rollbackstays allowed: it is a harmless no-op there and refusing it would only complicate callers' cleanup paths. Refusals don't poison the transaction — it still serves pinned reads afterwards (pinned by test).2. Snapshot lifetime observable; loud debug warning on long holds
The read-only marker doubles as a creation timestamp:
is_snapshot_read()andsnapshot_age()are public on the transaction. Debug builds additionally log a loud warning — once per transaction — when a read executes on a snapshot held longer than 1s (three orders of magnitude above the intended millisecond-scoped holds), naming the compaction-debt failure mode. The failure mode is a loud log, not a slow node; release builds carry no check on the read path.3. Silent-regression channel on the read funnel closed
Both prefixed transaction contexts now read exclusively through the wrapper's
get/get_cf/raw_iterator, each of which injects the transaction's snapshot into that read'sReadOptions(the per-contextread_options()helpers are gone). A read method added later cannot reach the raw un-optioned accessors from outside the storage module, so it cannot silently revert to latest-committed reads.A conformance test walks every read method of the storage-context trait —
get,get_aux,get_root,get_meta, and every raw-iterator navigation variant (seek_to_first/forward,seek_to_last/backward,seek,seek_for_prev) — on both context types under a snapshot transaction with a commit landed after creation (overwrite + insert + delete in every column family), asserting pre-commit visibility per method, with a plain-transaction control asserting post-commit visibility. A forgotten new read method surfaces as an obvious test-extension failure.Compatibility
start_transactionbehavior is unchanged.commit()/rollback()inherent methods, so existing direct call sites compile unchanged (commit()now returns the storageErrorinstead ofrocksdb::Error).Non-goal (per the issue)
The platform-side consistency asymmetry (branched
INreads snapshot-pinned; other unproved reads latest-committed per operation) is deliberate and remains documented, not extended.Testing
cargo nextest run --workspace --all-features: 5090 passed.cargo clippy --workspace --all-features -- -D warnings: clean.cargo check --workspace --all-features --all-targetsandcargo build --no-default-features --features verify -p grovedb: clean.insert/delete/commit_transactionwith reads surviving refusals; lifetime observability).🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Documentation