-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat: add rocksdb to save_blocks
#21003
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
cf89d57
parallelize save_blocks
joshieDo ad4998d
rm Tx: Sync bound
joshieDo 55e0f3d
touch-ups
joshieDo 40ea593
fix
joshieDo fadc97a
feat: enable account changesets on `save_blocks` (#21012)
joshieDo c2ddcb2
Merge branch 'main' into joshie/par-save-blocks
joshieDo 84bdf71
feat(storage): add tracing spans (#21072)
pepyakin d8a600c
add rocksdb writer to save_blocks
joshieDo 698e224
add get/set db settings for rocksdb
joshieDo 8e8e6b7
fix rocksdb metrics
joshieDo 48a2877
Merge remote-tracking branch 'origin/main' into joshie/par-save-block…
joshieDo 66e528c
simplify save_blocks rocksdb portion
joshieDo 8776d73
remove stub unused stuff
joshieDo d6781e3
add missing method
joshieDo 3ff440a
clippy
joshieDo d3358f7
fixes
joshieDo c94927f
more clippy
joshieDo 63669fa
chore: simplify LogLevel import in rocksdb_stub
yongkangc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ use crate::{ | |
| }, | ||
| providers::{ | ||
| database::{chain::ChainStorage, metrics}, | ||
| rocksdb::RocksDBProvider, | ||
| rocksdb::{PendingRocksDBBatches, RocksDBProvider, RocksDBWriteCtx}, | ||
| static_file::{StaticFileWriteCtx, StaticFileWriter}, | ||
| NodeTypesForProvider, StaticFileProvider, | ||
| }, | ||
|
|
@@ -188,8 +188,8 @@ pub struct DatabaseProvider<TX, N: NodeTypes> { | |
| /// `RocksDB` provider | ||
| rocksdb_provider: RocksDBProvider, | ||
| /// Pending `RocksDB` batches to be committed at provider commit time. | ||
| #[cfg(all(unix, feature = "rocksdb"))] | ||
| pending_rocksdb_batches: parking_lot::Mutex<Vec<rocksdb::WriteBatchWithTransaction<true>>>, | ||
| #[cfg_attr(not(all(unix, feature = "rocksdb")), allow(dead_code))] | ||
| pending_rocksdb_batches: PendingRocksDBBatches, | ||
| /// Minimum distance from tip required for pruning | ||
| minimum_pruning_distance: u64, | ||
| /// Database provider metrics | ||
|
|
@@ -205,10 +205,10 @@ impl<TX: Debug, N: NodeTypes> Debug for DatabaseProvider<TX, N> { | |
| .field("prune_modes", &self.prune_modes) | ||
| .field("storage", &self.storage) | ||
| .field("storage_settings", &self.storage_settings) | ||
| .field("rocksdb_provider", &self.rocksdb_provider); | ||
| #[cfg(all(unix, feature = "rocksdb"))] | ||
| s.field("pending_rocksdb_batches", &"<pending batches>"); | ||
| s.field("minimum_pruning_distance", &self.minimum_pruning_distance).finish() | ||
| .field("rocksdb_provider", &self.rocksdb_provider) | ||
| .field("pending_rocksdb_batches", &"<pending batches>") | ||
| .field("minimum_pruning_distance", &self.minimum_pruning_distance) | ||
| .finish() | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -336,8 +336,7 @@ impl<TX: DbTxMut, N: NodeTypes> DatabaseProvider<TX, N> { | |
| storage, | ||
| storage_settings, | ||
| rocksdb_provider, | ||
| #[cfg(all(unix, feature = "rocksdb"))] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we still need this feature? |
||
| pending_rocksdb_batches: parking_lot::Mutex::new(Vec::new()), | ||
| pending_rocksdb_batches: Default::default(), | ||
| minimum_pruning_distance: MINIMUM_PRUNING_DISTANCE, | ||
| metrics: metrics::DatabaseProviderMetrics::default(), | ||
| } | ||
|
|
@@ -403,6 +402,17 @@ impl<TX: DbTx + DbTxMut + 'static, N: NodeTypesForProvider> DatabaseProvider<TX, | |
| }) | ||
| } | ||
|
|
||
| /// Creates the context for `RocksDB` writes. | ||
| #[cfg_attr(not(all(unix, feature = "rocksdb")), allow(dead_code))] | ||
| fn rocksdb_write_ctx(&self, first_block: BlockNumber) -> RocksDBWriteCtx { | ||
| RocksDBWriteCtx { | ||
| first_block_number: first_block, | ||
| prune_tx_lookup: self.prune_modes.transaction_lookup, | ||
| storage_settings: self.cached_storage_settings(), | ||
| pending_batches: self.pending_rocksdb_batches.clone(), | ||
| } | ||
| } | ||
|
|
||
| /// Writes executed blocks and state to storage. | ||
| /// | ||
| /// This method parallelizes static file (SF) writes with MDBX writes. | ||
|
|
@@ -452,6 +462,10 @@ impl<TX: DbTx + DbTxMut + 'static, N: NodeTypesForProvider> DatabaseProvider<TX, | |
| // avoid capturing &self.tx in scope below. | ||
| let sf_provider = &self.static_file_provider; | ||
| let sf_ctx = self.static_file_write_ctx(save_mode, first_number, last_block_number)?; | ||
| #[cfg(all(unix, feature = "rocksdb"))] | ||
| let rocksdb_provider = self.rocksdb_provider.clone(); | ||
| #[cfg(all(unix, feature = "rocksdb"))] | ||
| let rocksdb_ctx = self.rocksdb_write_ctx(first_number); | ||
|
|
||
| thread::scope(|s| { | ||
| // SF writes | ||
|
|
@@ -461,6 +475,16 @@ impl<TX: DbTx + DbTxMut + 'static, N: NodeTypesForProvider> DatabaseProvider<TX, | |
| Ok::<_, ProviderError>(start.elapsed()) | ||
| }); | ||
|
|
||
| // RocksDB writes | ||
| #[cfg(all(unix, feature = "rocksdb"))] | ||
| let rocksdb_handle = rocksdb_ctx.storage_settings.any_in_rocksdb().then(|| { | ||
| s.spawn(|| { | ||
| let start = Instant::now(); | ||
| rocksdb_provider.write_blocks_data(&blocks, &tx_nums, rocksdb_ctx)?; | ||
| Ok::<_, ProviderError>(start.elapsed()) | ||
| }) | ||
| }); | ||
|
|
||
| // MDBX writes | ||
| let mdbx_start = Instant::now(); | ||
|
|
||
|
|
@@ -557,6 +581,12 @@ impl<TX: DbTx + DbTxMut + 'static, N: NodeTypesForProvider> DatabaseProvider<TX, | |
| .join() | ||
| .map_err(|_| StaticFileWriterError::ThreadPanic("static file"))??; | ||
|
|
||
| // Wait for RocksDB thread | ||
| #[cfg(all(unix, feature = "rocksdb"))] | ||
| if let Some(handle) = rocksdb_handle { | ||
| timings.rocksdb = handle.join().expect("RocksDB thread panicked")?; | ||
| } | ||
|
|
||
| timings.total = total_start.elapsed(); | ||
|
|
||
| self.metrics.record_save_blocks(&timings); | ||
|
|
@@ -821,8 +851,7 @@ impl<TX: DbTx + 'static, N: NodeTypesForProvider> DatabaseProvider<TX, N> { | |
| storage, | ||
| storage_settings, | ||
| rocksdb_provider, | ||
| #[cfg(all(unix, feature = "rocksdb"))] | ||
| pending_rocksdb_batches: parking_lot::Mutex::new(Vec::new()), | ||
| pending_rocksdb_batches: Default::default(), | ||
| minimum_pruning_distance: MINIMUM_PRUNING_DISTANCE, | ||
| metrics: metrics::DatabaseProviderMetrics::default(), | ||
| } | ||
|
|
@@ -3167,14 +3196,13 @@ impl<TX: DbTxMut + DbTx + 'static, N: NodeTypes> HistoryWriter for DatabaseProvi | |
|
|
||
| #[instrument(level = "debug", target = "providers::db", skip_all)] | ||
| fn update_history_indices(&self, range: RangeInclusive<BlockNumber>) -> ProviderResult<()> { | ||
| // account history stage | ||
| { | ||
| let storage_settings = self.cached_storage_settings(); | ||
| if !storage_settings.account_history_in_rocksdb { | ||
| let indices = self.changed_accounts_and_blocks_with_range(range.clone())?; | ||
| self.insert_account_history_index(indices)?; | ||
| } | ||
|
|
||
| // storage history stage | ||
| { | ||
| if !storage_settings.storages_history_in_rocksdb { | ||
| let indices = self.changed_storages_and_blocks_with_range(range)?; | ||
| self.insert_storage_history_index(indices)?; | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
do we still need this?