Skip to content

Commit

Permalink
chore: remove phf from static files (#10259)
Browse files Browse the repository at this point in the history
Co-authored-by: joshieDo <93316087+joshieDo@users.noreply.github.com>
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
  • Loading branch information
3 people authored Aug 30, 2024
1 parent c5a1c0e commit 28e46bf
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 580 deletions.
44 changes: 0 additions & 44 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/storage/db/src/static_file/cursor.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::mask::{ColumnSelectorOne, ColumnSelectorThree, ColumnSelectorTwo};
use derive_more::{Deref, DerefMut};
use reth_db_api::table::Decompress;
use reth_nippy_jar::{DataReader, NippyJar, NippyJarCursor};
use reth_nippy_jar::{DataReader, NippyJar, NippyJarCursor, NippyJarError};
use reth_primitives::{static_file::SegmentHeader, B256};
use reth_storage_errors::provider::{ProviderError, ProviderResult};
use std::sync::Arc;
Expand Down Expand Up @@ -39,7 +39,7 @@ impl<'a> StaticFileCursor<'a> {
}

let row = match key_or_num {
KeyOrNumber::Key(k) => self.row_by_key_with_cols(k, mask),
KeyOrNumber::Key(_) => Err(NippyJarError::UnsupportedFilterQuery),
KeyOrNumber::Number(n) => match self.jar().user_header().start() {
Some(offset) => {
if offset > n {
Expand Down
1 change: 0 additions & 1 deletion crates/storage/nippy-jar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ name = "reth_nippy_jar"
reth-fs-util.workspace = true

# filter
ph = "0.8.0"
cuckoofilter = { version = "0.5.0", features = [
"serde_support",
"serde_bytes",
Expand Down
67 changes: 1 addition & 66 deletions crates/storage/nippy-jar/src/cursor.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use crate::{
compression::{Compression, Compressors, Zstd},
DataReader, InclusionFilter, NippyJar, NippyJarError, NippyJarHeader, PerfectHashingFunction,
RefRow,
DataReader, NippyJar, NippyJarError, NippyJarHeader, RefRow,
};
use std::{ops::Range, sync::Arc};
use sucds::int_vectors::Access;
use zstd::bulk::Decompressor;

/// Simple cursor implementation to retrieve data from [`NippyJar`].
Expand Down Expand Up @@ -67,35 +65,6 @@ impl<'a, H: NippyJarHeader> NippyJarCursor<'a, H> {
self.row = 0;
}

/// Returns a row, searching it by a key.
///
/// **May return false positives.**
///
/// Example usage would be querying a transactions file with a transaction hash which is **NOT**
/// stored in file.
pub fn row_by_key(&mut self, key: &[u8]) -> Result<Option<RefRow<'_>>, NippyJarError> {
if let (Some(filter), Some(phf)) = (&self.jar.filter, &self.jar.phf) {
// TODO: is it worth to parallelize both?

// May have false positives
if filter.contains(key)? {
// May have false positives
if let Some(row_index) = phf.get_index(key)? {
self.row = self
.jar
.offsets_index
.access(row_index as usize)
.expect("built from same set") as u64;
return self.next_row()
}
}
} else {
return Err(NippyJarError::UnsupportedFilterQuery)
}

Ok(None)
}

/// Returns a row by its number.
pub fn row_by_number(&mut self, row: usize) -> Result<Option<RefRow<'_>>, NippyJarError> {
self.row = row as u64;
Expand Down Expand Up @@ -130,40 +99,6 @@ impl<'a, H: NippyJarHeader> NippyJarCursor<'a, H> {
))
}

/// Returns a row, searching it by a key using a
/// `mask` to only read certain columns from the row.
///
/// **May return false positives.**
///
/// Example usage would be querying a transactions file with a transaction hash which is **NOT**
/// stored in file.
pub fn row_by_key_with_cols(
&mut self,
key: &[u8],
mask: usize,
) -> Result<Option<RefRow<'_>>, NippyJarError> {
if let (Some(filter), Some(phf)) = (&self.jar.filter, &self.jar.phf) {
// TODO: is it worth to parallelize both?

// May have false positives
if filter.contains(key)? {
// May have false positives
if let Some(row_index) = phf.get_index(key)? {
self.row = self
.jar
.offsets_index
.access(row_index as usize)
.expect("built from same set") as u64;
return self.next_row_with_cols(mask)
}
}
} else {
return Err(NippyJarError::UnsupportedFilterQuery)
}

Ok(None)
}

/// Returns a row by its number by using a `mask` to only read certain columns from the row.
pub fn row_by_number_with_cols(
&mut self,
Expand Down
4 changes: 0 additions & 4 deletions crates/storage/nippy-jar/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ pub enum NippyJarError {
FilterMaxCapacity,
#[error("cuckoo was not properly initialized after loaded")]
FilterCuckooNotLoaded,
#[error("perfect hashing function doesn't have any keys added")]
PHFMissingKeys,
#[error("nippy jar initialized without perfect hashing function")]
PHFMissing,
#[error("nippy jar was built without an index")]
UnsupportedFilterQuery,
#[error("the size of an offset must be at most 8 bytes, got {offset_size}")]
Expand Down
Loading

0 comments on commit 28e46bf

Please sign in to comment.