pub struct TreeClose { /* private fields */ }Expand description
The signal of a tree being closed, returned by
Tree::close and its counterparts.
A tree is closed once nothing of it owns a file of its directory or works in it any more: no tree handle, iterator, snapshot or pin holds it, its table file pool made its last file and the background deleter removed the last file it was handed. From then on the tree writes nothing into its directory, and removing the directory is safe.
The handle keeps nothing open itself, nor do the callbacks registered on it, so it can be held for as long as wanted.
Implementations§
Source§impl TreeClose
impl TreeClose
Sourcepub fn on_closed(&self, f: impl FnOnce() + Send + 'static)
pub fn on_closed(&self, f: impl FnOnce() + Send + 'static)
Runs f once the tree is closed, on the thread that finished closing
it, or at once on this thread if it is closed already. Nothing waits or
polls meanwhile: an async caller completes its own oneshot from it.
f runs inside the drop that closed the tree, so it should be short.
With std a panic in f is caught and logged, and the other
callbacks still run.
§Examples
use std::sync::mpsc;
let tree = lsm_tree::Config::new(
folder.path(),
lsm_tree::SequenceNumberCounter::default(),
lsm_tree::SequenceNumberCounter::default(),
)
.open()?;
let (closed, on_closed) = mpsc::channel();
// The receiver may be gone by then: a failed send is nothing to report.
tree.close().on_closed(move || {
let _ = closed.send(());
});
on_closed.recv()?;
std::fs::remove_dir_all(folder.path())?;Sourcepub fn wait(&self)
pub fn wait(&self)
Blocks until the tree is closed.
Blocks for good if the caller itself still holds a tree handle, an
iterator, a snapshot or a pin of the tree: drop them first, or use
on_closed.
§Examples
use lsm_tree::AbstractTree;
let tree = lsm_tree::Config::new(
folder.path(),
lsm_tree::SequenceNumberCounter::default(),
lsm_tree::SequenceNumberCounter::default(),
)
.open()?;
tree.insert("a", "1", 0);
tree.flush_active_memtable(0)?;
tree.close().wait();
std::fs::remove_dir_all(folder.path())?;Sourcepub fn wait_timeout(&self, timeout: Duration) -> bool
pub fn wait_timeout(&self, timeout: Duration) -> bool
Blocks until the tree is closed or timeout passes; whether it is
closed.
Returns false at the timeout while anything of the tree is held, the
caller’s own handles, iterators, snapshots and pins included.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for TreeClose
impl !UnwindSafe for TreeClose
impl Freeze for TreeClose
impl Send for TreeClose
impl Sync for TreeClose
impl Unpin for TreeClose
impl UnsafeUnpin for TreeClose
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more