Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
5b429fa
move tx_lookup hash calculation to db crate
joshieDo Oct 6, 2023
8090431
update doc on tx hash calc
joshieDo Oct 6, 2023
f5762b4
Merge remote-tracking branch 'origin/main' into joshie/snapshot-bin-2
joshieDo Oct 12, 2023
8eaab06
use databaseprovider instead
joshieDo Oct 12, 2023
95e0574
add find_transaction_range
joshieDo Oct 12, 2023
e03a3c0
cargo deps
joshieDo Oct 12, 2023
16e4457
add TransactionsProviderExt
joshieDo Oct 12, 2023
a6edbc4
add transactions snapshot segment
joshieDo Oct 12, 2023
765ea2e
snapshot benches compare results
joshieDo Oct 12, 2023
1b41008
add TransactionNotFound error
joshieDo Oct 12, 2023
b6789e4
add additional empty provider impls to SnapshotProvider
joshieDo Oct 12, 2023
a900860
add SegmentHeader to snapshot jars
joshieDo Oct 13, 2023
9ae5939
add wip transaction_by_hash
joshieDo Oct 13, 2023
96f77fc
fix doc test
joshieDo Oct 13, 2023
16c33a7
fmt
joshieDo Oct 13, 2023
d14a483
add with_hash to walk bench as well
joshieDo Oct 13, 2023
055a818
fix recover_hashes range
joshieDo Oct 13, 2023
5bef37f
Merge remote-tracking branch 'origin/main' into joshie/snapshot-bin-2
joshieDo Oct 16, 2023
a66b603
fix doc test
joshieDo Oct 16, 2023
f327d91
fix test_snap
joshieDo Oct 16, 2023
5582db3
share dataset_for_compression implementation
joshieDo Oct 16, 2023
13136ed
add snapshot segment
joshieDo Oct 16, 2023
d4c8b33
add receipts command
joshieDo Oct 16, 2023
36fa32f
Merge remote-tracking branch 'origin/main' into joshie/snapshot-bin-2
joshieDo Oct 19, 2023
648d55e
move dictionaries inside NippyJar
joshieDo Oct 21, 2023
bfde955
introduce snapshotjarprovider and dashmap
joshieDo Oct 23, 2023
0beb01a
docs
joshieDo Oct 23, 2023
b4d1d1e
Update bin/reth/src/db/snapshots/receipts.rs
joshieDo Oct 24, 2023
79c72db
Update bin/reth/src/db/snapshots/transactions.rs
joshieDo Oct 24, 2023
8880d6f
Update bin/reth/src/db/snapshots/transactions.rs
joshieDo Oct 24, 2023
6224354
Update bin/reth/src/db/snapshots/receipts.rs
joshieDo Oct 24, 2023
8e56d1d
Update crates/interfaces/src/provider.rs
joshieDo Oct 24, 2023
4fb1871
add transaction_hashes_by_range to provider
joshieDo Oct 24, 2023
9ab6333
add TxHashOrNumber type
joshieDo Oct 24, 2023
c562e0c
Update bin/reth/src/db/snapshots/receipts.rs
joshieDo Oct 24, 2023
27d6ab2
Update bin/reth/src/db/snapshots/transactions.rs
joshieDo Oct 24, 2023
21edb80
Merge remote-tracking branch 'origin/main' into joshie/snapshot-bin-2
joshieDo Oct 24, 2023
3a385ec
Merge branch 'joshie/snapshot-bin-2' into joshie/sprov
joshieDo Oct 24, 2023
2f8d303
clippy
joshieDo Oct 24, 2023
3631dec
Merge branch 'joshie/snapshot-bin-2' into joshie/sprov
joshieDo Oct 24, 2023
f2768f3
small fixes
joshieDo Oct 24, 2023
47e0036
add serde dictionaries
joshieDo Oct 24, 2023
e5e71be
yes clippy
joshieDo Oct 24, 2023
d7c01b2
Merge branch 'joshie/snapshot-bin-2' into joshie/sprov
joshieDo Oct 24, 2023
9cd888d
share mmap handle between snap providers
joshieDo Oct 24, 2023
ab58542
split up snapshot provider mod
joshieDo Oct 24, 2023
6bf07fd
add NippyJarCursor::with_handle
joshieDo Oct 25, 2023
e920318
fix doc
joshieDo Oct 25, 2023
5fd1124
Merge branch 'joshie/snapshot-bin-2' into joshie/sprov
joshieDo Oct 25, 2023
a5e93be
Merge branch 'joshie/sprov' into joshie/snapshot-prov-mod
joshieDo Oct 25, 2023
30c4748
Merge remote-tracking branch 'origin/main' into joshie/snapshot-bin-2
joshieDo Oct 26, 2023
efeb602
fmt
joshieDo Oct 26, 2023
7dab55d
Merge branch 'joshie/snapshot-bin-2' into joshie/sprov
joshieDo Oct 26, 2023
1ef82fa
Merge branch 'joshie/sprov' into joshie/snapshot-prov-mod
joshieDo Oct 26, 2023
2e2cabd
use AsRef Path instead
joshieDo Oct 26, 2023
888e123
Merge remote-tracking branch 'origin/main' into joshie/sprov
joshieDo Oct 26, 2023
8f9cbdb
use BLOCKS_PER_SNAPSHOT instead
joshieDo Oct 27, 2023
5e836ff
Merge branch 'joshie/sprov' into joshie/snapshot-prov-mod
joshieDo Oct 27, 2023
ad289c8
Merge remote-tracking branch 'origin/main' into joshie/snapshot-prov-mod
joshieDo Oct 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions crates/storage/nippy-jar/src/cursor.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::{
compression::{Compression, Compressors, Zstd},
InclusionFilter, NippyJar, NippyJarError, PerfectHashingFunction, RefRow,
InclusionFilter, MmapHandle, NippyJar, NippyJarError, PerfectHashingFunction, RefRow,
};
use memmap2::Mmap;
use serde::{de::Deserialize, ser::Serialize};
use std::{fs::File, ops::Range, sync::Arc};
use std::ops::Range;
use sucds::int_vectors::Access;
use zstd::bulk::Decompressor;

