Fix: use either db_size>0 or wal max frame>0 to decide when to read schema

This commit is contained in:
Jussi Saurio
2025-06-18 10:40:54 +03:00
committed by Diego Reis
parent ba3bfa058d
commit 2dc9b1cf7f
2 changed files with 9 additions and 7 deletions

View File

@@ -60,7 +60,7 @@ use std::{
num::NonZero,
ops::Deref,
rc::Rc,
sync::Arc,
sync::{atomic::Ordering, Arc},
};
use storage::btree::btree_init_page;
#[cfg(feature = "fs")]
@@ -159,7 +159,9 @@ impl Database {
} else {
None
};
let wal_exists = maybe_shared_wal.is_some();
let wal_has_frames = maybe_shared_wal.as_ref().map_or(false, |wal| {
unsafe { &*wal.get() }.max_frame.load(Ordering::SeqCst) > 0
});
let shared_page_cache = Arc::new(RwLock::new(DumbLruPageCache::default()));
let schema = Arc::new(RwLock::new(Schema::new()));
@@ -174,7 +176,7 @@ impl Database {
open_flags: flags,
};
let db = Arc::new(db);
if db_size > 0 || wal_exists {
if db_size > 0 || wal_has_frames {
// parse schema
let conn = db.connect()?;
let rows = conn.query("SELECT * FROM sqlite_schema")?;

View File

@@ -1683,11 +1683,11 @@ pub fn op_transaction(
if conn._db.open_flags.contains(OpenFlags::ReadOnly) {
return Err(LimboError::ReadOnly);
}
}
// We allocate the first page lazily in the *first* write transaction
if conn.pager.is_empty.load(Ordering::SeqCst) {
conn.pager.allocate_page1()?;
}
// We allocate the first page lazily in the first transaction
if conn.pager.is_empty.load(Ordering::SeqCst) {
conn.pager.allocate_page1()?;
}
if let Some(mv_store) = &mv_store {