sonic/executor/flushc.rs
1// Sonic
2//
3// Fast, lightweight and schema-less search backend
4// Copyright: 2019, Valerian Saliou <valerian@valeriansaliou.name>
5// Copyright: 2026, Rémi Bardon <remi@remibardon.name>
6// License: Mozilla Public License v2.0 (MPL v2.0)
7
8use crate::store::StoreItem;
9use crate::store::kv::StoreKVActionBuilder;
10
11impl super::Executor {
12 pub fn flushc(&self, item: StoreItem) -> Result<u32, ()> {
13 // Important: do not acquire the store from there, as otherwise it will remain open \
14 // even if dropped in the inner function, as this caller would still own a reference to \
15 // it.
16 if let StoreItem(collection, None, None) = item {
17 // Acquire KV + FST locks in write mode, as we will erase them, we need to prevent any \
18 // other consumer to use them.
19 let _kv_write_guard = self.kv_pool.lock_write_access();
20 let _fst_write_guard = self.fst_pool.lock_write_access();
21
22 let kv_action_builder = StoreKVActionBuilder {
23 kv_pool: &self.kv_pool,
24 };
25
26 match (
27 kv_action_builder.erase(collection, None),
28 self.fst_pool.erase(collection, None),
29 ) {
30 (Ok(erase_count), Ok(_)) => Ok(erase_count),
31 _ => Err(()),
32 }
33 } else {
34 Err(())
35 }
36 }
37}