pub struct StorageService { /* private fields */ }Expand description
Asynchronous storage service wrapping a single Backend.
StorageService is the main entry point for storing and retrieving objects.
It delegates all storage operations to the backend supplied at construction,
adding task spawning, panic isolation, and a concurrency limit on top.
The typical backend is TieredStorage,
which provides size-based routing to high-volume and long-term backends along
with redirect tombstone management. Any type implementing Backend can be used.
§Lifecycle
After construction, call start to start the
service’s background processes.
§Run-to-Completion and Panic Isolation
Each operation runs to completion even if the caller is cancelled (e.g., on
client disconnect). This ensures that multi-step operations in the backend
are never left partially applied. Post-commit cleanup (e.g. deleting
unreferenced long-term blobs) runs in background tasks so callers are not
blocked. Call join during shutdown to wait for
outstanding cleanup. Operations are also isolated from panics in backend
code — a failure in one operation does not bring down other in-flight work.
See Error::Panic.
§Concurrency Limit
A semaphore caps the number of in-flight backend operations. The limit is
configured via with_concurrency_limit;
without an explicit value the default is DEFAULT_CONCURRENCY_LIMIT.
Operations that exceed the limit are rejected immediately with
Error::AtCapacity.
Implementations§
Source§impl StorageService
impl StorageService
Sourcepub fn new(backend: Box<dyn Backend>) -> Self
pub fn new(backend: Box<dyn Backend>) -> Self
Creates a new StorageService wrapping the given backend.
Sourcepub fn with_concurrency_limit(self, max: usize) -> Self
pub fn with_concurrency_limit(self, max: usize) -> Self
Sets the maximum number of concurrent backend operations.
Must be called before start. Operations beyond this
limit are rejected with Error::AtCapacity.
Sourcepub fn tasks_available(&self) -> usize
pub fn tasks_available(&self) -> usize
Returns the number of backend task slots currently available.
Sourcepub fn tasks_running(&self) -> usize
pub fn tasks_running(&self) -> usize
Returns the number of backend tasks currently running.
Sourcepub fn tasks_limit(&self) -> usize
pub fn tasks_limit(&self) -> usize
Returns the configured limit for concurrent backend tasks.
Sourcepub fn stream(&self) -> Result<StreamExecutor>
pub fn stream(&self) -> Result<StreamExecutor>
Prepares to stream multiple operations concurrently against this service.
Operations are executed concurrently up to a window derived from the
service’s current capacity. The permits for that window are reserved
upfront — if the service is at capacity, this returns
Error::AtCapacity immediately before any operations are read.
Sourcepub fn start(&self)
pub fn start(&self)
Starts background processes for the storage service.
Currently spawns a task that emits the service.concurrency.in_use
and service.concurrency.limit gauges once per second.
Sourcepub async fn insert_object(
&self,
context: ObjectContext,
key: Option<String>,
metadata: Metadata,
stream: ClientStream,
) -> Result<InsertResponse>
pub async fn insert_object( &self, context: ObjectContext, key: Option<String>, metadata: Metadata, stream: ClientStream, ) -> Result<InsertResponse>
Creates or overwrites an object.
The object is identified by the components of an ObjectId. The
context is required, while the key can be assigned automatically if
set to None.
§Run-to-completion
Once called, the operation runs to completion even if the returned future is dropped (e.g., on client disconnect). This guarantees that partially written objects in the backend are never left in an inconsistent state.
Sourcepub async fn get_metadata(&self, id: ObjectId) -> Result<MetadataResponse>
pub async fn get_metadata(&self, id: ObjectId) -> Result<MetadataResponse>
Retrieves only the metadata for an object, without the payload.
Sourcepub async fn get_object(&self, id: ObjectId) -> Result<GetResponse>
pub async fn get_object(&self, id: ObjectId) -> Result<GetResponse>
Streams the contents of an object.
Sourcepub async fn delete_object(&self, id: ObjectId) -> Result<DeleteResponse>
pub async fn delete_object(&self, id: ObjectId) -> Result<DeleteResponse>
Deletes an object, if it exists.
§Run-to-completion
Once called, the operation runs to completion even if the returned future is dropped. This guarantees that multi-step delete sequences in the backend are never left partially applied.
Trait Implementations§
Source§impl Clone for StorageService
impl Clone for StorageService
Source§fn clone(&self) -> StorageService
fn clone(&self) -> StorageService
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for StorageService
impl !RefUnwindSafe for StorageService
impl Send for StorageService
impl Sync for StorageService
impl Unpin for StorageService
impl !UnwindSafe for StorageService
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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>
§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].