diff --git a/core/lib.rs b/core/lib.rs index d1e867cbf..4067aac15 100644 --- a/core/lib.rs +++ b/core/lib.rs @@ -119,7 +119,6 @@ pub struct Database { is_empty: Arc, init_lock: Arc>, open_flags: OpenFlags, - wal_checkpoint_disabled: Cell, } 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, readonly: Cell, + wal_checkpoint_disabled: Cell, } 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 { - 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 { 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 { diff --git a/core/vdbe/mod.rs b/core/vdbe/mod.rs index 383c4a82f..3663afa6f 100644 --- a/core/vdbe/mod.rs +++ b/core/vdbe/mod.rs @@ -469,8 +469,12 @@ impl Program { rollback: bool, change_schema: bool, ) -> Result { - 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 { diff --git a/sqlite3/src/lib.rs b/sqlite3/src/lib.rs index 0d6e4d36b..240e3acbd 100644 --- a/sqlite3/src/lib.rs +++ b/sqlite3/src/lib.rs @@ -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.