mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-05 00:04:23 +01:00
minor improvements based on PR comments
This commit is contained in:
13
core/lib.rs
13
core/lib.rs
@@ -179,7 +179,6 @@ impl Database {
|
||||
) -> Result<Arc<Database>> {
|
||||
let wal_path = format!("{path}-wal");
|
||||
let maybe_shared_wal = WalFileShared::open_shared_if_exists(&io, wal_path.as_str())?;
|
||||
let db_size = db_file.size()?;
|
||||
|
||||
let mv_store = if enable_mvcc {
|
||||
Some(Rc::new(MvStore::new(
|
||||
@@ -189,12 +188,9 @@ impl Database {
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let wal_has_frames = maybe_shared_wal
|
||||
.as_ref()
|
||||
.is_some_and(|wal| unsafe { &*wal.get() }.max_frame.load(Ordering::SeqCst) > 0);
|
||||
|
||||
// No pages in DB file or WAL -> empty database
|
||||
let db_state = if db_size == 0 && !wal_has_frames {
|
||||
let db_size = db_file.size()?;
|
||||
let db_state = if db_size == 0 {
|
||||
DB_STATE_UNINITIALIZED
|
||||
} else {
|
||||
DB_STATE_INITIALIZED
|
||||
@@ -228,10 +224,9 @@ impl Database {
|
||||
.expect("lock on schema should succeed first try");
|
||||
|
||||
let syms = conn.syms.borrow();
|
||||
let pager = conn.pager.borrow().clone();
|
||||
|
||||
if let Err(LimboError::ExtensionError(e)) =
|
||||
schema.make_from_btree(None, conn.pager.clone(), &syms)
|
||||
{
|
||||
if let Err(LimboError::ExtensionError(e)) = schema.make_from_btree(None, pager, &syms) {
|
||||
// this means that a vtab exists and we no longer have the module loaded. we print
|
||||
// a warning to the user to load the module
|
||||
eprintln!("Warning: {e}");
|
||||
|
||||
@@ -9,7 +9,7 @@ use crate::types::CursorResult;
|
||||
use crate::Completion;
|
||||
use crate::{Buffer, Connection, LimboError, Result};
|
||||
use parking_lot::RwLock;
|
||||
use std::cell::{OnceCell, RefCell, UnsafeCell};
|
||||
use std::cell::{Cell, OnceCell, RefCell, UnsafeCell};
|
||||
use std::collections::HashSet;
|
||||
use std::rc::Rc;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
@@ -225,7 +225,7 @@ pub struct Pager {
|
||||
/// Cache page_size and reserved_space at Pager init and reuse for subsequent
|
||||
/// `usable_space` calls. TODO: Invalidate reserved_space when we add the functionality
|
||||
/// to change it.
|
||||
page_size: RefCell<Option<u32>>,
|
||||
page_size: Cell<Option<u32>>,
|
||||
reserved_space: OnceCell<u8>,
|
||||
}
|
||||
|
||||
@@ -291,7 +291,7 @@ impl Pager {
|
||||
db_state,
|
||||
init_lock,
|
||||
allocate_page1_state,
|
||||
page_size: RefCell::new(None),
|
||||
page_size: Cell::new(None),
|
||||
reserved_space: OnceCell::new(),
|
||||
})
|
||||
}
|
||||
@@ -586,7 +586,7 @@ impl Pager {
|
||||
pub fn usable_space(&self) -> usize {
|
||||
let page_size = *self
|
||||
.page_size
|
||||
.borrow_mut()
|
||||
.get()
|
||||
.get_or_insert_with(|| header_accessor::get_page_size(self).unwrap_or_default());
|
||||
|
||||
let reserved_space = *self
|
||||
@@ -598,6 +598,7 @@ impl Pager {
|
||||
|
||||
/// Set the initial page size for the database. Should only be called before the database is initialized
|
||||
pub fn set_initial_page_size(&self, size: u32) {
|
||||
assert_eq!(self.db_state.load(Ordering::SeqCst), DB_STATE_UNINITIALIZED);
|
||||
self.page_size.replace(Some(size));
|
||||
}
|
||||
|
||||
@@ -1063,7 +1064,7 @@ impl Pager {
|
||||
self.db_state.store(DB_STATE_INITIALIZING, Ordering::SeqCst);
|
||||
let mut default_header = DatabaseHeader::default();
|
||||
default_header.database_size += 1;
|
||||
if let Some(size) = *self.page_size.borrow() {
|
||||
if let Some(size) = self.page_size.get() {
|
||||
default_header.update_page_size(size);
|
||||
}
|
||||
let page = allocate_page(1, &self.buffer_pool, 0);
|
||||
|
||||
Reference in New Issue
Block a user