Skip to content

Conversation

@yongkangc
Copy link
Member

@yongkangc yongkangc commented Dec 11, 2025

Closes #20278, #20279, #20280

Add RocksDB variants to EitherReader, EitherWriter, and EitherWriterDestination enums.

This is done by switching from DB to TransactionDB and add RocksTx wrapper providing MDBX-like transaction semantics.

Changes

  • Replace DB with TransactionDB in RocksDBProvider
  • Add RocksTx<'db> wrapper with get, put, delete, iter, commit, rollback
  • Update EitherWriter/EitherReader to use RocksTx instead of RocksDBProvider
  • Add tests for read-your-writes, rollback, and iterator behavior

@github-project-automation github-project-automation bot moved this to Backlog in Reth Tracker Dec 11, 2025
@github-actions github-actions bot added the C-enhancement New feature or request label Dec 11, 2025
@yongkangc yongkangc changed the title Add RocksDB variant to EitherReader feat: add RocksDB variant to EitherReader Dec 11, 2025
@yongkangc yongkangc added the A-db Related to the database label Dec 11, 2025
@yongkangc yongkangc self-assigned this Dec 11, 2025
@yongkangc yongkangc force-pushed the feat/either-reader-rocksdb branch from fa993f3 to 02c1ea8 Compare December 11, 2025 07:55
@yongkangc yongkangc changed the title feat: add RocksDB variant to EitherReader feat: add RocksDB routing variants and constructors for Either* types Dec 11, 2025
@yongkangc yongkangc force-pushed the feat/either-reader-rocksdb branch from 02c1ea8 to b1571e5 Compare December 11, 2025 08:12
@yongkangc yongkangc changed the title feat: add RocksDB routing variants and constructors for Either* types feat: add RocksDB variant to EitherReader and EitherWriter Dec 11, 2025
Ok(EitherReader::RocksDB(provider.rocksdb_provider()))
} else {
Ok(EitherReader::Database(provider.tx_ref().cursor_read::<tables::StoragesHistory>()?))
}
Copy link
Member Author

Choose a reason for hiding this comment

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

will have to add in constructor for account history after
#20282

is merged in

Copy link
Member

Choose a reason for hiding this comment

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

merged

@yongkangc yongkangc force-pushed the feat/either-reader-rocksdb branch 2 times, most recently from ce435c6 to d4daf0e Compare December 11, 2025 08:41
@yongkangc yongkangc marked this pull request as ready for review December 11, 2025 08:43
@yongkangc yongkangc requested review from Rjected and mattsse December 11, 2025 08:43
@yongkangc
Copy link
Member Author

yongkangc commented Dec 11, 2025

@Rjected might be obvious but just clarifying: we would still need implementation to add the actual operations (e.g., append, read, prune) for StoragesHistory and TransactionHashNumbers when using the RocksDB variant.

That hasn't been added for this pr.


