core/wal: cache wal is initialized

This commit is contained in:
Pere Diaz Bou
2025-08-27 14:57:22 +00:00
parent b4eba8b456
commit db5e2883ee
2 changed files with 9 additions and 2 deletions

View File

@@ -1639,9 +1639,9 @@ pub fn read_entire_wal_dumb(file: &Arc<dyn File>) -> Result<Arc<UnsafeCell<WalFi
write_lock: TursoRwLock::new(),
loaded: AtomicBool::new(false),
checkpoint_lock: TursoRwLock::new(),
initialized: AtomicBool::new(false),
}));
let wal_file_shared_for_completion = wal_file_shared_ret.clone();
let complete: Box<ReadComplete> = Box::new(move |res: Result<(Arc<Buffer>, i32), _>| {
let Ok((buf, bytes_read)) = res else {
return;
@@ -1832,6 +1832,9 @@ pub fn read_entire_wal_dumb(file: &Arc<dyn File>) -> Result<Arc<UnsafeCell<WalFi
wfs_data.nbackfills.store(0, Ordering::SeqCst);
wfs_data.loaded.store(true, Ordering::SeqCst);
if size >= 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)?;

View File

@@ -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<bool> {
Ok(self.file.size()? >= WAL_HEADER_SIZE as u64)
Ok(self.initialized.load(Ordering::Acquire))
}
pub fn new_shared(file: Arc<dyn File>) -> Result<Arc<UnsafeCell<WalFileShared>>> {
@@ -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)))
}