Skip to content

Commit

Permalink
Updating the digest changes to follow updated version of bloom. As we…
Browse files Browse the repository at this point in the history
…ll as removing unnecesary fields saved in rdb

Signed-off-by: zackcam <zackcam@amazon.com>
  • Loading branch information
zackcam committed Dec 3, 2024
1 parent 669fd9f commit 3b62a01
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ homepage = "https://github.com/valkey-io/valkey-bloom"
valkey-module = "0.1.2"
valkey-module-macros = "0"
linkme = "0"
bloomfilter = { version = "3", features = ["serde"] }
bloomfilter = { version = "3.0.1", features = ["serde"] }
lazy_static = "1.4.0"
libc = "0.2"
serde = { version = "1.0", features = ["derive"] }
Expand Down
33 changes: 13 additions & 20 deletions src/bloom/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,14 @@ impl ValkeyDataType for BloomFilterType {
let Ok(bitmap) = raw::load_string_buffer(rdb) else {
return None;
};
let Ok(number_of_bits) = raw::load_unsigned(rdb) else {
return None;
};
// Reject RDB Load if any bloom filter within a bloom object of a size greater than what is allowed.
if !BloomFilter::validate_size_with_bits(number_of_bits) {
logging::log_warning("Failed to restore bloom object because it contains a filter larger than the max allowed size limit.");
return None;
}
let Ok(number_of_hash_functions) = raw::load_unsigned(rdb) else {
return None;
};
// let Ok(number_of_bits) = raw::load_unsigned(rdb) else {
// return None;
// };
// // Reject RDB Load if any bloom filter within a bloom object of a size greater than what is allowed.
// if !BloomFilter::validate_size_with_bits(number_of_bits) {
// logging::log_warning("Failed to restore bloom object because it contains a filter larger than the max allowed size limit.");
// return None;
// // }
let Ok(capacity) = raw::load_unsigned(rdb) else {
return None;
};
Expand All @@ -103,12 +100,12 @@ impl ValkeyDataType for BloomFilterType {
} else {
capacity
};
let sip_keys = [
(FIXED_SIP_KEY_ONE_A, FIXED_SIP_KEY_ONE_B),
(FIXED_SIP_KEY_TWO_A, FIXED_SIP_KEY_TWO_B),
];
let filter =
BloomFilter::from_existing(bitmap.as_ref(), num_items as u32, capacity as u32);
if !BloomFilter::validate_size_with_bits(filter.bloom.len()) {
logging::log_warning("Failed to restore bloom object because it contains a filter larger than the max allowed size limit.");
return None;
}
filters.push(filter);
}
BLOOM_OBJECT_TOTAL_MEMORY_BYTES.fetch_add(
Expand All @@ -129,11 +126,7 @@ impl ValkeyDataType for BloomFilterType {
dig.add_long_long(self.expansion.into());
dig.add_string_buffer(&self.fp_rate.to_le_bytes());
for filter in &self.filters {
dig.add_string_buffer(&filter.bloom.bitmap());
for &(key1, key2) in &filter.sip_keys() {
dig.add_long_long(key1 as i64);
dig.add_long_long(key2 as i64);
}
dig.add_string_buffer(filter.bloom.as_slice());
dig.add_long_long(filter.num_items.into());
dig.add_long_long(filter.capacity.into());
}
Expand Down
4 changes: 0 additions & 4 deletions src/bloom/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,6 @@ impl BloomFilter {
self.bloom.set(item)
}

pub fn sip_keys(&self) -> [(u64, u64); 2] {
self.bloom.sip_keys()
}

/// Create a new BloomFilter from an existing BloomFilter object (COPY command).
pub fn create_copy_from(bf: &BloomFilter) -> BloomFilter {
BloomFilter::from_existing(&bf.bloom.to_bytes(), bf.num_items, bf.capacity)
Expand Down
2 changes: 0 additions & 2 deletions src/wrapper/bloom_callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ pub unsafe extern "C" fn bloom_rdb_save(rdb: *mut raw::RedisModuleIO, value: *mu
bitmap.as_ptr().cast::<c_char>(),
bitmap.len(),
);
raw::save_unsigned(rdb, bloom.len());
raw::save_unsigned(rdb, bloom.number_of_hash_functions() as u64);
raw::save_unsigned(rdb, filter.capacity as u64);
if filter_list_iter.peek().is_none() {
raw::save_unsigned(rdb, filter.num_items as u64);
Expand Down

0 comments on commit 3b62a01

Please sign in to comment.