Minor improvement in flush api

This commit is contained in:
PThorpe92
2025-08-11 16:01:41 -04:00
parent 1f554c2707
commit e2896d2f95
2 changed files with 14 additions and 12 deletions

View File

@@ -975,8 +975,8 @@ pub fn write_pages_vectored(
// Create the atomic counters
let runs_left = Arc::new(AtomicUsize::new(run_count));
flush.new_flush();
let done = flush.done.clone();
done.store(false, Ordering::Release);
// we know how many runs, but we don't know how many buffers per run, so we can only give an
// estimate of the capacity
const EST_BUFF_CAPACITY: usize = 32;

View File

@@ -393,9 +393,19 @@ impl PendingFlush {
done: Arc::new(AtomicBool::new(true)),
}
}
fn clear(&mut self) {
pub(super) fn new_flush(&self) {
turso_assert!(
self.is_done(),
"should not reset new flush without being in done state"
);
self.done.store(false, Ordering::Release);
}
fn clear(&self) {
self.done.store(true, Ordering::Relaxed);
}
fn is_done(&self) -> bool {
self.done.load(Ordering::Acquire)
}
}
impl fmt::Debug for OngoingCheckpoint {
@@ -1476,12 +1486,7 @@ impl WalFile {
self.ongoing_checkpoint.state = CheckpointState::WaitFlush;
}
CheckpointState::WaitFlush => {
if !self
.ongoing_checkpoint
.pending_flush
.done
.load(Ordering::Acquire)
{
if !self.ongoing_checkpoint.pending_flush.is_done() {
return Ok(IOResult::IO);
}
tracing::debug!("finished checkpoint backfilling batch");
@@ -1503,10 +1508,7 @@ impl WalFile {
// Release all locks and return the current num of wal frames and the amount we backfilled
CheckpointState::Done => {
turso_assert!(
self.ongoing_checkpoint
.pending_flush
.done
.load(Ordering::Relaxed),
self.ongoing_checkpoint.pending_flush.is_done(),
"checkpoint pending flush must have finished"
);
let mut checkpoint_result = {