/
flushc.rs
35 lines (31 loc) 路 1.22 KB
/
flushc.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Sonic
//
// Fast, lightweight and schema-less search backend
// Copyright: 2019, Valerian Saliou <valerian@valeriansaliou.name>
// License: Mozilla Public License v2.0 (MPL v2.0)
use crate::store::fst::StoreFSTActionBuilder;
use crate::store::item::StoreItem;
use crate::store::kv::StoreKVActionBuilder;
pub struct ExecutorFlushC;
impl ExecutorFlushC {
pub fn execute(store: StoreItem) -> Result<u32, ()> {
// 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 {
// Acquire KV + FST locks in write mode, as we will erase them, we need to prevent any \
// other consumer to use them.
general_kv_access_lock_write!();
general_fst_access_lock_write!();
match (
StoreKVActionBuilder::erase(collection, None),
StoreFSTActionBuilder::erase(collection, None),
) {
(Ok(erase_count), Ok(_)) => Ok(erase_count),
_ => Err(()),
}
} else {
Err(())
}
}
}