Skip to content

Commit

Permalink
Update command_handler
Browse files Browse the repository at this point in the history
Signed-off-by: Nihal Mehta <nnmehta@amazon.com>
  • Loading branch information
nnmehta committed Dec 5, 2024
1 parent ec22d90 commit e4521ea
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/bloom/command_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,9 @@ pub fn bloom_filter_reserve(ctx: &Context, input_args: &[ValkeyString]) -> Valke

pub fn bloom_filter_insert(ctx: &Context, input_args: &[ValkeyString]) -> ValkeyResult {
let argc = input_args.len();
let validate_size_limit = ctx.get_flags().contains(ContextFlags::REPLICATED);
let replicated_cmd = ctx.get_flags().contains(ContextFlags::REPLICATED);
// At the very least, we need: BF.INSERT <key> ITEMS <item>
if !validate_size_limit && argc < 4 || validate_size_limit && argc < 5 {
if argc < 4 {
return Err(ValkeyError::WrongArity);
}
let mut idx = 1;
Expand Down Expand Up @@ -333,9 +333,9 @@ pub fn bloom_filter_insert(ctx: &Context, input_args: &[ValkeyString]) -> Valkey
}
};
}
"TIGHTENING" => {
if !validate_size_limit {
return Err(ValkeyError::Str(utils::ERROR));
"TIGHTENING" if replicated_cmd => {
if idx >= (argc - 1) {
return Err(ValkeyError::WrongArity);
}
idx += 1;
tightening_ratio = match input_args[idx].to_string_lossy().parse::<f64>() {
Expand Down
9 changes: 4 additions & 5 deletions src/bloom/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ impl BloomFilterType {
// Create the bloom filter and add to the main BloomFilter object.
let bloom = BloomFilter::new(fp_rate, capacity);
let filters = vec![bloom];
let tightening_ratio = 0.5;
let bloom = BloomFilterType {
expansion,
fp_rate,
Expand Down Expand Up @@ -608,14 +607,14 @@ mod tests {
let rand_prefix = random_prefix(7);
// 1 in every 1000 operations is expected to be a false positive.
let expected_fp_rate: f64 = 0.001;
let expected_tightening_ratio: f64 = 0.5;
let tightening_ratio: f64 = 0.5;
let initial_capacity = 10000;
// Expansion of 0 indicates non scaling.
let expansion = 0;
// Validate the non scaling behavior of the bloom filter.
let mut bf = BloomFilterType::new_reserved(
expected_fp_rate,
expected_tightening_ratio,
tightening_ratio,
initial_capacity,
expansion,
true,
Expand Down Expand Up @@ -672,13 +671,13 @@ mod tests {
let rand_prefix = random_prefix(7);
// 1 in every 1000 operations is expected to be a false positive.
let expected_fp_rate: f64 = 0.001;
let expected_tightening_ratio: f64 = 0.5;
let tightening_ratio: f64 = 0.5;
let initial_capacity = 10000;
let expansion = 2;
let num_filters_to_scale = 5;
let mut bf = BloomFilterType::new_reserved(
expected_fp_rate,
expected_tightening_ratio,
tightening_ratio,
initial_capacity,
expansion,
true,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_replication.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_replication_behavior(self):
('BF.ADD', 'BF.ADD key item', 'BF.ADD key item1', 2),
('BF.MADD', 'BF.MADD key item', 'BF.MADD key item1', 2),
('BF.RESERVE', 'BF.RESERVE key 0.001 100000', 'BF.ADD key item1', 1),
('BF.INSERT', 'BF.INSERT key items item tightening 0.5', 'BF.INSERT key items item1 tightening 0.5', 2),
('BF.INSERT', 'BF.INSERT key items item', 'BF.INSERT key items item1', 2),
]
for test_case in bloom_write_cmds:
prefix = test_case[0]
Expand Down

0 comments on commit e4521ea

Please sign in to comment.