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<SubmitReceipt>
pub fn submit_batch( &mut self, batch: TransactionFrameBatch, ) -> Result<SubmitReceipt>
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_filling(&mut self, expected_epoch: u64) -> Result<u64>
pub fn abort_filling(&mut self, expected_epoch: u64) -> Result<u64>
Abort a not-yet-started filling epoch after its elected flusher is cancelled.
No WAL bytes have been written while the consolidator is still in
Filling, so every queued batch can fail atomically. The failed epoch
is consumed before returning; the next submitter therefore receives a
fresh target epoch instead of colliding with retained failure metadata.
§Errors
Returns Err unless the expected non-empty filling epoch is active.
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).