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: PouchMetaPersistent quota and usage tracking.
index: FragmentIndexIn-memory fragment index (rebuilt from disk on load).
Implementations§
Source§impl StorageManager
impl StorageManager
Sourcepub fn init(
network_id: String,
service_id: String,
storage_bytes_bid: u64,
) -> BpResult<Self>
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.
Sourcepub fn load(network_id: &str, service_id: &str) -> BpResult<Self>
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.
Sourcepub fn store_fragment(&mut self, fragment: &EncodedFragment) -> BpResult<()>
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.
Sourcepub fn load_fragment(
&self,
chunk_id: &str,
fragment_id: &str,
) -> BpResult<EncodedFragment>
pub fn load_fragment( &self, chunk_id: &str, fragment_id: &str, ) -> BpResult<EncodedFragment>
Load a fragment from disk by chunk_id and fragment_id.
Sourcepub fn remove_fragment(
&mut self,
chunk_id: &str,
fragment_id: &str,
) -> BpResult<()>
pub fn remove_fragment( &mut self, chunk_id: &str, fragment_id: &str, ) -> BpResult<()>
Remove a fragment from disk and update the index.
Sourcepub fn recode_chunk(
&self,
chunk_id: &str,
count: usize,
) -> BpResult<Vec<EncodedFragment>>
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.
Sourcepub fn has_capacity(&self, bytes: u64) -> bool
pub fn has_capacity(&self, bytes: u64) -> bool
Whether this Pouch has remaining capacity for bytes more data.
Sourcepub fn purge(&self) -> BpResult<()>
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.
Sourcepub fn storage_summary(&self) -> (usize, usize, u64)
pub fn storage_summary(&self) -> (usize, usize, u64)
Summary of what is stored: (chunk_count, fragment_count, total_bytes).
Auto Trait Implementations§
impl Freeze for StorageManager
impl RefUnwindSafe for StorageManager
impl Send for StorageManager
impl Sync for StorageManager
impl Unpin for StorageManager
impl UnwindSafe for StorageManager
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