From 5838efe7dd5bd6d870fc4771cd0f18c29bc97137 Mon Sep 17 00:00:00 2001 From: Nikita Sivukhin Date: Wed, 13 Aug 2025 12:53:19 +0400 Subject: [PATCH] rename flag to wal_auto_checkpoint_disabled --- Cargo.lock | 1 - core/lib.rs | 14 ++++++++------ core/mvcc/database/mod.rs | 2 +- core/storage/pager.rs | 12 ++++++------ core/vdbe/mod.rs | 2 +- sqlite3/src/lib.rs | 2 +- 6 files changed, 17 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 545aa6095..8081dcc3f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4028,7 +4028,6 @@ dependencies = [ "napi", "napi-build", "napi-derive", - "tracing-subscriber", "turso_core", "turso_node", "turso_sync_engine", diff --git a/core/lib.rs b/core/lib.rs index c258122e7..85bf799c1 100644 --- a/core/lib.rs +++ b/core/lib.rs @@ -411,7 +411,7 @@ impl Database { _shared_cache: false, cache_size: Cell::new(default_cache_size), page_size: Cell::new(page_size), - wal_checkpoint_disabled: Cell::new(false), + wal_auto_checkpoint_disabled: Cell::new(false), capture_data_changes: RefCell::new(CaptureDataChangesMode::Off), closed: Cell::new(false), attached_databases: RefCell::new(DatabaseCatalog::new()), @@ -780,7 +780,9 @@ pub struct Connection { /// page size used for an uninitialized database or the next vacuum command. /// it's not always equal to the current page size of the database page_size: Cell, - wal_checkpoint_disabled: Cell, + /// Disable automatic checkpoint behaviour when DB is shutted down or WAL reach certain size + /// Client still can manually execute PRAGMA wal_checkpoint(...) commands + wal_auto_checkpoint_disabled: Cell, capture_data_changes: RefCell, closed: Cell, /// Attached databases @@ -1405,7 +1407,7 @@ impl Connection { pager.end_tx( true, // rollback = true for close self, - self.wal_checkpoint_disabled.get(), + self.wal_auto_checkpoint_disabled.get(), ) })?; self.transaction_state.set(TransactionState::None); @@ -1414,11 +1416,11 @@ impl Connection { self.pager .borrow() - .checkpoint_shutdown(self.wal_checkpoint_disabled.get()) + .checkpoint_shutdown(self.wal_auto_checkpoint_disabled.get()) } - pub fn wal_disable_checkpoint(&self) { - self.wal_checkpoint_disabled.set(true); + pub fn wal_auto_checkpoint_disable(&self) { + self.wal_auto_checkpoint_disabled.set(true); } pub fn last_insert_rowid(&self) -> i64 { diff --git a/core/mvcc/database/mod.rs b/core/mvcc/database/mod.rs index e78b9dcd0..24e55256e 100644 --- a/core/mvcc/database/mod.rs +++ b/core/mvcc/database/mod.rs @@ -502,7 +502,7 @@ impl StateTransition for CommitStateMachine { .end_tx( false, // rollback = false since we're committing &self.connection, - self.connection.wal_checkpoint_disabled.get(), + self.connection.wal_auto_checkpoint_disabled.get(), ) .map_err(|e| LimboError::InternalError(e.to_string())) .unwrap(); diff --git a/core/storage/pager.rs b/core/storage/pager.rs index dc33fab31..5a6212336 100644 --- a/core/storage/pager.rs +++ b/core/storage/pager.rs @@ -961,7 +961,7 @@ impl Pager { &self, rollback: bool, connection: &Connection, - wal_checkpoint_disabled: bool, + wal_auto_checkpoint_disabled: bool, ) -> Result> { tracing::trace!("end_tx(rollback={})", rollback); let Some(wal) = self.wal.as_ref() else { @@ -980,7 +980,7 @@ impl Pager { self.rollback(schema_did_change, connection, is_write)?; return Ok(IOResult::Done(PagerCommitResult::Rollback)); } - let commit_status = return_if_io!(self.commit_dirty_pages(wal_checkpoint_disabled)); + let commit_status = return_if_io!(self.commit_dirty_pages(wal_auto_checkpoint_disabled)); wal.borrow().end_write_tx(); wal.borrow().end_read_tx(); @@ -1163,7 +1163,7 @@ impl Pager { #[instrument(skip_all, level = Level::DEBUG)] pub fn commit_dirty_pages( &self, - wal_checkpoint_disabled: bool, + wal_auto_checkpoint_disabled: bool, ) -> Result> { let Some(wal) = self.wal.as_ref() else { return Err(LimboError::InternalError( @@ -1226,7 +1226,7 @@ impl Pager { return Ok(IOResult::IO(IOCompletions::Single(c))); } CommitState::AfterSyncWal => { - if wal_checkpoint_disabled || !wal.borrow().should_checkpoint() { + if wal_auto_checkpoint_disabled || !wal.borrow().should_checkpoint() { self.commit_info.borrow_mut().state = CommitState::Start; break PagerCommitResult::WalWritten; } @@ -1354,7 +1354,7 @@ impl Pager { .expect("Failed to clear page cache"); } - pub fn checkpoint_shutdown(&self, wal_checkpoint_disabled: bool) -> Result<()> { + pub fn checkpoint_shutdown(&self, wal_auto_checkpoint_disabled: bool) -> Result<()> { let mut _attempts = 0; { let Some(wal) = self.wal.as_ref() else { @@ -1369,7 +1369,7 @@ impl Pager { let c = wal.sync()?; self.io.wait_for_completion(c)?; } - if !wal_checkpoint_disabled { + if !wal_auto_checkpoint_disabled { self.wal_checkpoint(CheckpointMode::Passive)?; } Ok(()) diff --git a/core/vdbe/mod.rs b/core/vdbe/mod.rs index 9232887d3..38d24d0dd 100644 --- a/core/vdbe/mod.rs +++ b/core/vdbe/mod.rs @@ -581,7 +581,7 @@ impl Program { let cacheflush_status = pager.end_tx( rollback, connection, - connection.wal_checkpoint_disabled.get(), + connection.wal_auto_checkpoint_disabled.get(), )?; match cacheflush_status { IOResult::Done(_) => { diff --git a/sqlite3/src/lib.rs b/sqlite3/src/lib.rs index 723a3f178..30e3af817 100644 --- a/sqlite3/src/lib.rs +++ b/sqlite3/src/lib.rs @@ -1476,7 +1476,7 @@ pub unsafe extern "C" fn libsql_wal_disable_checkpoint(db: *mut sqlite3) -> ffi: } let db: &mut sqlite3 = &mut *db; let db = db.inner.lock().unwrap(); - db.conn.wal_disable_checkpoint(); + db.conn.wal_auto_checkpoint_disable(); SQLITE_OK }