forked from fjall-rs/lsm-tree
-
Notifications
You must be signed in to change notification settings - Fork 1
refactor: unify merge resolution via bloom-filtered iterator pipeline #69
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
Merged
polaz
merged 10 commits into
main
from
feat/#46-refactor-unify-merge-resolution-via-bloom-filtered
Mar 22, 2026
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c6fea40
refactor: unify merge resolution via bloom-filtered iterator pipeline
polaz 0c8f22e
test: cover bloom_passes key_hash and prefix_hash rejection paths
polaz 318fe32
refactor(bloom): rename bloom_may_contain_key to bloom_may_contain_ke…
polaz 7f36218
docs: remove stale line references and clarify test docstrings
polaz 8e6ba0f
fix: remove leftover conflict marker in tree_prefix_bloom test
polaz 52deaef
docs: remove stale line ref and clarify pipeline design choice
polaz 94f767c
docs(bloom): note conservative fallback for partitioned/TLI filters
polaz 56aafdb
fix(bloom): apply key_hash filtering to multi-table runs
polaz 4836e82
perf(bench): add merge point-read latency benchmark for deep L0
polaz 3d97a40
refactor(bench): extract populate_merge_tree helper
polaz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| use criterion::{criterion_group, criterion_main, Criterion}; | ||
| use lsm_tree::{AbstractTree, Cache, Config, MergeOperator, SequenceNumberCounter, UserValue}; | ||
| use std::sync::Arc; | ||
| use tempfile::tempdir; | ||
|
|
||
| /// Simple counter merge operator for benchmarks. | ||
| struct CounterMerge; | ||
|
|
||
| impl MergeOperator for CounterMerge { | ||
| fn merge( | ||
| &self, | ||
| _key: &[u8], | ||
| base_value: Option<&[u8]>, | ||
| operands: &[&[u8]], | ||
| ) -> lsm_tree::Result<UserValue> { | ||
| let mut counter: i64 = match base_value { | ||
| Some(bytes) if bytes.len() == 8 => { | ||
| i64::from_le_bytes(bytes.try_into().expect("checked")) | ||
| } | ||
| _ => 0, | ||
| }; | ||
| for op in operands { | ||
| if op.len() == 8 { | ||
| counter += i64::from_le_bytes((*op).try_into().expect("checked")); | ||
| } | ||
| } | ||
| Ok(counter.to_le_bytes().to_vec().into()) | ||
| } | ||
| } | ||
|
|
||
| fn merge_point_read_deep_tree(c: &mut Criterion) { | ||
| let mut group = c.benchmark_group("merge point read"); | ||
| group.sample_size(100); | ||
|
|
||
| for table_count in [10, 50, 100] { | ||
| // --- Uncached: cold disk reads --- | ||
| let folder = tempdir().unwrap(); | ||
| let tree = Config::new( | ||
| &folder, | ||
| SequenceNumberCounter::default(), | ||
| SequenceNumberCounter::default(), | ||
| ) | ||
| .use_cache(Arc::new(Cache::with_capacity_bytes(0))) | ||
| .with_merge_operator(Some(Arc::new(CounterMerge))) | ||
| .open() | ||
| .unwrap(); | ||
|
|
||
| let mut seqno = 0u64; | ||
|
|
||
| // Base value on disk | ||
| tree.insert("counter", 100_i64.to_le_bytes(), seqno); | ||
| seqno += 1; | ||
| tree.flush_active_memtable(0).unwrap(); | ||
|
|
||
| // Create many tables with unrelated keys (bloom should reject these) | ||
| for i in 1..table_count { | ||
| let key = format!("other_{i:04}"); | ||
| tree.insert(key, 0_i64.to_le_bytes(), seqno); | ||
| seqno += 1; | ||
| tree.flush_active_memtable(0).unwrap(); | ||
| } | ||
|
|
||
| // Merge operand in active memtable | ||
| tree.merge("counter", 1_i64.to_le_bytes(), seqno); | ||
| seqno += 1; | ||
|
|
||
| group.bench_function(format!("merge get, {table_count} tables (uncached)"), |b| { | ||
| b.iter(|| { | ||
| let val = tree.get("counter", seqno).unwrap().unwrap(); | ||
| let n = i64::from_le_bytes((*val).try_into().unwrap()); | ||
| assert_eq!(n, 101); | ||
| }); | ||
| }); | ||
|
|
||
| // --- Cached: warm block cache --- | ||
| let folder2 = tempdir().unwrap(); | ||
| let tree_cached = Config::new( | ||
| &folder2, | ||
| SequenceNumberCounter::default(), | ||
| SequenceNumberCounter::default(), | ||
| ) | ||
| .use_cache(Arc::new(Cache::with_capacity_bytes(64 * 1_024 * 1_024))) | ||
| .with_merge_operator(Some(Arc::new(CounterMerge))) | ||
| .open() | ||
| .unwrap(); | ||
|
|
||
| let mut s = 0u64; | ||
| tree_cached.insert("counter", 100_i64.to_le_bytes(), s); | ||
| s += 1; | ||
| tree_cached.flush_active_memtable(0).unwrap(); | ||
|
|
||
| for i in 1..table_count { | ||
| let key = format!("other_{i:04}"); | ||
| tree_cached.insert(key, 0_i64.to_le_bytes(), s); | ||
| s += 1; | ||
| tree_cached.flush_active_memtable(0).unwrap(); | ||
| } | ||
|
|
||
| tree_cached.merge("counter", 1_i64.to_le_bytes(), s); | ||
| s += 1; | ||
|
|
||
| // Warm the cache | ||
| let _ = tree_cached.get("counter", s).unwrap(); | ||
|
|
||
| group.bench_function(format!("merge get, {table_count} tables (cached)"), |b| { | ||
| b.iter(|| { | ||
| let val = tree_cached.get("counter", s).unwrap().unwrap(); | ||
| let n = i64::from_le_bytes((*val).try_into().unwrap()); | ||
| assert_eq!(n, 101); | ||
| }); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| criterion_group!(benches, merge_point_read_deep_tree); | ||
| criterion_main!(benches); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.