tuwunel_database/map/clear.rs
1use std::sync::Arc;
2
3use futures::{Stream, TryStreamExt};
4use tuwunel_core::{
5 Result, implement,
6 utils::stream::{ReadyExt, TryIgnore},
7};
8
9use crate::keyval::Key;
10
11/// Deletes all entries that exist when the clear scan begins.
12///
13/// The operation scans a consistent iterator view, so later writes can remain.
14/// When debug assertions are disabled, scan errors are filtered after any
15/// preceding keys have been removed.
16///
17/// # Panics
18///
19/// Panics if a scan error occurs with debug assertions enabled, RocksDB rejects
20/// a deletion, or an uncorked flush fails.
21#[implement(super::Map)]
22#[tracing::instrument(level = "trace")]
23pub async fn clear(self: &Arc<Self>) {
24 self.for_clear()
25 .ignore_err()
26 .ready_for_each(|_| ())
27 .await;
28}
29
30/// Deletes each entry visible to a clear scan and yields its key.
31///
32/// The iterator view is fixed when the stream begins, so later writes can
33/// remain. Polling drives deletion and exposes scan errors to the caller. Each
34/// yielded key borrows cursor storage and must not be retained across another
35/// poll.
36///
37/// # Panics
38///
39/// Panics if RocksDB rejects a deletion or an uncorked flush fails.
40#[implement(super::Map)]
41#[tracing::instrument(level = "trace")]
42pub fn for_clear(self: &Arc<Self>) -> impl Stream<Item = Result<Key<'_>>> + Send {
43 self.raw_keys().inspect_ok(|key| self.remove(key))
44}