move disable behavior to connection instead of checkpoint

This commit is contained in:
pedrocarlo 2025-07-02 14:11:31 -03:00
parent 3861584edc
commit 56d87cb916
3 changed files with 14 additions and 11 deletions

View file

@ -119,7 +119,6 @@ pub struct Database {
is_empty: Arc<AtomicUsize>,
init_lock: Arc<Mutex<()>>,
open_flags: OpenFlags,
wal_checkpoint_disabled: Cell<bool>,
}
unsafe impl Send for Database {}
@ -211,7 +210,6 @@ impl Database {
open_flags: flags,
is_empty: Arc::new(AtomicUsize::new(is_empty)),
init_lock: Arc::new(Mutex::new(())),
wal_checkpoint_disabled: Cell::new(false),
};
let db = Arc::new(db);
@ -279,6 +277,7 @@ impl Database {
_shared_cache: false,
cache_size: Cell::new(default_cache_size),
readonly: Cell::new(false),
wal_checkpoint_disabled: Cell::new(false),
});
if let Err(e) = conn.register_builtins() {
return Err(LimboError::ExtensionError(e));
@ -330,6 +329,7 @@ impl Database {
_shared_cache: false,
cache_size: Cell::new(default_cache_size),
readonly: Cell::new(false),
wal_checkpoint_disabled: Cell::new(false),
});
if let Err(e) = conn.register_builtins() {
@ -449,6 +449,7 @@ pub struct Connection {
_shared_cache: bool,
cache_size: Cell<i32>,
readonly: Cell<bool>,
wal_checkpoint_disabled: Cell<bool>,
}
impl Connection {
@ -675,8 +676,7 @@ impl Connection {
/// If the WAL size is over the checkpoint threshold, it will checkpoint the WAL to
/// the database file and then fsync the database file.
pub fn cacheflush(&self) -> Result<PagerCacheflushStatus> {
self.pager
.cacheflush(self._db.wal_checkpoint_disabled.get())
self.pager.cacheflush(self.wal_checkpoint_disabled.get())
}
pub fn clear_page_cache(&self) -> Result<()> {
@ -686,17 +686,17 @@ impl Connection {
pub fn checkpoint(&self) -> Result<CheckpointResult> {
self.pager
.wal_checkpoint(self._db.wal_checkpoint_disabled.get())
.wal_checkpoint(self.wal_checkpoint_disabled.get())
}
/// Close a connection and checkpoint.
pub fn close(&self) -> Result<()> {
self.pager
.checkpoint_shutdown(self._db.wal_checkpoint_disabled.get())
.checkpoint_shutdown(self.wal_checkpoint_disabled.get())
}
pub fn wal_disable_checkpoint(&self) {
self._db.wal_checkpoint_disabled.set(true);
self.wal_checkpoint_disabled.set(true);
}
pub fn last_insert_rowid(&self) -> i64 {

View file

@ -469,8 +469,12 @@ impl Program {
rollback: bool,
change_schema: bool,
) -> Result<StepResult> {
let cacheflush_status =
pager.end_tx(rollback, change_schema, connection, connection._db.wal_checkpoint_disabled.get())?;
let cacheflush_status = pager.end_tx(
rollback,
change_schema,
connection,
connection.wal_checkpoint_disabled.get(),
)?;
match cacheflush_status {
PagerCacheflushStatus::Done(_) => {
if self.change_cnt_on {

View file

@ -1197,8 +1197,7 @@ pub unsafe extern "C" fn libsql_wal_get_frame(
/// Disable WAL checkpointing.
///
/// Note: This function disables WAL checkpointing entirely, including when
/// the last database connection is closed. This is different from
/// Note: This function disables WAL checkpointing entirely for the connection. This is different from
/// sqlite3_wal_autocheckpoint() which only disables automatic checkpoints
/// for the current connection, but still allows checkpointing when the
/// connection is closed.