pub struct StorageBlockCompactor {
pub fragments: HashMap<u64, BlockFragment>,
pub config: CompactorConfig,
pub stats: CompactorStats,
pub next_segment_id: u64,
}Expand description
Merges small fragmented blocks into larger compacted segments.
Fields§
§fragments: HashMap<u64, BlockFragment>Registered fragments keyed by block_id.
config: CompactorConfigCompactor configuration.
stats: CompactorStatsAccumulated statistics.
next_segment_id: u64Counter for generating unique segment IDs.
Implementations§
Source§impl StorageBlockCompactor
impl StorageBlockCompactor
Sourcepub fn new(config: CompactorConfig) -> Self
pub fn new(config: CompactorConfig) -> Self
Creates a new StorageBlockCompactor with the given configuration.
Sourcepub fn register_block(
&mut self,
block_id: u64,
cid: String,
size_bytes: u64,
tick: u64,
)
pub fn register_block( &mut self, block_id: u64, cid: String, size_bytes: u64, tick: u64, )
Registers a block as a compaction candidate.
Only blocks with size_bytes < min_block_size_to_compact are registered;
larger blocks are silently skipped.
Sourcepub fn touch(&mut self, block_id: u64, tick: u64) -> bool
pub fn touch(&mut self, block_id: u64, tick: u64) -> bool
Updates the last_accessed_tick for a registered block.
Returns true if the block was found and updated, false otherwise.
Sourcepub fn plan_compaction(&mut self) -> CompactionPlan
pub fn plan_compaction(&mut self) -> CompactionPlan
Produces a compaction plan by greedily grouping fragments into segments.
Fragments are sorted by size (ascending), then by block_id (ascending) for stable ordering. Segments with fewer than 2 blocks are excluded from the plan.
Sourcepub fn remove_block(&mut self, block_id: u64) -> bool
pub fn remove_block(&mut self, block_id: u64) -> bool
Removes a registered block fragment.
Returns true if the block was present and removed, false otherwise.
Sourcepub fn fragmentation_ratio(&self) -> f64
pub fn fragmentation_ratio(&self) -> f64
Returns the fragmentation ratio: blocks smaller than target_segment_bytes / 2
divided by total registered blocks.
Returns 0.0 if no fragments are registered.
Sourcepub fn stats(&self) -> &CompactorStats
pub fn stats(&self) -> &CompactorStats
Returns a reference to the accumulated statistics.
Auto Trait Implementations§
impl Freeze for StorageBlockCompactor
impl RefUnwindSafe for StorageBlockCompactor
impl Send for StorageBlockCompactor
impl Sync for StorageBlockCompactor
impl Unpin for StorageBlockCompactor
impl UnsafeUnpin for StorageBlockCompactor
impl UnwindSafe for StorageBlockCompactor
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