/// Creates a new [`EitherWriter`] for transaction hash numbers based on storage settings.
#[cfg(all(unix, feature = "rocksdb"))]
pub fn new_transaction_hash_numbers<P>(
Copy link
Member Author

Choose a reason for hiding this comment

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

is this what you mean by constructor? @Rjected

Copy link
Member

Choose a reason for hiding this comment

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

yep. I think we need to make sure this fn is not gated by cfg though

Copy link
Member Author

Choose a reason for hiding this comment

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

Done! Introduced type aliases (RocksTxArg, RocksTxRefArg) that resolve to RocksTx<'a> or &'a RocksTx<'a> when rocksdb is enabled, and () when disabled. The constructors are now always available - internal cfg blocks handle the routing.

Comment on lines 46 to 48
/// Write to `RocksDB`
#[cfg(all(unix, feature = "rocksdb"))]
RocksDB(RocksDBProvider),
Copy link
Collaborator

@joshieDo joshieDo Dec 11, 2025

Choose a reason for hiding this comment

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

we probably will want to use a rocksdb tx instead of just the provider

Copy link
Member Author

Choose a reason for hiding this comment

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

I see, could u expand on why we would wanna go with tx instead? @joshieDo

Copy link
Member Author

@yongkangc yongkangc Dec 11, 2025

Choose a reason for hiding this comment

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

ideally we should explicitly control with DatabaseProvider::commit when we actually commit to disk and in what order. with an txn we can roll back and commit but not with a provider. this breaks API compatibility in terms of rollback which might be necessary for some parts

Copy link
Member

Choose a reason for hiding this comment

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

This PR is just for EitherReader / EitherWriter, so IMO we def want a rocksdb TX type in here. And we want to manage the tx lifecycle separately (at the provider level). I think it's fine if we use a rocksdb TX in the enums, even if this means the constructors like new_transaction_hash_numbers have to take a rocksdb TX argument that would be removed later

Copy link
Member Author

@yongkangc yongkangc Dec 12, 2025

Choose a reason for hiding this comment

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

@joshieDo @Rjected made changes from DB to TransactionDB and added RocksTx wrapper.

This gives us the similar tx semantics as MDBX (read-your-writes, explicit commit/rollback, iterators seeing uncommitted writes). Let me know if that aligns with the design we should aim for.

## Problem
Either* types needed RocksDB support for routing data to RocksDB-backed
tables based on StorageSettings flags.

## Solution
Add RocksDB variants and constructors to EitherReader, EitherWriter,
and EitherWriterDestination enums.

## Changes
- Add `EitherWriterDestination::RocksDB` variant
- Add `EitherWriter::RocksDB` variant with constructors (cfg-gated):
  - `new_storages_history()`, `new_transaction_hash_numbers()`
- Add `EitherReader::RocksDB` variant with constructors (cfg-gated):
  - `new_storages_history()`, `new_transaction_hash_numbers()`
- Add `RocksDBProviderFactory` trait for provider access

## Expected Impact
Enables routing write-heavy index tables (StoragesHistory,
TransactionHashNumbers) to RocksDB when configured via StorageSettings.

Closes #20278, #20279, #20280
Add RocksDB variants and constructors to EitherReader, EitherWriter, and EitherWriterDestination enums.

**Changes**
- Add `EitherWriterDestination::RocksDB` variant
- Add `EitherWriter::RocksDB` variant (cfg-gated)
- Add `EitherReader::RocksDB` variant (cfg-gated)
- Add `new_storages_history()` constructor for EitherWriter/EitherReader
- Add `new_transaction_hash_numbers()` constructor for EitherWriter/EitherReader

Closes #20278, #20279, #20280
@yongkangc yongkangc force-pushed the feat/either-reader-rocksdb branch from d4daf0e to bb2b4dc Compare December 12, 2025 03:14
@codspeed-hq
Copy link

codspeed-hq bot commented Dec 12, 2025

CodSpeed Performance Report

Merging #20288 will degrade performances by 32.51%

Comparing feat/either-reader-rocksdb (e00dd37) with main (3c41b99)

Summary

❌ 1 regression
✅ 112 untouched
⏩ 4 skipped1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
prefix set | size: 10 | `Vec` with binary search lookup 3.8 µs 5.7 µs -32.51%

Footnotes

  1. 4 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Replace DB with TransactionDB to enable native transaction support with
read-your-writes, commit/rollback, and iterators seeing uncommitted data.
Add RocksTx wrapper that provides MDBX-compatible transaction API.
@yongkangc yongkangc moved this from Backlog to In Progress in Reth Tracker Dec 12, 2025
Use type aliases (RocksTxArg, RocksTxRefArg) to make constructors
available regardless of feature flags. This allows callers to use
these functions without conditional compilation.
Copy link
Member

@fgimenez fgimenez left a comment

Choose a reason for hiding this comment

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

lgtm, once this one is merged we will need to update #20253 to:

  • Remove RocksDBAccess enum: TransactionDB doesn't support read-only mode
  • Remove RocksDBBuilder::read_only() method: cannot be implemented with TransactionDB
  • Remove read-only access checks in put(), delete(), write_batch() that return ProviderError::ReadOnlyRocksDBAccess
  • Remove access field from RocksDBProviderInner struct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-db Related to the database C-enhancement New feature or request

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

Add RocksDB variant to EitherReader

5 participants