Skip to content

feat: move ZstdDictionary inside NippyJar and create a snapshot manager#5139

Merged
joshieDo merged 51 commits intomainfrom
joshie/sprov
Oct 27, 2023
Merged

feat: move ZstdDictionary inside NippyJar and create a snapshot manager#5139
joshieDo merged 51 commits intomainfrom
joshie/sprov

Conversation

@joshieDo
Copy link
Collaborator

@joshieDo joshieDo commented Oct 23, 2023

  • Moves ZstdDictionary inside a loaded NippyJar.
    • Furthermore, I tried structuring it in such a way that we could share a ZstdDecompressor by using a reference from the ZstdDictionary, without having to recreate the decompressor over and over. Not quite successful (ffi C reference, self-referential structs), might give it another go (with 'static) in another time, but i feel like I spent too much time on it already.
  • SnapshotProvider basically becomes a snapshot manager which creates/loads SnapshotJarProvider by reference.
    • If the NippyJar has been loaded once, it just gives a reference (using dashmap for the concurrent access map, but maybe rolling out its own arc<hashmap<key, rwlock>> might be better?
  • Moved a few things to SnapshotSegments to make it easily usable. (wrt config and filenames)

@joshieDo joshieDo added C-enhancement New feature or request A-static-files Related to static files labels Oct 23, 2023
@joshieDo joshieDo requested review from mattsse and shekhirin October 23, 2023 13:36
Base automatically changed from joshie/snapshot-bin-2 to main October 26, 2023 12:11
@github-actions github-actions bot requested a review from rkrasiuk as a code owner October 26, 2023 12:11
@codecov
Copy link

codecov bot commented Oct 26, 2023

Codecov Report

Merging #5139 (f2768f3) into main (4dc15c3) will decrease coverage by 0.26%.
Report is 23 commits behind head on main.
The diff coverage is 0.00%.

❗ Current head f2768f3 differs from pull request most recent head 8f9cbdb. Consider uploading reports for the commit 8f9cbdb to get more accurate results

Impacted file tree graph

Files Coverage Δ
crates/interfaces/src/provider.rs 0.00% <ø> (ø)
crates/primitives/src/transaction/mod.rs 36.75% <ø> (ø)
crates/storage/codecs/src/lib.rs 36.77% <ø> (ø)
crates/storage/nippy-jar/src/error.rs 0.00% <ø> (ø)
crates/storage/provider/src/providers/mod.rs 26.92% <ø> (ø)
crates/stages/src/stages/tx_lookup.rs 2.38% <0.00%> (+0.20%) ⬆️
crates/storage/db/src/snapshot.rs 0.00% <0.00%> (ø)
bin/reth/src/db/snapshots/bench.rs 0.00% <0.00%> (ø)
bin/reth/src/db/snapshots/headers.rs 0.00% <0.00%> (ø)
crates/storage/provider/src/traits/transactions.rs 0.00% <0.00%> (ø)
... and 13 more

... and 9 files with indirect coverage changes

Flag Coverage Δ
integration-tests 25.81% <0.00%> (-0.26%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
reth binary 24.84% <0.00%> (-0.94%) ⬇️
blockchain tree 28.46% <ø> (ø)
pipeline 5.07% <0.00%> (+0.02%) ⬆️
storage (db) 29.08% <0.00%> (-0.90%) ⬇️
trie 22.53% <ø> (ø)
txpool 41.11% <ø> (-0.26%) ⬇️
networking 30.89% <ø> (ø)
rpc 26.21% <ø> (-0.27%) ⬇️
consensus 25.06% <ø> (ø)
revm 9.85% <ø> (ø)
payload builder 14.16% <ø> (ø)
primitives 29.03% <0.00%> (-0.15%) ⬇️

Comment on lines 59 to +69
let tx_range = ProviderFactory::new(open_db_read_only(db_path, log_level)?, chain.clone())
.provider()?
.transaction_range_by_block_range(block_range)?;
.transaction_range_by_block_range(block_range.clone())?;

let mut row_indexes = tx_range.clone().collect::<Vec<_>>();

let (provider, decompressors) = self.prepare_jar_provider(&mut jar, &mut dictionaries)?;
let mut cursor = if !decompressors.is_empty() {
provider.cursor_with_decompressors(decompressors)
} else {
provider.cursor()
};
let path = SnapshotSegment::Receipts.filename_with_configuration(
filters,
compression,
&block_range,
);
Copy link
Member

Choose a reason for hiding this comment

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

nit: I think we can avoid cloning by initializing path first, and then passing block_range by value into transaction_range_by_block_range

pub struct SnapshotProvider {
/// Maintains a map which allows for concurrent access to different `NippyJars`, over different
/// segments and ranges.
map: DashMap<(BlockNumber, SnapshotSegment), NippyJar<SegmentHeader>>,
Copy link
Member

Choose a reason for hiding this comment

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

nit: I think it will be more intuitive to have a block range as a key, because currently this key means a snapshot for key..key+SNAPSHOT_BLOCK_NUMBER_CHUNKS

Copy link
Member

@shekhirin shekhirin left a comment

Choose a reason for hiding this comment

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

A few nits, otherwise LGTM! Code looks clean

@joshieDo joshieDo enabled auto-merge October 27, 2023 09:57
@joshieDo joshieDo added this pull request to the merge queue Oct 27, 2023
Merged via the queue into main with commit 006259b Oct 27, 2023
@joshieDo joshieDo deleted the joshie/sprov branch October 27, 2023 10:16
mattsse pushed a commit that referenced this pull request Nov 8, 2023
…anager (#5139)

Co-authored-by: Alexey Shekhirin <a.shekhirin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-static-files Related to static files C-enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants