pub struct GroupCommitConsolidator { /* private fields */ }Expand description
The group commit consolidator accumulates frame batches from concurrent writers and flushes them to the WAL file in consolidated groups.
This struct manages the FILLING→FLUSHING→COMPLETE state machine.
It is designed to be held behind a Mutex and accessed by concurrent
writers through [GroupCommitQueue].
Implementations§
Source§impl GroupCommitConsolidator
impl GroupCommitConsolidator
Sourcepub fn new(config: GroupCommitConfig) -> Self
pub fn new(config: GroupCommitConfig) -> Self
Create a new consolidator with the given configuration.
Sourcepub const fn phase(&self) -> ConsolidationPhase
pub const fn phase(&self) -> ConsolidationPhase
Current consolidation phase.
Sourcepub const fn max_group_delay(&self) -> Duration
pub const fn max_group_delay(&self) -> Duration
Maximum time a batch may remain in the filling epoch before flush.
Sourcepub const fn pending_frame_count(&self) -> usize
pub const fn pending_frame_count(&self) -> usize
Number of pending frames in the current FILLING phase.
Sourcepub fn pending_batch_count(&self) -> usize
pub fn pending_batch_count(&self) -> usize
Number of pending transaction batches.
Sourcepub fn submit_batch(
&mut self,
batch: TransactionFrameBatch,
) -> Result<SubmitOutcome>
pub fn submit_batch( &mut self, batch: TransactionFrameBatch, ) -> Result<SubmitOutcome>
Submit a transaction’s frame batch for consolidation.
Returns Flusher if this writer should call flush_group, or
Waiter if this writer should wait for the flush to complete.
§Errors
Returns Err if the consolidator is in an unexpected phase.
Sourcepub fn should_flush_now(&self) -> bool
pub fn should_flush_now(&self) -> bool
Check whether the flusher should flush now.
Returns true if:
- The batch is full (
pending_frame_count >= max_group_size), OR - The max group delay has been exceeded.
Sourcepub fn time_until_flush(&self) -> Duration
pub fn time_until_flush(&self) -> Duration
Time remaining before the flusher must flush (for sleep/wait).
Sourcepub fn fill_age(&self) -> Duration
pub fn fill_age(&self) -> Duration
Age of the current FILLING epoch from the first submitted batch.
Sourcepub fn begin_flush(&mut self) -> Result<Vec<TransactionFrameBatch>>
pub fn begin_flush(&mut self) -> Result<Vec<TransactionFrameBatch>>
Transition to FLUSHING phase and take ownership of the pending batches.
Returns the batches to be written and the page size needed for frame construction.
§Errors
Returns Err if not in FILLING phase.
Sourcepub fn complete_flush(&mut self) -> Result<bool>
pub fn complete_flush(&mut self) -> Result<bool>
Mark the current flush as complete. Waiters can now proceed.
§Errors
Returns Err if not in FLUSHING phase.
Returns true if pipelined batches were promoted and the caller
should flush again. If the original flusher does not continue,
a fresh submitter may explicitly claim the promoted epoch via
Self::claim_flusher_vacancy.
Sourcepub fn has_pipelined_batches(&self) -> bool
pub fn has_pipelined_batches(&self) -> bool
Whether pipelined batches are waiting for the next epoch.
Sourcepub const fn has_flusher_vacancy(&self) -> bool
pub const fn has_flusher_vacancy(&self) -> bool
Whether a promoted epoch in Filling currently needs an explicit
flusher claim before a replacement flusher takes over.
Sourcepub fn claim_flusher_vacancy(&mut self) -> bool
pub fn claim_flusher_vacancy(&mut self) -> bool
Claim the promoted-epoch flusher vacancy after the original flusher
stopped before calling begin_flush() again.
Returns true if the caller successfully claimed the vacancy.
Sourcepub fn abort_flush(&mut self) -> Result<()>
pub fn abort_flush(&mut self) -> Result<()>
Abort the current flush after the flusher observed an I/O error.
This transitions the state machine out of Flushing so waiters can be
released with the epoch-level failure published by the caller.
§Errors
Returns Err if not in Flushing phase.
Sourcepub const fn completed_epoch(&self) -> u64
pub const fn completed_epoch(&self) -> u64
The completed epoch counter (for waiter synchronization).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for GroupCommitConsolidator
impl RefUnwindSafe for GroupCommitConsolidator
impl Send for GroupCommitConsolidator
impl Sync for GroupCommitConsolidator
impl Unpin for GroupCommitConsolidator
impl UnsafeUnpin for GroupCommitConsolidator
impl UnwindSafe for GroupCommitConsolidator
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
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