mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-05 00:04:23 +01:00
Fix wal tag safety issues, and add debug assertion that we are reading the proper frames
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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!(
|
||||
|
||||
Reference in New Issue
Block a user