Expand All @@ -14,10 +13,7 @@ pub struct NippyJarCursor<'a, H = ()> {
/// [`NippyJar`] which holds most of the required configuration to read from the file.
jar: &'a NippyJar<H>,
/// Data file.
#[allow(unused)]
file_handle: Arc<File>,
/// Data file.
mmap_handle: Arc<Mmap>,
mmap_handle: MmapHandle,
/// Internal buffer to unload data to without reallocating memory on each retrieval.
internal_buffer: Vec<u8>,
/// Cursor row position.
Expand All @@ -38,16 +34,24 @@ where
H: Send + Sync + Serialize + for<'b> Deserialize<'b> + std::fmt::Debug + 'static,
{
pub fn new(jar: &'a NippyJar<H>) -> Result<Self, NippyJarError> {
let file = File::open(jar.data_path())?;

// SAFETY: File is read-only and its descriptor is kept alive as long as the mmap handle.
let mmap = unsafe { Mmap::map(&file)? };
let max_row_size = jar.max_row_size;
Ok(NippyJarCursor {
jar,
mmap_handle: jar.open_data()?,
// Makes sure that we have enough buffer capacity to decompress any row of data.
internal_buffer: Vec::with_capacity(max_row_size),
row: 0,
})
}

pub fn with_handle(
jar: &'a NippyJar<H>,
mmap_handle: MmapHandle,
) -> Result<Self, NippyJarError> {
let max_row_size = jar.max_row_size;
Ok(NippyJarCursor {
jar,
file_handle: Arc::new(file),
mmap_handle: Arc::new(mmap),
mmap_handle,
// Makes sure that we have enough buffer capacity to decompress any row of data.
internal_buffer: Vec::with_capacity(max_row_size),
row: 0,
Expand Down
36 changes: 36 additions & 0 deletions crates/storage/nippy-jar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@
#![deny(unused_must_use, rust_2018_idioms)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

use memmap2::Mmap;
use serde::{Deserialize, Serialize};
use std::{
clone::Clone,
error::Error as StdError,
fs::File,
io::{Seek, Write},
marker::Sync,
ops::Deref,
path::{Path, PathBuf},
sync::Arc,
};
use sucds::{
int_vectors::PrefixSummedEliasFano,
Expand Down Expand Up @@ -247,6 +250,11 @@ where
.join(format!("{}.idx", data_path.file_name().expect("exists").to_string_lossy()))
}

/// Returns a [`MmapHandle`] of the data file
pub fn open_data(&self) -> Result<MmapHandle, NippyJarError> {
MmapHandle::new(self.data_path())
}

/// If required, prepares any compression algorithm to an early pass of the data.
pub fn prepare_compression(
&mut self,
Expand Down Expand Up @@ -487,6 +495,34 @@ where
}
}

/// Holds an `Arc` over a file and its associated mmap handle.
#[derive(Debug, Clone)]
pub struct MmapHandle {
/// File descriptor. Needs to be kept alive as long as the mmap handle.
#[allow(unused)]
file: Arc<File>,
/// Mmap handle.
mmap: Arc<Mmap>,
}

impl MmapHandle {
pub fn new(path: impl AsRef<Path>) -> Result<Self, NippyJarError> {
let file = File::open(path)?;

// SAFETY: File is read-only and its descriptor is kept alive as long as the mmap handle.
let mmap = unsafe { Mmap::map(&file)? };

Ok(Self { file: Arc::new(file), mmap: Arc::new(mmap) })
}
}

impl Deref for MmapHandle {
type Target = Mmap;
fn deref(&self) -> &Self::Target {
&self.mmap
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Loading