Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
Signed-off-by: Little-Wallace <bupt2013211450@gmail.com>
  • Loading branch information
Little-Wallace committed Jan 20, 2023
1 parent c6d9ac3 commit 660ad11
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 12 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

7 changes: 3 additions & 4 deletions src/storage/src/hummock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,11 @@ pub fn hit_sstable_bloom_filter(
local_stats: &mut StoreLocalStatistic,
) -> bool {
local_stats.bloom_filter_check_counts += 1;
let surely_not_have = sstable_info_ref.surely_not_have_hashvalue(prefix_hash);

if surely_not_have {
let may_exist = sstable_info_ref.may_match_hash(prefix_hash);
if !may_exist {
local_stats.bloom_filter_true_negative_count += 1;
}
!surely_not_have
may_exist
}

/// Get `user_value` from `OrderSortedUncommittedData`. If not get successful, return None.
Expand Down
6 changes: 5 additions & 1 deletion src/storage/src/hummock/sstable/bloom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ impl BloomFilterReader {
self.data.is_empty()
}

pub fn get_raw_data(&self) -> &[u8] {
&self.data
}

/// Judges whether the hash value is in the table with the given false positive rate.
///
/// Note:
Expand All @@ -91,7 +95,7 @@ impl BloomFilterReader {
/// - if the return value is true, then the table may or may not have the user key that has
/// the hash actually, a.k.a. we don't know the answer.
pub fn may_match(&self, mut h: u32) -> bool {
if self.k > 30 {
if self.k > 30 || self.k == 00 {
// potential new encoding for short Bloom filters
true
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/storage/src/hummock/sstable/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ pub(super) mod tests {
assert_eq!(table.has_bloom_filter(), with_blooms);
for i in 0..key_count {
let full_key = test_key_of(i);
assert!(!table.surely_not_have_dist_key(full_key.user_key.encode().as_slice()));
assert!(table.may_match(full_key.user_key.encode().as_slice()));
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/storage/src/hummock/sstable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,16 @@ impl Sstable {
!self.filter_reader.is_empty()
}

pub fn surely_not_have_dist_key(&self, dist_key: &[u8]) -> bool {
pub fn may_match(&self, dist_key: &[u8]) -> bool {
let enable_bloom_filter: fn() -> bool = || {
fail_point!("disable_bloom_filter", |_| false);
true
};
if enable_bloom_filter() && self.has_bloom_filter() {
let hash = xxh32::xxh32(dist_key, 0);
self.surely_not_have_hashvalue(hash)
self.may_match_hash(hash)
} else {
false
true
}
}

Expand All @@ -166,8 +166,8 @@ impl Sstable {
}

#[inline(always)]
pub fn surely_not_have_hashvalue(&self, hash: u32) -> bool {
!self.filter_reader.may_match(hash)
pub fn may_match_hash(&self, hash: u32) -> bool {
self.filter_reader.may_match(hash)
}

pub fn block_count(&self) -> usize {
Expand Down
10 changes: 9 additions & 1 deletion src/storage/src/hummock/sstable_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -869,14 +869,22 @@ mod tests {
async fn validate_sst(
sstable_store: SstableStoreRef,
info: &SstableInfo,
meta: SstableMeta,
mut meta: SstableMeta,
x_range: Range<usize>,
) {
let mut stats = StoreLocalStatistic::default();
let holder = sstable_store.sstable(info, &mut stats).await.unwrap();
let mut filter_data = std::mem::take(&mut meta.bloom_filter);
if !filter_data.is_empty() {
filter_data.pop();
}
assert_eq!(holder.value().meta, meta);
let holder = sstable_store.sstable(info, &mut stats).await.unwrap();
assert_eq!(holder.value().meta, meta);
assert_eq!(
filter_data.as_slice(),
holder.value().filter_reader.get_raw_data()
);
let mut iter = SstableIterator::new(
holder,
sstable_store,
Expand Down
2 changes: 2 additions & 0 deletions src/workspace-hack/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ ahash = { version = "0.8" }
anyhow = { version = "1", features = ["backtrace"] }
arrayvec = { version = "0.7", default-features = false, features = ["std"] }
auto_enums = { version = "0.7", features = ["futures"] }
base64 = { version = "0.21" }
bytes = { version = "1", features = ["serde"] }
chrono = { version = "0.4" }
clap = { version = "3", features = ["derive", "env"] }
Expand Down Expand Up @@ -109,6 +110,7 @@ anyhow = { version = "1", features = ["backtrace"] }
arrayvec = { version = "0.7", default-features = false, features = ["std"] }
auto_enums = { version = "0.7", features = ["futures"] }
auto_enums_derive = { version = "0.7", default-features = false, features = ["futures", "std"] }
base64 = { version = "0.21" }
bytes = { version = "1", features = ["serde"] }
cc = { version = "1", default-features = false, features = ["parallel"] }
chrono = { version = "0.4" }
Expand Down

0 comments on commit 660ad11

Please sign in to comment.