pub struct BackingStore<B: BackingStoreT> { /* private fields */ }Expand description
A manager that wraps a BackingStoreT implementation, providing concurrency control,
task management via a Tokio runtime, and tracking of persisted paths.
It handles potential races and deduplication of tasks, ensuring that multiple tasks can safely operate on the same backing store without conflicts.
Implementations§
Source§impl<B: BackingStoreT> BackingStore<B>
impl<B: BackingStoreT> BackingStore<B>
Sourcepub fn new(backing: B, runtime: Handle) -> Self
pub fn new(backing: B, runtime: Handle) -> Self
Creates a new BackingStore manager.
§Arguments
backing- The low-level BackingStoreT implementation.runtime- A handle to a Tokio runtime used for spawning background tasks and managing async operations.
If all available blocking threads on this runtime are simultaneously attempting a
blocking_load, there can potentially be a deadlock. Either don’t directly call
spawn_blocking on this runtime or at least don’t saturate the blocking thread pool.
Alternatively don’t use this runtime to call the blocking_* functions within file-backed,
or else use a separate tokio runtime.
Sourcepub fn track_path(
self: &Arc<Self>,
path: B::PersistPath,
) -> JoinHandle<TrackedPath<B::PersistPath>>
pub fn track_path( self: &Arc<Self>, path: B::PersistPath, ) -> JoinHandle<TrackedPath<B::PersistPath>>
Asynchronously begins tracking the given persistence path.
It retrieves all keys currently persisted at the path using the iterator returned from
BackingStoreT::sanitize_path and returns a JoinHandle resolving to a TrackedPath
containing the path and keys.
Sourcepub fn blocking_track_path(
self: &Arc<Self>,
path: B::PersistPath,
) -> TrackedPath<B::PersistPath>
pub fn blocking_track_path( self: &Arc<Self>, path: B::PersistPath, ) -> TrackedPath<B::PersistPath>
Blocking version of track_path. Waits for the path tracking to complete.
Must not be called from an async context that isn’t allowed to block.
Sourcepub fn spawn_blocking<R: Send + 'static>(
self: &Arc<Self>,
f: impl FnOnce() -> R + Send + 'static,
) -> JoinHandle<R>
pub fn spawn_blocking<R: Send + 'static>( self: &Arc<Self>, f: impl FnOnce() -> R + Send + 'static, ) -> JoinHandle<R>
Spawns a blocking function f onto the store’s managed Tokio runtime’s blocking pool.
Returns a JoinHandle to await the result R.
Sourcepub fn task_tracker(&self) -> &TaskTracker
pub fn task_tracker(&self) -> &TaskTracker
Returns a reference to the underlying TaskTracker used for detecting
when all background tasks have completed.
Sourcepub async fn finished(&self)
pub async fn finished(&self)
Returns a future that completes when all background tasks currently queued or
running within this BackingStore instance have finished.
This includes tasks like delayed deletions or background flushes.
Sourcepub fn sync(
self: &Arc<Self>,
tracked: &Arc<TrackedPath<B::PersistPath>>,
) -> JoinHandle<()>
pub fn sync( self: &Arc<Self>, tracked: &Arc<TrackedPath<B::PersistPath>>, ) -> JoinHandle<()>
Asynchronously triggers the underlying BackingStoreT::sync_persisted
operation for the given tracked path.
Returns a JoinHandle that completes when the sync operation is done.
Sourcepub fn blocking_sync(&self, path: &B::PersistPath)
pub fn blocking_sync(&self, path: &B::PersistPath)
Blocking version of sync. Calls BackingStoreT::sync_persisted and waits for completion.
Must not be called from an async context that isn’t allowed to block.
Sourcepub fn delete_persisted(
self: &Arc<Self>,
tracked: &Arc<TrackedPath<B::PersistPath>>,
key: Uuid,
) -> JoinHandle<()>
pub fn delete_persisted( self: &Arc<Self>, tracked: &Arc<TrackedPath<B::PersistPath>>, key: Uuid, ) -> JoinHandle<()>
Asynchronously triggers the underlying BackingStoreT::delete_persisted
operation for the given key at the tracked path.
Returns a JoinHandle that completes when the deletion is done.
Sourcepub fn blocking_delete_persisted(
&self,
tracked: &TrackedPath<B::PersistPath>,
key: Uuid,
)
pub fn blocking_delete_persisted( &self, tracked: &TrackedPath<B::PersistPath>, key: Uuid, )
Blocking version of delete_persisted. Calls BackingStoreT::delete_persisted
and waits for completion.
Must not be called from an async context that isn’t allowed to block.