From 79b182af08584ac21bd8ad08b4190509a575aaa9 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Fri, 31 Aug 2018 20:49:27 +0300 Subject: [PATCH] Add full compaction helpers to `store` module --- src/store.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/store.rs b/src/store.rs index acc988d..53de6b6 100644 --- a/src/store.rs +++ b/src/store.rs @@ -142,3 +142,22 @@ impl Drop for DBStore { trace!("closing DB at {:?}", self.opts.path); } } + +fn full_compaction_marker() -> Row { + Row { + key: b"F".to_vec(), + value: b"".to_vec(), + } +} + +pub fn full_compaction(store: DBStore) -> DBStore { + store.flush(); + let store = store.compact().enable_compaction(); + store.write(vec![full_compaction_marker()]); + store +} + +pub fn is_fully_compacted(store: &ReadStore) -> bool { + let marker = store.get(&full_compaction_marker().key); + marker.is_some() +}