-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat: move ZstdDictionary inside NippyJar and create a snapshot manager
#5139
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
Changes from all commits
5b429fa
8090431
f5762b4
8eaab06
95e0574
e03a3c0
16e4457
a6edbc4
765ea2e
1b41008
b6789e4
a900860
9ae5939
96f77fc
16c33a7
d14a483
055a818
5bef37f
a66b603
f327d91
5582db3
13136ed
d4c8b33
36fa32f
648d55e
bfde955
0beb01a
b4d1d1e
79c72db
8880d6f
6224354
8e56d1d
4fb1871
9ab6333
c562e0c
27d6ab2
21edb80
3a385ec
2f8d303
3631dec
f2768f3
47e0036
e5e71be
d7c01b2
e920318
5fd1124
30c4748
efeb602
7dab55d
888e123
8f9cbdb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| use crate::{BlockNumber, TxNumber}; | ||
| use crate::{snapshot::PerfectHashingFunction, BlockNumber, TxNumber}; | ||
| use serde::{Deserialize, Serialize}; | ||
| use std::ops::RangeInclusive; | ||
| use std::{ops::RangeInclusive, path::PathBuf}; | ||
|
|
||
| use super::{Compression, Filters, InclusionFilter}; | ||
|
|
||
| #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd, Deserialize, Serialize)] | ||
| #[cfg_attr(feature = "clap", derive(clap::ValueEnum))] | ||
|
|
@@ -14,8 +16,70 @@ pub enum SnapshotSegment { | |
| Receipts, | ||
| } | ||
|
|
||
| impl SnapshotSegment { | ||
| /// Returns the default configuration of the segment. | ||
| const fn config(&self) -> (Filters, Compression) { | ||
| let default_config = ( | ||
| Filters::WithFilters(InclusionFilter::Cuckoo, super::PerfectHashingFunction::Fmph), | ||
| Compression::Lz4, | ||
| ); | ||
|
|
||
| match self { | ||
| SnapshotSegment::Headers => default_config, | ||
| SnapshotSegment::Transactions => default_config, | ||
| SnapshotSegment::Receipts => default_config, | ||
| } | ||
| } | ||
|
|
||
| /// Returns the default file name for the provided segment and range. | ||
| pub fn filename(&self, range: &RangeInclusive<BlockNumber>) -> PathBuf { | ||
| let (filters, compression) = self.config(); | ||
| self.filename_with_configuration(filters, compression, range) | ||
| } | ||
|
|
||
| /// Returns file name for the provided segment, filters, compression and range. | ||
| pub fn filename_with_configuration( | ||
| &self, | ||
| filters: Filters, | ||
| compression: Compression, | ||
| range: &RangeInclusive<BlockNumber>, | ||
|
Collaborator
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. does this work with something like
Collaborator
Author
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. it requires a ref. would you rather it be an object and not a ref? |
||
| ) -> PathBuf { | ||
| let segment_name = match self { | ||
| SnapshotSegment::Headers => "headers", | ||
| SnapshotSegment::Transactions => "transactions", | ||
| SnapshotSegment::Receipts => "receipts", | ||
| }; | ||
| let filters_name = match filters { | ||
| Filters::WithFilters(inclusion_filter, phf) => { | ||
| let inclusion_filter = match inclusion_filter { | ||
| InclusionFilter::Cuckoo => "cuckoo", | ||
| }; | ||
| let phf = match phf { | ||
| PerfectHashingFunction::Fmph => "fmph", | ||
| PerfectHashingFunction::GoFmph => "gofmph", | ||
| }; | ||
| format!("{inclusion_filter}-{phf}") | ||
| } | ||
| Filters::WithoutFilters => "none".to_string(), | ||
| }; | ||
| let compression_name = match compression { | ||
| Compression::Lz4 => "lz4", | ||
| Compression::Zstd => "zstd", | ||
| Compression::ZstdWithDictionary => "zstd-dict", | ||
| Compression::Uncompressed => "uncompressed", | ||
| }; | ||
|
|
||
| format!( | ||
| "snapshot_{segment_name}_{}_{}_{filters_name}_{compression_name}", | ||
| range.start(), | ||
| range.end(), | ||
| ) | ||
| .into() | ||
| } | ||
| } | ||
|
|
||
| /// A segment header that contains information common to all segments. Used for storage. | ||
| #[derive(Debug, Serialize, Deserialize)] | ||
| #[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Hash)] | ||
| pub struct SegmentHeader { | ||
| block_range: RangeInclusive<BlockNumber>, | ||
| tx_range: RangeInclusive<TxNumber>, | ||
|
|
||
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.
nit: I think we can avoid cloning by initializing
pathfirst, and then passingblock_rangeby value intotransaction_range_by_block_range