pub struct CompactionScheduler { /* private fields */ }Expand description
Lock-free compaction scheduler for Sled block stores.
All mutable state is held in atomics so Arc<CompactionScheduler> is
safely shared across threads and async tasks without a mutex.
Implementations§
Source§impl CompactionScheduler
impl CompactionScheduler
Sourcepub fn new(config: CompactionConfig) -> Arc<Self> ⓘ
pub fn new(config: CompactionConfig) -> Arc<Self> ⓘ
Create a new scheduler wrapped in an Arc.
Sourcepub fn record_write(&self, bytes: usize)
pub fn record_write(&self, bytes: usize)
Record a write of bytes bytes.
Updates the “last operation” timestamp and the byte counter that feeds the bytes-threshold trigger.
Sourcepub fn should_compact(&self) -> bool
pub fn should_compact(&self) -> bool
Returns true when the scheduler recommends a compaction be triggered.
Specifically it returns true when all of the following hold:
- No compaction is already in-flight (
!is_compacting). - The bytes threshold is exceeded or (the store has been idle long enough and the minimum inter-compaction interval has been met).
Sourcepub fn mark_compaction_started(&self) -> bool
pub fn mark_compaction_started(&self) -> bool
Attempt to claim the compaction lock.
Uses a compare-and-swap to atomically transition is_compacting from
false to true. Returns true when the caller won the race (they
should proceed with the compaction); returns false if another goroutine
is already compacting.
Sourcepub fn mark_compaction_done(&self)
pub fn mark_compaction_done(&self)
Release the compaction lock and update post-compaction bookkeeping.
Resets the bytes counter, updates the last-compaction timestamp, and increments the compaction count before clearing the in-flight flag.
Sourcepub fn compaction_count(&self) -> u64
pub fn compaction_count(&self) -> u64
Total number of completed compactions.
Sourcepub fn bytes_since_last_compaction(&self) -> u64
pub fn bytes_since_last_compaction(&self) -> u64
Bytes written to the store since the last compaction completed.
Sourcepub fn idle_duration(&self) -> Duration
pub fn idle_duration(&self) -> Duration
Duration since the last recorded write operation.
Sourcepub fn time_since_last_compaction(&self) -> Duration
pub fn time_since_last_compaction(&self) -> Duration
Duration since the last compaction completed.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for CompactionScheduler
impl RefUnwindSafe for CompactionScheduler
impl Send for CompactionScheduler
impl Sync for CompactionScheduler
impl Unpin for CompactionScheduler
impl UnsafeUnpin for CompactionScheduler
impl UnwindSafe for CompactionScheduler
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