Skip to content

Commit

Permalink
addad Memtable::clear
Browse files Browse the repository at this point in the history
  • Loading branch information
marvin-j97 committed Sep 14, 2024
1 parent 608e69f commit 0871c05
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/memtable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ where
#[derive(Default)]
pub struct Memtable {
#[doc(hidden)]
items: SkipMap<InternalKey, UserValue>,
pub items: SkipMap<InternalKey, UserValue>,

/// Approximate active memtable size
///
Expand All @@ -45,6 +45,13 @@ pub struct Memtable {
}

impl Memtable {
/// Clears the memtable.
pub fn clear(&mut self) {
self.items.clear();
self.approximate_size
.store(0, std::sync::atomic::Ordering::Release);
}

/// Creates an iterator over all items.
pub fn iter(&self) -> impl DoubleEndedIterator<Item = InternalValue> + '_ {
self.items.iter().map(|entry| InternalValue {
Expand Down
7 changes: 4 additions & 3 deletions src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ impl AbstractTree for Tree {
})?;

for segment in segments {
log::trace!("releasing sealed memtable {}", segment.metadata.id);
sealed_memtables.remove(segment.metadata.id);
}

Expand Down Expand Up @@ -239,13 +240,13 @@ impl AbstractTree for Tree {
log::trace!("rotate: acquiring active memtable write lock");
let mut active_memtable = self.lock_active_memtable();

log::trace!("rotate: acquiring sealed memtables write lock");
let mut sealed_memtables = self.lock_sealed_memtables();

if active_memtable.is_empty() {
return None;
}

log::trace!("rotate: acquiring sealed memtables write lock");
let mut sealed_memtables = self.lock_sealed_memtables();

let yanked_memtable = std::mem::take(&mut *active_memtable);
let yanked_memtable = Arc::new(yanked_memtable);

Expand Down

0 comments on commit 0871c05

Please sign in to comment.