Skip to content

Commit

Permalink
Opt: has option switch key value separation off (#182)
Browse files Browse the repository at this point in the history
* opt: has option turn off key value separation

Signed-off-by: zhangjinpeng1987 <zhangjinpeng@pingcap.com>
  • Loading branch information
zhangjinpeng87 authored Jul 13, 2022
1 parent a4e06f1 commit 475e17b
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/db/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +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.
/// 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.
///
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -275,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!(opt.skip_vlog(&e));
opt.value_threshold = v_len - 1;
assert!(!opt.skip_vlog(&e));
opt.value_threshold = 0;
assert!(opt.skip_vlog(&e));
}
}

0 comments on commit 475e17b

Please sign in to comment.