From db5e2883ee2169fafa44d7682d5ed954d75e1cfe Mon Sep 17 00:00:00 2001 From: Pere Diaz Bou Date: Wed, 27 Aug 2025 14:57:22 +0000 Subject: [PATCH] core/wal: cache wal is initialized --- core/storage/sqlite3_ondisk.rs | 5 ++++- core/storage/wal.rs | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/core/storage/sqlite3_ondisk.rs b/core/storage/sqlite3_ondisk.rs index 8ca674cef..94c5a4215 100644 --- a/core/storage/sqlite3_ondisk.rs +++ b/core/storage/sqlite3_ondisk.rs @@ -1639,9 +1639,9 @@ pub fn read_entire_wal_dumb(file: &Arc) -> Result = Box::new(move |res: Result<(Arc, i32), _>| { let Ok((buf, bytes_read)) = res else { return; @@ -1832,6 +1832,9 @@ pub fn read_entire_wal_dumb(file: &Arc) -> Result= WAL_HEADER_SIZE as u64 { + wfs_data.initialized.store(true, Ordering::SeqCst); + } }); let c = Completion::new_read(buf_for_pread, complete); let _c = file.pread(0, c)?; diff --git a/core/storage/wal.rs b/core/storage/wal.rs index 3f1d09571..cdaac1f99 100644 --- a/core/storage/wal.rs +++ b/core/storage/wal.rs @@ -682,6 +682,7 @@ pub struct WalFileShared { /// Serialises checkpointer threads, only one checkpoint can be in flight at any time. Blocking and exclusive only pub checkpoint_lock: TursoRwLock, pub loaded: AtomicBool, + pub initialized: AtomicBool, } impl fmt::Debug for WalFileShared { @@ -1640,6 +1641,7 @@ impl WalFile { )?)?; self.io .wait_for_completion(shared.file.sync(Completion::new_sync(|_| {}))?)?; + shared.initialized.store(true, Ordering::Release); Ok(()) } @@ -2046,6 +2048,7 @@ impl WalFile { .file .truncate(0, c) .inspect_err(|e| unlock(Some(e)))?; + shared.initialized.store(false, Ordering::Release); self.io .wait_for_completion(c) .inspect_err(|e| unlock(Some(e)))?; @@ -2150,7 +2153,7 @@ impl WalFileShared { } pub fn is_initialized(&self) -> Result { - Ok(self.file.size()? >= WAL_HEADER_SIZE as u64) + Ok(self.initialized.load(Ordering::Acquire)) } pub fn new_shared(file: Arc) -> Result>> { @@ -2190,6 +2193,7 @@ impl WalFileShared { write_lock: TursoRwLock::new(), checkpoint_lock: TursoRwLock::new(), loaded: AtomicBool::new(true), + initialized: AtomicBool::new(false), }; Ok(Arc::new(UnsafeCell::new(shared))) }