Skip to content

Commit e44ac48

Browse files
Add server version validation during module loading
Signed-off-by: VanessaTang <[email protected]>
1 parent 8f1c9f4 commit e44ac48

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/configs.rs

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ pub const BLOOM_USE_RANDOM_SEED_DEFAULT: bool = true;
3030

3131
pub const BLOOM_DEFRAG_DEAFULT: bool = true;
3232

33+
/// Minimal Valkey version that supports Bloom Module
34+
pub const BLOOM_MIN_MAJOR_VERSION: i64 = 8;
35+
pub const BLOOM_MIN_MINOR_VERSION: i64 = 0;
36+
pub const BLOOM_MIN_PATCH_VERSION: i64 = 0;
37+
3338
// Max Memory usage allowed overall within a bloom object (128MB).
3439
// Beyond this threshold, a bloom object is classified as large.
3540
// Write operations that result in bloom object allocation larger than this size will be rejected.

src/lib.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,29 @@ pub mod metrics;
99
pub mod wrapper;
1010
use crate::bloom::command_handler;
1111
use crate::bloom::data_type::BLOOM_TYPE;
12+
use configs::{BLOOM_MIN_MAJOR_VERSION, BLOOM_MIN_MINOR_VERSION, BLOOM_MIN_PATCH_VERSION};
1213
use valkey_module_macros::info_command_handler;
1314

1415
pub const MODULE_NAME: &str = "bf";
1516

16-
fn initialize(_ctx: &Context, _args: &[ValkeyString]) -> Status {
17-
Status::Ok
17+
fn initialize(ctx: &Context, _args: &[ValkeyString]) -> Status {
18+
let ver = ctx
19+
.get_redis_version()
20+
.expect("Unable to get server version!");
21+
let server_version: Vec<i64> = vec![ver.major.into(), ver.minor.into(), ver.patch.into()];
22+
let min_support_version: Vec<i64> = vec![
23+
BLOOM_MIN_MAJOR_VERSION,
24+
BLOOM_MIN_MINOR_VERSION,
25+
BLOOM_MIN_PATCH_VERSION,
26+
];
27+
if server_version < min_support_version {
28+
ctx.log_warning(
29+
"Current server version doesn't satisfy minimal required version for bloom module!",
30+
);
31+
Status::Err
32+
} else {
33+
Status::Ok
34+
}
1835
}
1936

2037
fn deinitialize(_ctx: &Context) -> Status {

0 commit comments

Comments
 (0)