From 0e75a7f5e3253220de45c069c34b72ca52f9f446 Mon Sep 17 00:00:00 2001 From: Nihal Mehta Date: Mon, 9 Dec 2024 20:18:31 +0000 Subject: [PATCH] Add TIGHTENING Ratio and FP_Rate module string configs and parse to float Signed-off-by: Nihal Mehta --- src/bloom/command_handler.rs | 10 +++++----- src/configs.rs | 3 +++ src/lib.rs | 2 ++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/bloom/command_handler.rs b/src/bloom/command_handler.rs index e0306c7..0a76f74 100644 --- a/src/bloom/command_handler.rs +++ b/src/bloom/command_handler.rs @@ -109,8 +109,8 @@ pub fn bloom_filter_add_value( } None => { // Instantiate empty bloom filter. - let fp_rate = configs::BLOOM_FP_RATE_DEFAULT; - let tightening_ratio = configs::TIGHTENING_RATIO; + let fp_rate = configs::BLOOM_FP_RATE; + let tightening_ratio = configs::BLOOM_TIGHTENING_RATIO; let capacity = configs::BLOOM_CAPACITY.load(Ordering::Relaxed) as u32; let expansion = configs::BLOOM_EXPANSION.load(Ordering::Relaxed) as u32; let use_random_seed = configs::BLOOM_USE_RANDOM_SEED.load(Ordering::Relaxed); @@ -315,8 +315,8 @@ pub fn bloom_filter_insert(ctx: &Context, input_args: &[ValkeyString]) -> Valkey // Parse the filter name let filter_name = &input_args[idx]; idx += 1; - let mut fp_rate = configs::BLOOM_FP_RATE_DEFAULT; - let mut tightening_ratio = configs::TIGHTENING_RATIO; + let mut fp_rate = configs::BLOOM_FP_RATE; + let mut tightening_ratio = configs::BLOOM_TIGHTENING_RATIO; let mut capacity = configs::BLOOM_CAPACITY.load(Ordering::Relaxed) as u32; let mut expansion = configs::BLOOM_EXPANSION.load(Ordering::Relaxed) as u32; let mut nocreate = false; @@ -561,4 +561,4 @@ pub fn bloom_filter_load(ctx: &Context, input_args: &[ValkeyString]) -> ValkeyRe } } } -} +} \ No newline at end of file diff --git a/src/configs.rs b/src/configs.rs index e16fc11..5978816 100644 --- a/src/configs.rs +++ b/src/configs.rs @@ -1,6 +1,7 @@ use lazy_static::lazy_static; use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicI64; +use std::sync::Mutex; /// Configurations pub const BLOOM_CAPACITY_DEFAULT: i64 = 100000; @@ -30,6 +31,8 @@ lazy_static! { pub static ref BLOOM_MEMORY_LIMIT_PER_FILTER: AtomicI64 = AtomicI64::new(BLOOM_MEMORY_LIMIT_PER_FILTER_DEFAULT); pub static ref BLOOM_USE_RANDOM_SEED: AtomicBool = AtomicBool::default(); + pub static ref BLOOM_FP_RATE: Mutex = Mutex::new(BLOOM_FP_RATE_DEFAULT); + pub static ref BLOOM_TIGHTENING_RATIO: Mutex = Mutex::new(TIGHTENING_RATIO); } /// Constants diff --git a/src/lib.rs b/src/lib.rs index 8f5b971..6ccc504 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -103,6 +103,8 @@ valkey_module! { ["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: [ + ["bloom-fp-rate", &*configs::BLOOM_FP_RATE.to_string(), configs::BLOOM_FP_RATE_DEFAULT.to_string(), ConfigurationFlags::DEFAULT, None], + ["bloom-tightening-ratio", &*configs::BLOOM_TIGHTENING_RATIO.to_string(), configs::TIGHTENING_RATIO.to_string(), ConfigurationFlags::DEFAULT, None], ], bool: [ ["bloom-use-random-seed", &*configs::BLOOM_USE_RANDOM_SEED, configs::BLOOM_USE_RANDOM_SEED_DEFAULT, ConfigurationFlags::DEFAULT, None],