pub struct StorageBlockPacker {
pub packs: HashMap<u64, Pack>,
pub next_pack_id: u64,
pub config: PackerConfig,
}Expand description
Packs multiple small blocks into larger pack files for efficient storage.
Fields§
§packs: HashMap<u64, Pack>All packs, keyed by pack_id.
next_pack_id: u64The next pack_id to assign.
config: PackerConfigConfiguration controlling packing behavior.
Implementations§
Source§impl StorageBlockPacker
impl StorageBlockPacker
Sourcepub fn new(config: PackerConfig) -> Self
pub fn new(config: PackerConfig) -> Self
Creates a new StorageBlockPacker with the given configuration.
Sourcepub fn pack(&mut self, blocks: Vec<(String, u64)>, now_secs: u64) -> Vec<u64>
pub fn pack(&mut self, blocks: Vec<(String, u64)>, now_secs: u64) -> Vec<u64>
Packs a list of (cid, size_bytes) blocks into one or more pack files.
Only blocks where size_bytes < min_block_size_bytes are eligible.
Blocks are greedily packed: a new pack is started whenever the current
pack would exceed max_pack_size_bytes or max_entries_per_pack.
Returns the list of newly created pack IDs (empty if no eligible blocks).
Sourcepub fn find_pack(&self, cid: &str) -> Option<(&Pack, &PackEntry)>
pub fn find_pack(&self, cid: &str) -> Option<(&Pack, &PackEntry)>
Searches all packs for the given CID.
Returns Some((&Pack, &PackEntry)) if found, None otherwise.
Sourcepub fn get_pack(&self, pack_id: u64) -> Option<&Pack>
pub fn get_pack(&self, pack_id: u64) -> Option<&Pack>
Returns a reference to the pack with the given ID, or None.
Sourcepub fn delete_pack(&mut self, pack_id: u64) -> bool
pub fn delete_pack(&mut self, pack_id: u64) -> bool
Removes the pack with the given ID.
Returns true if the pack existed and was removed, false otherwise.
Sourcepub fn stats(&self) -> PackerStats
pub fn stats(&self) -> PackerStats
Computes aggregate statistics over all packs.
Auto Trait Implementations§
impl Freeze for StorageBlockPacker
impl RefUnwindSafe for StorageBlockPacker
impl Send for StorageBlockPacker
impl Sync for StorageBlockPacker
impl Unpin for StorageBlockPacker
impl UnsafeUnpin for StorageBlockPacker
impl UnwindSafe for StorageBlockPacker
Blanket Implementations§
impl<T> Allocation for T
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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