Fix wal tag safety issues, and add debug assertion that we are reading the proper frames

This commit is contained in:
PThorpe92
2025-08-15 22:40:25 -04:00
parent 4100737358
commit e28a38abc5
3 changed files with 5 additions and 7 deletions

View File

@@ -287,6 +287,7 @@ impl Page {
self.get().wal_tag.store(TAG_UNSET, Ordering::Release)
}
#[inline]
pub fn is_valid_for_checkpoint(&self, target_frame: u64, seq: u32) -> bool {
let (f, s) = self.wal_tag_pair();
f == target_frame && s == seq && !self.is_dirty()

View File

@@ -912,6 +912,9 @@ pub fn finish_read_page(page_idx: usize, buffer_ref: Arc<Buffer>, page: PageRef)
page.get().contents.replace(inner);
page.clear_locked();
page.set_loaded();
// we set the wal tag only when reading page from log, or in allocate_page,
// we clear it here for safety in case page is being re-loaded.
page.clear_wal_tag();
}
}

View File

@@ -1375,12 +1375,6 @@ impl WalFile {
shared: Arc<UnsafeCell<WalFileShared>>,
buffer_pool: Arc<BufferPool>,
) -> Self {
let checkpoint_page = Arc::new(Page::new(0));
let buffer = buffer_pool.get_page();
{
checkpoint_page.get().contents = Some(PageContent::new(0, Arc::new(buffer)));
}
let header = unsafe { shared.get().as_mut().unwrap().wal_header.lock() };
let last_checksum = unsafe { (*shared.get()).last_checksum };
let disable_checkpoint_cache =
@@ -1813,7 +1807,7 @@ impl WalFile {
/// Must be invoked while writer and checkpoint locks are still held.
fn restart_log(&mut self, mode: CheckpointMode) -> Result<()> {
turso_assert!(
matches!(mode, CheckpointMode::Restart | CheckpointMode::Truncate),
mode.should_restart_log(),
"CheckpointMode must be Restart or Truncate"
);
turso_assert!(