-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: add RocksDB variant to EitherReader and EitherWriter #20288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
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.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merged
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.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
| /// Write to `RocksDB` | ||
| #[cfg(all(unix, feature = "rocksdb"))] | ||
| RocksDB(RocksDBProvider), |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## 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.
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
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
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