feat: add RocksDB variant to EitherReader and EitherWriter#20288
feat: add RocksDB variant to EitherReader and EitherWriter#20288
Conversation
fa993f3 to
02c1ea8
Compare
02c1ea8 to
b1571e5
Compare
| Ok(EitherReader::RocksDB(provider.rocksdb_provider())) | ||
| } else { | ||
| Ok(EitherReader::Database(provider.tx_ref().cursor_read::<tables::StoragesHistory>()?)) | ||
| } |
There was a problem hiding this comment.
will have to add in constructor for account history after
#20282
is merged in
ce435c6 to
d4daf0e
Compare
|
@Rjected might be obvious but just clarifying: we would still need implementation to add the actual operations (e.g., append, read, prune) for 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>( |
There was a problem hiding this comment.
is this what you mean by constructor? @Rjected
There was a problem hiding this comment.
yep. I think we need to make sure this fn is not gated by cfg though
There was a problem hiding this comment.
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.
| /// Write to `RocksDB` | ||
| #[cfg(all(unix, feature = "rocksdb"))] | ||
| RocksDB(RocksDBProvider), |
There was a problem hiding this comment.
we probably will want to use a rocksdb tx instead of just the provider
There was a problem hiding this comment.
I see, could u expand on why we would wanna go with tx instead? @joshieDo
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
## 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
d4daf0e to
bb2b4dc
Compare
CodSpeed Performance ReportMerging #20288 will degrade performances by 32.51%Comparing Summary
Benchmarks breakdown
Footnotes
|
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.
Use type aliases (RocksTxArg, RocksTxRefArg) to make constructors available regardless of feature flags. This allows callers to use these functions without conditional compilation.
There was a problem hiding this comment.
lgtm, once this one is merged we will need to update #20253 to:
- Remove
RocksDBAccessenum:TransactionDBdoesn't support read-only mode - Remove
RocksDBBuilder::read_only()method: cannot be implemented withTransactionDB - Remove read-only access checks in
put(),delete(),write_batch()that returnProviderError::ReadOnlyRocksDBAccess - Remove
accessfield fromRocksDBProviderInnerstruct
Rjected
left a comment
There was a problem hiding this comment.
LGTM, let's explore TransactionDB (or OptimisticTransactionDB) vs WriteBatch for read vs write in a follow up, if it makes sense
Thanks will do! |
Roger thanks for note fede @fgimenez |
Closes #20278, #20279, #20280
Add RocksDB variants to EitherReader, EitherWriter, and EitherWriterDestination enums.
This is done by switching from
DBtoTransactionDBand addRocksTxwrapper providing MDBX-like transaction semantics.Changes
DBwithTransactionDBinRocksDBProviderRocksTx<'db>wrapper withget,put,delete,iter,commit,rollbackEitherWriter/EitherReaderto useRocksTxinstead ofRocksDBProvider