Skip to content

Commit

Permalink
Rename config -s
Browse files Browse the repository at this point in the history
  • Loading branch information
KarthikSubbarao committed Oct 29, 2024
1 parent 227b7d5 commit 0e7ddd9
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/bloom/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ impl BloomFilter {
pub fn validate_size(capacity: u32, fp_rate: f64) -> bool {
let bytes = bloomfilter::Bloom::<[u8]>::compute_bitmap_size(capacity as usize, fp_rate)
+ std::mem::size_of::<BloomFilter>();
if bytes > configs::BLOOM_MAX_MEMORY_USAGE.load(Ordering::Relaxed) as usize {
if bytes > configs::BLOOM_MEMORY_LIMIT_PER_FILTER.load(Ordering::Relaxed) as usize {
return false;
}
true
Expand All @@ -249,7 +249,7 @@ impl BloomFilter {
/// Returns whether the bloom filter is of a valid size or not.
pub fn validate_size_with_bits(number_of_bits: u64) -> bool {
let bytes = std::mem::size_of::<BloomFilter>() as u64 + number_of_bits;
if bytes > configs::BLOOM_MAX_MEMORY_USAGE.load(Ordering::Relaxed) as u64 {
if bytes > configs::BLOOM_MEMORY_LIMIT_PER_FILTER.load(Ordering::Relaxed) as u64 {
return false;
}
true
Expand Down
10 changes: 5 additions & 5 deletions src/configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ pub const BLOOM_FP_RATE_MAX: f64 = 1.0;
// Max Memory usage allowed per bloom filter within a bloom object (64MB).
// Beyond this threshold, a bloom object is classified as large and is exempt from defrag operations.
// Also, write operations that result in bloom object allocation larger than this size will be rejected.
pub const BLOOM_MAX_MEMORY_USAGE_DEFAULT: i64 = 64 * 1024 * 1024;
pub const BLOOM_MAX_MEMORY_USAGE_MIN: i64 = 0;
pub const BLOOM_MAX_MEMORY_USAGE_MAX: i64 = i64::MAX;
pub const BLOOM_MEMORY_LIMIT_PER_FILTER_DEFAULT: i64 = 64 * 1024 * 1024;
pub const BLOOM_MEMORY_LIMIT_PER_FILTER_MIN: i64 = 0;
pub const BLOOM_MEMORY_LIMIT_PER_FILTER_MAX: i64 = i64::MAX;

lazy_static! {
pub static ref BLOOM_CAPACITY: AtomicI64 = AtomicI64::new(BLOOM_CAPACITY_DEFAULT);
pub static ref BLOOM_EXPANSION: AtomicI64 = AtomicI64::new(BLOOM_EXPANSION_DEFAULT);
pub static ref BLOOM_MAX_MEMORY_USAGE: AtomicI64 =
AtomicI64::new(BLOOM_MAX_MEMORY_USAGE_DEFAULT);
pub static ref BLOOM_MEMORY_LIMIT_PER_FILTER: AtomicI64 =
AtomicI64::new(BLOOM_MEMORY_LIMIT_PER_FILTER_DEFAULT);
}

/// Constants
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ valkey_module! {
i64: [
["bloom-max-item-size", &*configs::BLOOM_CAPACITY, configs::BLOOM_CAPACITY_DEFAULT, configs::BLOOM_CAPACITY_MIN as i64, configs::BLOOM_CAPACITY_MAX as i64, ConfigurationFlags::DEFAULT, None],
["bloom-expansion-rate", &*configs::BLOOM_EXPANSION, configs::BLOOM_EXPANSION_DEFAULT, configs::BLOOM_EXPANSION_MIN as i64, configs::BLOOM_EXPANSION_MAX as i64, ConfigurationFlags::DEFAULT, None],
["bloom-max-memory-usage", &*configs::BLOOM_MAX_MEMORY_USAGE, configs::BLOOM_MAX_MEMORY_USAGE_DEFAULT, configs::BLOOM_MAX_MEMORY_USAGE_MIN, configs::BLOOM_MAX_MEMORY_USAGE_MAX, ConfigurationFlags::DEFAULT, None],
["bloom-memory-limit-per-filter", &*configs::BLOOM_MEMORY_LIMIT_PER_FILTER, configs::BLOOM_MEMORY_LIMIT_PER_FILTER_DEFAULT, configs::BLOOM_MEMORY_LIMIT_PER_FILTER_MIN, configs::BLOOM_MEMORY_LIMIT_PER_FILTER_MAX, ConfigurationFlags::DEFAULT, None],
],
string: [
],
Expand Down
4 changes: 3 additions & 1 deletion src/wrapper/bloom_callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ pub unsafe extern "C" fn bloom_defrag(
value: *mut *mut c_void,
) -> i32 {
let curr_item = &*(*value).cast::<BloomFilterType>();
if curr_item.memory_usage() > configs::BLOOM_MAX_MEMORY_USAGE.load(Ordering::Relaxed) as usize {
if curr_item.memory_usage()
> configs::BLOOM_MEMORY_LIMIT_PER_FILTER.load(Ordering::Relaxed) as usize
{
return 0;
}
let new_item = BloomFilterType::create_copy_from(curr_item);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_memory_usage_cmd(self):
def test_too_large_bloom_obj(self):
client = self.server.get_new_client()
# Set the max allowed size per bloom filter per bloom object to be 1000 bytes.
assert client.execute_command('CONFIG SET bf.bloom-max-memory-usage 1000') == b'OK'
assert client.execute_command('CONFIG SET bf.bloom-memory-limit-per-filter 1000') == b'OK'
obj_exceeds_size_err = "operation results in filter allocation exceeding size limit"
# Non Scaling
# Validate that when a cmd would have resulted in a bloom object creation with the starting filter with size
Expand Down
2 changes: 1 addition & 1 deletion tests/test_save_and_restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_restore_failed_large_bloom_filter(self):
# When we try to restore this on a server with the default max allowed filter size of 64MB, start up should fail.
updated_max_size = 180 * 1024 * 1024
original_max_size = 64 * 1024 * 1024
bf_add_result_1 = client.execute_command('CONFIG SET bf.bloom-max-memory-usage ' + str(updated_max_size))
bf_add_result_1 = client.execute_command('CONFIG SET bf.bloom-memory-limit-per-filter ' + str(updated_max_size))
client.execute_command('BF.RESERVE testSave 0.001 100000000')
assert int(client.execute_command('BF.INFO testSave size')) > original_max_size
bf_add_result_1 = client.execute_command('BF.ADD testSave item')
Expand Down

0 comments on commit 0e7ddd9

Please sign in to comment.