Skip to content

Commit 8077d58

Browse files
authored
Code cleanup: removing unused dependencies in tests, removing digest (#44)
file as it can be taken from a dependency and moving metric increments to after creates Signed-off-by: zackcam <[email protected]>
1 parent 56f631f commit 8077d58

18 files changed

+18
-118
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- name: Run cargo and clippy format check
2323
run: |
2424
cargo fmt --check
25-
# cargo clippy --profile release --all-targets -- -D clippy::all
25+
cargo clippy --profile release --all-targets -- -D clippy::all
2626
- name: Release Build
2727
run: RUSTFLAGS="-D warnings" cargo build --all --all-targets --release
2828
- name: Run unit tests
@@ -56,7 +56,7 @@ jobs:
5656
- name: Run cargo and clippy format check
5757
run: |
5858
cargo fmt --check
59-
# cargo clippy --profile release --all-targets -- -D clippy::all
59+
cargo clippy --profile release --all-targets -- -D clippy::all
6060
- name: Release Build
6161
run: RUSTFLAGS="-D warnings" cargo build --all --all-targets --release
6262
- name: Run unit tests
@@ -75,7 +75,7 @@ jobs:
7575
- name: Run cargo and clippy format check
7676
run: |
7777
cargo fmt --check
78-
# cargo clippy --profile release --all-targets -- -D clippy::all
78+
cargo clippy --profile release --all-targets -- -D clippy::all
7979
- name: Release Build
8080
run: RUSTFLAGS="-D warnings" cargo build --all --all-targets --release
8181
- name: Run unit tests

src/bloom/data_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use crate::bloom::utils::BloomFilter;
22
use crate::bloom::utils::BloomObject;
33
use crate::configs;
44
use crate::wrapper::bloom_callback;
5-
use crate::wrapper::digest::Digest;
65
use crate::MODULE_NAME;
76
use std::os::raw::c_int;
7+
use valkey_module::digest::Digest;
88
use valkey_module::native_types::ValkeyType;
99
use valkey_module::{logging, raw};
1010

src/bloom/utils.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,15 @@ impl BloomObject {
161161
let new_filter = Box::new(BloomFilter::create_copy_from(filter));
162162
filters.push(new_filter);
163163
}
164-
from_bf.bloom_object_incr_metrics_on_new_create();
165-
BloomObject {
164+
let new_copy = BloomObject {
166165
expansion: from_bf.expansion,
167166
fp_rate: from_bf.fp_rate,
168167
tightening_ratio: from_bf.tightening_ratio,
169168
is_seed_random: from_bf.is_seed_random,
170169
filters,
171-
}
170+
};
171+
new_copy.bloom_object_incr_metrics_on_new_create();
172+
new_copy
172173
}
173174

