Spool

Trait Spool 

Source
pub trait Spool: Send + Sync {
    // Required methods
    fn load<'life0, 'async_trait>(
        &'life0 self,
        id: SpoolId,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn remove<'life0, 'async_trait>(
        &'life0 self,
        id: SpoolId,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn store<'life0, 'async_trait>(
        &'life0 self,
        id: SpoolId,
        data: Arc<Box<[u8]>>,
        force_sync: bool,
        deadline: Option<Instant>,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn enumerate(
        &self,
        sender: Sender<SpoolEntry>,
        start_time: DateTime<Utc>,
    ) -> Result<()>;
    fn cleanup<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn shutdown<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn advise_low_memory<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<isize>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn compact<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn unhealthy_reason(&self) -> Option<&'static str> { ... }
}

Required Methods§

Source

fn load<'life0, 'async_trait>( &'life0 self, id: SpoolId, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Load the data corresponding to the provided Id

Source

fn remove<'life0, 'async_trait>( &'life0 self, id: SpoolId, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Remove the data associated with the provided Id

Source

fn store<'life0, 'async_trait>( &'life0 self, id: SpoolId, data: Arc<Box<[u8]>>, force_sync: bool, deadline: Option<Instant>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Write/Replace the data associated with the provided Id

Source

fn enumerate( &self, sender: Sender<SpoolEntry>, start_time: DateTime<Utc>, ) -> Result<()>

Scan the contents of the spool, and emit a SpoolEntry for each item to the provided channel sender. The items are enumerated in an unspecified order. It is recommended that you use a bounded channel.

The results are undefined if you enumerate concurrently with load/remove/store operations.

Source

fn cleanup<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Perform some periodic cleanup/maintenance

Source

fn shutdown<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Shutdown the store

Source

fn advise_low_memory<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<isize>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Called when system memory is low. The spool module should flush and drop caches. Returns the number of bytes that were saved, which might be negative if the flush actually increased the total.

Provided Methods§

Source

fn compact<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Synchronously flush in-memory buffers and run a full compaction of the underlying storage.

Intended for operational diagnostics and for tests that need to drive the storage into a deterministic state. Storage backends that do not have any concept of compaction may leave the default no-op implementation in place.

Errors are propagated to the caller. In particular, for rocksdb, a missing or corrupt SST file encountered during the operation surfaces as an Err.

Source

fn unhealthy_reason(&self) -> Option<&'static str>

Returns None when the spool is healthy. Returns Some(reason) when the spool is in a state that should cause ingress paths to shed load.

This is called from hot load-shedding paths and must be cheap: no I/O, no awaits, no allocation. The returned reason is the externally visible explanation and should be intentionally bland; it must not leak implementation details.

Implementors§