From c2755369436a35f57ca8b0b2d0be7b0d39e332fd Mon Sep 17 00:00:00 2001 From: zhangjinpeng1987 Date: Tue, 12 Jul 2022 18:52:30 +0800 Subject: [PATCH 1/4] opt: has option turn off key value separation Signed-off-by: zhangjinpeng1987 --- src/db/opt.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/db/opt.rs b/src/db/opt.rs index 58f7379b..9560e133 100644 --- a/src/db/opt.rs +++ b/src/db/opt.rs @@ -71,6 +71,7 @@ pub struct AgateOptions { /// LSM tree or separately in the log value files. /// /// The default value of `value_threshold` is 1 << 10 bytes. + /// 0 means trun off key value separation. pub value_threshold: usize, /// Sets the maximum number of tables to keep in memory before stalling. /// @@ -226,7 +227,7 @@ impl AgateOptions { } pub fn skip_vlog(&self, entry: &Entry) -> bool { - entry.value.len() < self.value_threshold + self.value_threshold == 0 || entry.value.len() < self.value_threshold } pub fn arena_size(&self) -> u64 { From a6693b68299275e50ea3ceb18bf73575b814904a Mon Sep 17 00:00:00 2001 From: zhangjinpeng1987 Date: Tue, 12 Jul 2022 19:04:01 +0800 Subject: [PATCH 2/4] opt: add option can totally turn off key value separation Signed-off-by: zhangjinpeng1987 --- src/db/opt.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/db/opt.rs b/src/db/opt.rs index 9560e133..7eae29d8 100644 --- a/src/db/opt.rs +++ b/src/db/opt.rs @@ -70,8 +70,8 @@ pub struct AgateOptions { /// Sets the threshold used to decide whether a value is stored directly in the /// LSM tree or separately in the log value files. /// - /// The default value of `value_threshold` is 1 << 10 bytes. - /// 0 means trun off key value separation. + /// The default value of `value_threshold` is 1 << 10 bytes. 0 means trun off key + /// value separation. pub value_threshold: usize, /// Sets the maximum number of tables to keep in memory before stalling. /// @@ -276,4 +276,18 @@ mod tests { assert!(opt.arena_size() > opt.mem_table_size); assert!(opt.arena_size() <= (opt.mem_table_size as f64 * 1.1) as u64); } + + #[test] + fn test_skip_vlog() { + let mut opt = AgateOptions::default(); + let (k, v) = (Bytes::from("key"), Bytes::from("value")); + let v_len = v.len(); + let e = Entry::new(k, v); + opt.value_threshold = v_len + 1; + assert_eq!(opt.skip_vlog(&e), true); + opt.value_threshold = v_len - 1; + assert_eq!(opt.skip_vlog(&e), false); + opt.value_threshold = 0; + assert_eq!(opt.skip_vlog(&e), true); + } } From d938feecee09ada3d73c90b78dbc7e6a73b670bb Mon Sep 17 00:00:00 2001 From: zhangjinpeng1987 Date: Tue, 12 Jul 2022 23:24:38 +0800 Subject: [PATCH 3/4] make lint happy Signed-off-by: zhangjinpeng1987 --- src/db/opt.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/db/opt.rs b/src/db/opt.rs index 4ed8d685..7b1a2779 100644 --- a/src/db/opt.rs +++ b/src/db/opt.rs @@ -284,10 +284,10 @@ mod tests { let v_len = v.len(); let e = Entry::new(k, v); opt.value_threshold = v_len + 1; - assert_eq!(opt.skip_vlog(&e), true); + assert!(opt.skip_vlog(&e), true); opt.value_threshold = v_len - 1; - assert_eq!(opt.skip_vlog(&e), false); + assert!(!opt.skip_vlog(&e)); opt.value_threshold = 0; - assert_eq!(opt.skip_vlog(&e), true); + assert!(opt.skip_vlog(&e), true); } } From 12ca31e1fd437a0c4c363c52a45b7a87e03ec717 Mon Sep 17 00:00:00 2001 From: zhangjinpeng1987 Date: Tue, 12 Jul 2022 23:40:19 +0800 Subject: [PATCH 4/4] make lint happy Signed-off-by: zhangjinpeng1987 --- src/db/opt.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/db/opt.rs b/src/db/opt.rs index 7b1a2779..2b5025dc 100644 --- a/src/db/opt.rs +++ b/src/db/opt.rs @@ -284,10 +284,10 @@ mod tests { let v_len = v.len(); let e = Entry::new(k, v); opt.value_threshold = v_len + 1; - assert!(opt.skip_vlog(&e), true); + assert!(opt.skip_vlog(&e)); opt.value_threshold = v_len - 1; assert!(!opt.skip_vlog(&e)); opt.value_threshold = 0; - assert!(opt.skip_vlog(&e), true); + assert!(opt.skip_vlog(&e)); } }