174175
/// Return the total memory usage of the BloomObject and every allocation it contains.
@@ -328,10 +329,7 @@ impl BloomObject {
328329
// Scale out by adding a new filter with capacity bounded within the u32 range. false positive rate is also
329330
// bound within the range f64::MIN_POSITIVE <= x < 1.0.
330331
let new_fp_rate =
331-
match Self::calculate_fp_rate(self.fp_rate, num_filters, self.tightening_ratio) {
332-
Ok(rate) => rate,
333-
Err(e) => return Err(e),
334-
};
332+
Self::calculate_fp_rate(self.fp_rate, num_filters, self.tightening_ratio)?;
335333
let new_capacity = match filter.capacity.checked_mul(self.expansion.into()) {
336334
Some(new_capacity) => new_capacity,
337335
None => {
@@ -467,13 +465,13 @@ impl BloomObject {
467465
is_seed_random,
468466
filters,
469467
};
468+
// Add overall bloom object metrics.
469+
item.bloom_object_incr_metrics_on_new_create();
470470
let bytes = item.memory_usage();
471471
// Reject the request, if the operation will result in creation of a bloom object of size greater than what is allowed.
472472
if validate_size_limit && !BloomObject::validate_size(bytes) {
473473
return Err(BloomError::ExceedsMaxBloomSize);
474474
}
475-
// Add overall bloom object metrics.
476-
item.bloom_object_incr_metrics_on_new_create();
477475
Ok(item)
478476
}
479477
_ => Err(BloomError::DecodeUnsupportedVersion),
@@ -672,7 +670,7 @@ impl BloomFilter {
672670
+ (self.bloom.len() / 8) as usize
673671
}
674672

675-
/// Caculates the number of bytes that the bloom filter will require to be allocated.
673+
/// Calculates the number of bytes that the bloom filter will require to be allocated.
676674
pub fn compute_size(capacity: i64, fp_rate: f64) -> usize {
677675
std::mem::size_of::<BloomFilter>()
678676
+ std::mem::size_of::<bloomfilter::Bloom<[u8]>>()

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ fn bloom_reserve_command(ctx: &Context, args: Vec<ValkeyString>) -> ValkeyResult
5151
command_handler::bloom_filter_reserve(ctx, &args)
5252
}
5353

54-
/// Command handler for BF.INFO <key> [CAPACITY | SIZE | FILTERS | ITEMS | EXPANSION]
54+
/// Command handler for BF.INFO <key> [CAPACITY | SIZE | FILTERS | ITEMS | EXPANSION | ERROR | MAXSCALEDCAPACITY]
5555
fn bloom_info_command(ctx: &Context, args: Vec<ValkeyString>) -> ValkeyResult {
5656
command_handler::bloom_filter_info(ctx, &args)
5757
}
5858

5959
/// Command handler for:
60-
/// BF.INSERT <key> [ERROR <fp_error>] [CAPACITY <capacity>] [EXPANSION <expansion>] [NOCREATE] [NONSCALING] ITEMS <item> [<item> ...]
60+
/// BF.INSERT <key> [ERROR <fp_error>] [CAPACITY <capacity>] [EXPANSION <expansion>] [NOCREATE] [NONSCALING] [VALIDATESCALETO <validatescaleto>] ITEMS <item> [<item> ...]
6161
fn bloom_insert_command(ctx: &Context, args: Vec<ValkeyString>) -> ValkeyResult {
6262
command_handler::bloom_filter_insert(ctx, &args)
6363
}

src/wrapper/bloom_callback.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::bloom::utils::BloomFilter;
44
use crate::bloom::utils::BloomObject;
55
use crate::configs;
66
use crate::metrics;
7-
use crate::wrapper::digest::Digest;
87
use bloomfilter::Bloom;
98
use lazy_static::lazy_static;
109
use std::ffi::CString;
@@ -13,6 +12,7 @@ use std::os::raw::{c_char, c_int, c_void};
1312
use std::ptr::null_mut;
1413
use std::sync::atomic::Ordering;
1514
use std::sync::Mutex;
15+
use valkey_module::digest::Digest;
1616
use valkey_module::logging;
1717
use valkey_module::logging::{log_io_error, ValkeyLogLevel};
1818
use valkey_module::raw;

src/wrapper/digest.rs

Lines changed: 0 additions & 80 deletions
This file was deleted.

src/wrapper/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
pub mod bloom_callback;
22
pub mod defrag;
3-
pub mod digest;

tests/test_bloom_acl_category.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import pytest
21
from valkeytests.conftest import resource_port_tracker
32
from valkey_bloom_test_case import ValkeyBloomTestCaseBase
43
from util.waiters import *

tests/test_bloom_basic.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import time
2-
import pytest
32
from util.waiters import *
43
from valkey import ResponseError
54
from valkey_bloom_test_case import ValkeyBloomTestCaseBase
65
from valkeytests.conftest import resource_port_tracker
7-
import logging
8-
import os
96

107
class TestBloomBasic(ValkeyBloomTestCaseBase):
118

tests/test_bloom_command.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import pytest
21
from valkey_bloom_test_case import ValkeyBloomTestCaseBase
32
from valkeytests.conftest import resource_port_tracker
4-
import valkey
5-
import uuid
63

74
class TestBloomCommand(ValkeyBloomTestCaseBase):
85

tests/test_bloom_correctness.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import pytest
21
from valkeytests.conftest import resource_port_tracker
32
from valkey_bloom_test_case import ValkeyBloomTestCaseBase
43

tests/test_bloom_defrag.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import time
2-
from valkeytests.valkey_test_case import ValkeyAction
32
from valkey_bloom_test_case import ValkeyBloomTestCaseBase
43
from valkeytests.conftest import resource_port_tracker
54
from util.waiters import *

tests/test_bloom_keyspace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import logging, time
1+
import time
22
from valkey_bloom_test_case import ValkeyBloomTestCaseBase
33
from valkeytests.conftest import resource_port_tracker
44

tests/test_bloom_metrics.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import pytest, time
2-
import os
1+
import time
32
from valkey_bloom_test_case import ValkeyBloomTestCaseBase
43
from valkeytests.conftest import resource_port_tracker
54
from util.waiters import *

tests/test_bloom_replication.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import pytest
1+
import pytest, os
22
from valkey import ResponseError
33
from valkeytests.valkey_test_case import ReplicationTestCase
44
from valkeytests.conftest import resource_port_tracker
5-
import os
65

76
class TestBloomReplication(ReplicationTestCase):
87

tests/test_bloom_save_and_restore.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import pytest, time
21
import os
32
from valkey import ResponseError
43
from valkey_bloom_test_case import ValkeyBloomTestCaseBase

tests/valkeytests/conftest.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
import socket
99
import os
1010
import tempfile
11-
import random
12-
import subprocess
13-
import threading
1411
from pathlib import Path
1512

1613
class PortTracker(object):

tests/valkeytests/util/waiters.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
timeout: The maximum time to wait for the function to return the expected value (default: TEST_MAX_WAIT_TIME_SECONDS)
1515
ignore_exception: The exception to ignore (default is None)
1616
"""
17-
import contextlib
18-
import warnings
1917
from functools import wraps
2018
import operator
2119
import time

0 commit comments

Comments
 (0)