Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opt: has option switch key value separation off #182

Merged
merged 5 commits into from
Jul 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}
}