StorageManager

Struct StorageManager 

Source
pub struct StorageManager {
    pub meta: PouchMeta,
    pub index: FragmentIndex,
    /* private fields */
}
Expand description

Manages on-disk storage for a single Pouch service instance.

One StorageManager exists per active Pouch service. It is held inside DaemonState (wrapped in Arc<RwLock<StorageManager>>) alongside the service registry.

Fields§

§meta: PouchMeta

Persistent quota and usage tracking.

§index: FragmentIndex

In-memory fragment index (rebuilt from disk on load).

Implementations§

Source§

impl StorageManager

Source

pub fn init( network_id: String, service_id: String, storage_bytes_bid: u64, ) -> BpResult<Self>

Initialise a brand-new Pouch storage directory.

Creates the directory structure, writes meta.json, and returns a manager with an empty fragment index.

§Errors

Fails if disk I/O fails or the XDG base directory cannot be resolved.

Source

pub fn load(network_id: &str, service_id: &str) -> BpResult<Self>

Load an existing Pouch storage directory from disk.

Reads meta.json and rebuilds the fragment index by scanning the fragments/ subdirectory.

Source

pub fn store_fragment(&mut self, fragment: &EncodedFragment) -> BpResult<()>

Persist an encoded fragment to disk and update the index.

Returns an error if the Pouch does not have enough remaining capacity.

Source

pub fn load_fragment( &self, chunk_id: &str, fragment_id: &str, ) -> BpResult<EncodedFragment>

Load a fragment from disk by chunk_id and fragment_id.

Source

pub fn remove_fragment( &mut self, chunk_id: &str, fragment_id: &str, ) -> BpResult<()>

Remove a fragment from disk and update the index.

Source

pub fn recode_chunk( &self, chunk_id: &str, count: usize, ) -> BpResult<Vec<EncodedFragment>>

Generate count new fragments for chunk_id by recoding the local ones.

This is the key operation for filling new Pouches: no decoding is performed, no original data is required.

Returns an error if this Pouch holds no fragments for the given chunk.

Source

pub fn has_capacity(&self, bytes: u64) -> bool

Whether this Pouch has remaining capacity for bytes more data.

Source

pub fn root(&self) -> &Path

Root directory of this Pouch’s storage.

Source

pub fn purge(&self) -> BpResult<()>

Permanently delete all on-disk storage for this Pouch.

Removes the entire storage directory (fragments/, meta.json, etc.). Call only after the service has been removed from ServiceRegistry.

Source

pub fn storage_summary(&self) -> (usize, usize, u64)

Summary of what is stored: (chunk_count, fragment_count, total_bytes).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more