Skip to content

Commit

Permalink
fixes #21
Browse files Browse the repository at this point in the history
Signed-off-by: Valerian Saliou <valerian@valeriansaliou.name>
  • Loading branch information
valeriansaliou committed Mar 7, 2019
1 parent cbcee23 commit 8c491e0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
11 changes: 6 additions & 5 deletions src/executor/flushc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ pub struct ExecutorFlushC;

impl ExecutorFlushC {
pub fn execute<'a>(store: StoreItem<'a>) -> Result<u64, ()> {
// Important: do not acquire the store from there, as otherwise it will remain open \
// even if dropped in the inner function, as this caller would still own a reference to \
// it.
if let StoreItem(collection, None, None) = store {
if let Ok(kv_store) = StoreKVPool::acquire(collection) {
return StoreKVActionBuilder::erase(kv_store);
}
StoreKVActionBuilder::erase(collection)
} else {
Err(())
}

Err(())
}
}
21 changes: 10 additions & 11 deletions src/store/kv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,10 @@ impl StoreKVActionBuilder {
action
}

pub fn erase(store: StoreKVBox) -> Result<u64, ()> {
let collection = &store.collection;
pub fn erase<'a, T: Into<&'a str>>(collection: T) -> Result<u64, ()> {
let collection_str = collection.into();

info!("erase requested on collection: {}", collection);
info!("erase requested on collection: {}", collection_str);

// Acquire write + access locks, and reference it in context
// Notice: write lock prevents database to be acquired from any context; while access lock \
Expand All @@ -247,22 +247,21 @@ impl StoreKVActionBuilder {
);

// Check if database storage directory exists
let collection_path = StoreKVBuilder::path(collection);
let collection_path = StoreKVBuilder::path(collection_str);

// TODO: the path always exists on MacOS, is this a Rust bug?
// @see: https://github.com/rust-lang/rust/issues/58989
if collection_path.exists() == true {
debug!(
"collection store exists, erasing collection: {} at path: {:?}",
collection, collection_path
collection_str, &collection_path
);

// Force a RocksDB database close
STORE_POOL.write().unwrap().remove(collection);
drop(store);
{
STORE_POOL.write().unwrap().remove(collection_str);
}

// Remove database storage from filesystem
let erase_result = fs::remove_dir_all(collection_path);
let erase_result = fs::remove_dir_all(&collection_path);

if erase_result.is_ok() == true {
debug!("done with collection erasure");
Expand All @@ -274,7 +273,7 @@ impl StoreKVActionBuilder {
} else {
debug!(
"collection store does not exist, consider already erased: {} at path: {:?}",
collection, collection_path
collection_str, &collection_path
);

Ok(0)
Expand Down

0 comments on commit 8c491e0

Please sign in to comment.