Skip to content

Commit eaa4c49

Browse files
committed
simplify point lookup logic
1 parent fda5553 commit eaa4c49

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

src/any_tree.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@ pub enum AnyTree {
1919
Blob(BlobTree),
2020
}
2121

22-
/// Unified ingestion builder over AnyTree
22+
/// Unified ingestion builder over `AnyTree`
23+
// Keep zero allocations and direct dispatch; boxing introduces heap indirection and `dyn` adds virtual dispatch.
24+
// Ingestion calls use `&mut self` in tight loops; the active variant is stable and branch prediction makes the match cheap.
25+
// Allowing this lint preserves hot-path performance at the cost of a larger enum size.
26+
#[allow(clippy::large_enum_variant)]
2327
pub enum AnyIngestion<'a> {
2428
/// Ingestion for a standard LSM-tree
2529
Standard(Ingestion<'a>),
26-
/// Ingestion for a BlobTree with KV separation
30+
/// Ingestion for a [`BlobTree`] with KV separation
2731
Blob(BlobIngestion<'a>),
2832
}
2933

src/tree/mod.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,30 +84,26 @@ impl AbstractTree for Tree {
8484
let version_history_lock = self.version_history.read().expect("lock is poisoned");
8585
let super_version = version_history_lock.get_version_for_snapshot(seqno);
8686

87-
// Track the newest visible version across all sources
88-
let mut best: Option<InternalValue> = super_version.active_memtable.get(key, seqno);
87+
// Active memtable has the newest writes; if present, it's definitive.
88+
if let Some(entry) = super_version.active_memtable.get(key, seqno) {
89+
return Ok(ignore_tombstone_value(entry));
90+
}
8991

92+
// Sealed memtables are newer than any tables; return on first hit.
9093
if let Some(entry) =
9194
Self::get_internal_entry_from_sealed_memtables(&super_version, key, seqno)
9295
{
93-
match &best {
94-
Some(b) if b.key.seqno >= entry.key.seqno => {}
95-
_ => best = Some(entry),
96-
}
96+
return Ok(ignore_tombstone_value(entry));
9797
}
9898

99-
// Merge with the newest version found in tables
99+
// Otherwise consult tables (levels top-down, runs newest-first) and return first hit.
100100
if let Some(entry) =
101101
self.get_internal_entry_from_tables(&super_version.version, key, seqno)?
102102
{
103-
match &best {
104-
Some(b) if b.key.seqno >= entry.key.seqno => {}
105-
_ => best = Some(entry),
106-
}
103+
return Ok(ignore_tombstone_value(entry));
107104
}
108105

109-
// Apply tombstone semantics after choosing the newest version
110-
Ok(best.and_then(ignore_tombstone_value))
106+
Ok(None)
111107
}
112108

113109
fn current_version(&self) -> Version {
@@ -479,7 +475,6 @@ impl AbstractTree for Tree {
479475
self.current_version().level(idx).map(|x| x.table_count())
480476
}
481477

482-
#[expect(clippy::significant_drop_tightening)]
483478
fn approximate_len(&self) -> usize {
484479
let super_version = self
485480
.version_history
@@ -512,7 +507,6 @@ impl AbstractTree for Tree {
512507
.sum()
513508
}
514509

515-
#[expect(clippy::significant_drop_tightening)]
516510
fn get_highest_memtable_seqno(&self) -> Option<SeqNo> {
517511
let version = self
518512
.version_history

0 commit comments

Comments
 (0)