Skip to content

Commit

Permalink
Add TIGHTENING Ratio and FP_Rate module string configs and parse to f…
Browse files Browse the repository at this point in the history
…loat

Signed-off-by: Nihal Mehta <[email protected]>
  • Loading branch information
nnmehta committed Dec 9, 2024
1 parent eaa218f commit adba9e5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/bloom/command_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/configs.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<f64> = Mutex::new(BLOOM_FP_RATE_DEFAULT);
pub static ref BLOOM_TIGHTENING_RATIO: Mutex<f64> = Mutex::new(TIGHTENING_RATIO);
}

/// Constants
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down

0 comments on commit adba9e5

Please sign in to comment.