pub struct StorageCompactor { /* private fields */ }Expand description
Background compaction manager.
Maintains a set of storage regions described by (offset, size, is_used)
tuples and can analyse/compact them on demand.
Implementations§
Source§impl StorageCompactor
impl StorageCompactor
Sourcepub fn new(config: CompactorConfig) -> Self
pub fn new(config: CompactorConfig) -> Self
Create a new compactor with the given configuration.
Sourcepub fn add_region(&mut self, offset: u64, size: u64, is_used: bool)
pub fn add_region(&mut self, offset: u64, size: u64, is_used: bool)
Register a storage region.
Sourcepub fn remove_region(&mut self, offset: u64) -> bool
pub fn remove_region(&mut self, offset: u64) -> bool
Remove the region at the given offset.
Returns true if a region was found and removed.
Sourcepub fn analyze(&mut self) -> FragmentationReport
pub fn analyze(&mut self) -> FragmentationReport
Analyse the current region set and return a fragmentation report.
Sets the compactor state to CompactionState::Analyzing during the
call and back to CompactionState::Idle afterwards (unless the
compactor was already in a terminal state).
Sourcepub fn should_compact(&self) -> bool
pub fn should_compact(&self) -> bool
Returns true if compaction should be triggered based on the current
fragmentation ratio and the configured interval.
Sourcepub fn compact(&mut self) -> Result<CompactionResult, String>
pub fn compact(&mut self) -> Result<CompactionResult, String>
Run compaction: sort regions by offset, merge adjacent free regions.
Returns an error if the compactor is already in the Compacting state.
Sourcepub fn reclaimed_bytes(&self) -> u64
pub fn reclaimed_bytes(&self) -> u64
Total bytes reclaimed across all compaction runs.
Sourcepub fn stats(&self) -> CompactorStats
pub fn stats(&self) -> CompactorStats
Return a snapshot of the compactor’s cumulative statistics.
Auto Trait Implementations§
impl Freeze for StorageCompactor
impl RefUnwindSafe for StorageCompactor
impl Send for StorageCompactor
impl Sync for StorageCompactor
impl Unpin for StorageCompactor
impl UnsafeUnpin for StorageCompactor
impl UnwindSafe for StorageCompactor
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