Struct tor_persist::state_dir::InstanceStateHandle
source · pub struct InstanceStateHandle { /* private fields */ }
state-dir
only.Expand description
State or cache directory for an instance of a facility
Implies exclusive access:
there is only one InstanceStateHandle
at a time,
across any number of processes, tasks, and threads,
for the same instance.
§Key uniqueness and syntactic restrictions
Methods on InstanceStateHandle
typically take a TryIntoSlug
.
It is important that keys are distinct within an instance.
Specifically:
each key provided to a method on the same InstanceStateHandle
(or a clone of it)
must be different.
Violating this rule does not result in memory-unsafety,
but might result in incorrect operation due to concurrent filesystem access,
including possible data loss and corruption.
(Typically, the key is fixed, and the StorageHandle
s are usually
obtained during instance construction, so ensuring this is straightforward.)
There are also syntactic restrictions on keys. See slug.
Implementations§
source§impl InstanceStateHandle
impl InstanceStateHandle
sourcepub fn storage_handle<T>(
&self,
key: &(impl TryIntoSlug + ?Sized)
) -> Result<StorageHandle<T>>
pub fn storage_handle<T>( &self, key: &(impl TryIntoSlug + ?Sized) ) -> Result<StorageHandle<T>>
Obtain a StorageHandle
, usable for storing/retrieving a T
sourcepub fn raw_subdir(
&self,
key: &(impl TryIntoSlug + ?Sized)
) -> Result<InstanceRawSubdir>
pub fn raw_subdir( &self, key: &(impl TryIntoSlug + ?Sized) ) -> Result<InstanceRawSubdir>
Obtain a raw filesystem subdirectory, within the directory for this instance
This API is unsuitable platforms without a filesystem accessible via std::fs
.
May therefore only be used within Arti for features
where we’re happy to not to support such platforms (eg WASM without WASI)
without substantial further work.
sourcepub fn purge(self) -> Result<()>
pub fn purge(self) -> Result<()>
Unconditionally delete this instance directory
For expiry, use StateDirectory::purge_instances
,
and then call this in the dispose
method.
Will return a BadAPIUsage
if other clones of this InstanceStateHandle
exist.
§Deletion is not atomic
If a deletion operation doesn’t complete for any reason (maybe it was interrupted, or there was a filesystem access problem), part of the instance contents may remain.
After such an interrupted deletion,
storage items (StorageHandle
) are might each independently
be deleted (load
returns None
)
or retained (Some
).
Deletion of the contents of raw subdirectories
(InstanceStateHandle::raw_subdir
)
is done with std::fs::remove_dir_all
.
If deletion is interrupted, the raw subdirectory may contain partial contents.
Trait Implementations§
source§impl Clone for InstanceStateHandle
impl Clone for InstanceStateHandle
source§fn clone(&self) -> InstanceStateHandle
fn clone(&self) -> InstanceStateHandle
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl ContainsInstanceStateGuard for InstanceStateHandle
impl ContainsInstanceStateGuard for InstanceStateHandle
source§fn raw_lock_guard(&self) -> Arc<LockFileGuard>
fn raw_lock_guard(&self) -> Arc<LockFileGuard>
Auto Trait Implementations§
impl Freeze for InstanceStateHandle
impl RefUnwindSafe for InstanceStateHandle
impl Send for InstanceStateHandle
impl Sync for InstanceStateHandle
impl Unpin for InstanceStateHandle
impl UnwindSafe for InstanceStateHandle
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<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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