Skip to content

Commit d988b6b

Browse files
Fixes
Signed-off-by: Valerian Saliou <valerian@valeriansaliou.name>
1 parent 49f3efd commit d988b6b

File tree

3 files changed

+46
-49
lines changed

3 files changed

+46
-49
lines changed

config.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
[server]
88

9-
log_level = "error"
9+
log_level = "debug"
1010

1111

1212
[channel]

src/executor/flushb.rs

+41-12
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,54 @@
66

77
use crate::store::fst::StoreFSTActionBuilder;
88
use crate::store::item::StoreItem;
9-
use crate::store::kv::StoreKVActionBuilder;
9+
use crate::store::kv::{StoreKVAcquireMode, StoreKVActionBuilder, StoreKVPool};
1010

1111
pub struct ExecutorFlushB;
1212

1313
impl ExecutorFlushB {
1414
pub fn execute<'a>(store: StoreItem<'a>) -> Result<u32, ()> {
15-
// Important: do not acquire the store from there, as otherwise it will remain open \
16-
// even if dropped in the inner function, as this caller would still own a reference to \
17-
// it.
1815
if let StoreItem(collection, Some(bucket), None) = store {
19-
match (
20-
StoreKVActionBuilder::erase(collection, Some(bucket)),
21-
StoreFSTActionBuilder::erase(collection, Some(bucket)),
22-
) {
23-
(Ok(erase_count), Ok(_)) => Ok(erase_count),
24-
_ => Err(()),
16+
// Important: acquire database access read lock, and reference it in context. This \
17+
// prevents the database from being erased while using it in this block.
18+
general_kv_access_lock_read!();
19+
20+
if let Ok(kv_store) = StoreKVPool::acquire(StoreKVAcquireMode::OpenOnly, collection) {
21+
// Important: acquire bucket store write lock
22+
executor_kv_lock_write!(kv_store);
23+
24+
if kv_store.is_some() == true {
25+
// Store exists, proceed erasure.
26+
debug!(
27+
"collection store exists, erasing: {} from {}",
28+
bucket.as_str(),
29+
collection.as_str()
30+
);
31+
32+
let kv_action = StoreKVActionBuilder::access(bucket, kv_store);
33+
34+
// Notice: we cannot use the provided KV bucket erasure helper there, as \
35+
// erasing a bucket requires a database lock, which would incur a dead-lock, \
36+
// thus we need to perform the erasure from there.
37+
if let Ok(erase_count) = kv_action.batch_erase_bucket() {
38+
if StoreFSTActionBuilder::erase(collection, Some(bucket)).is_ok() == true {
39+
debug!("done with bucket erasure");
40+
41+
return Ok(erase_count);
42+
}
43+
}
44+
} else {
45+
// Store does not exist, consider as already erased.
46+
debug!(
47+
"collection store does not exist, consider {} from {} already erased",
48+
bucket.as_str(),
49+
collection.as_str()
50+
);
51+
52+
return Ok(0);
53+
}
2554
}
26-
} else {
27-
Err(())
2855
}
56+
57+
Err(())
2958
}
3059
}

src/store/kv.rs

+4-36
Original file line numberDiff line numberDiff line change
@@ -269,43 +269,11 @@ impl StoreGenericActionBuilder for StoreKVActionBuilder {
269269
}
270270

271271
fn proceed_erase_bucket<'a>(
272-
collection: StoreItemPart<'a>,
273-
bucket: StoreItemPart<'a>,
272+
_collection: StoreItemPart<'a>,
273+
_bucket: StoreItemPart<'a>,
274274
) -> Result<u32, ()> {
275-
debug!(
276-
"sub-erase on kv bucket: {} for collection: {}",
277-
bucket.as_str(),
278-
collection.as_str()
279-
);
280-
281-
if let Ok(kv_store) = StoreKVPool::acquire(StoreKVAcquireMode::OpenOnly, collection) {
282-
if kv_store.is_some() == true {
283-
// Store exists, proceed erasure.
284-
debug!(
285-
"kv collection store exists, erasing: {} from {}",
286-
bucket.as_str(),
287-
collection.as_str()
288-
);
289-
290-
let kv_action = Self::access(bucket, kv_store);
291-
292-
if let Ok(erase_count) = kv_action.batch_erase_bucket() {
293-
debug!("done with kv bucket erasure");
294-
295-
return Ok(erase_count);
296-
}
297-
} else {
298-
// Store does not exist, consider as already erased.
299-
debug!(
300-
"kv collection store does not exist, consider {} from {} already erased",
301-
bucket.as_str(),
302-
collection.as_str()
303-
);
304-
305-
return Ok(0);
306-
}
307-
}
308-
275+
// This one is not implemented, as we need to acquire the collection; which would cause \
276+
// a party-killer dead-lock.
309277
Err(())
310278
}
311279
}

0 commit comments

Comments
 (0)