diff --git a/src/db.rs b/src/db.rs index 7ced2957..c035fa62 100644 --- a/src/db.rs +++ b/src/db.rs @@ -780,6 +780,8 @@ impl Database { transaction_id, false, true, + // don't trim the database file, because we want the allocator hash to match exactly + false, )?; Ok(()) diff --git a/src/transactions.rs b/src/transactions.rs index c0f69071..b9681782 100644 --- a/src/transactions.rs +++ b/src/transactions.rs @@ -1024,6 +1024,7 @@ impl WriteTransaction { self.transaction_id, eventual, two_phase, + true, )?; // Mark any pending non-durable commits as fully committed. diff --git a/src/tree_store/page_store/page_manager.rs b/src/tree_store/page_store/page_manager.rs index 0b046a24..5407df1d 100644 --- a/src/tree_store/page_store/page_manager.rs +++ b/src/tree_store/page_store/page_manager.rs @@ -456,6 +456,7 @@ impl TransactionalMemory { } // Commit all outstanding changes and make them visible as the primary + #[allow(clippy::too-many-arguments)] pub(crate) fn commit( &self, data_root: Option, @@ -464,6 +465,7 @@ impl TransactionalMemory { transaction_id: TransactionId, eventual: bool, two_phase: bool, + allow_trim: bool, ) -> Result { let result = self.commit_inner( data_root, @@ -472,6 +474,7 @@ impl TransactionalMemory { transaction_id, eventual, two_phase, + allow_trim, ); if result.is_err() { self.needs_recovery.store(true, Ordering::Release); @@ -479,6 +482,7 @@ impl TransactionalMemory { result } + #[allow(clippy::too-many-arguments)] fn commit_inner( &self, data_root: Option, @@ -487,6 +491,7 @@ impl TransactionalMemory { transaction_id: TransactionId, eventual: bool, two_phase: bool, + allow_trim: bool, ) -> Result { // All mutable pages must be dropped, this ensures that when a transaction completes // no more writes can happen to the pages it allocated. Thus it is safe to make them visible @@ -497,7 +502,11 @@ impl TransactionalMemory { let mut state = self.state.lock().unwrap(); // Trim surplus file space, before finalizing the commit - let shrunk = self.try_shrink(&mut state)?; + let shrunk = if allow_trim { + self.try_shrink(&mut state)? + } else { + false + }; // Copy the header so that we can release the state lock, while we flush the file let mut header = state.header.clone(); drop(state); @@ -1023,6 +1032,7 @@ impl Drop for TransactionalMemory { non_durable_transaction_id, false, true, + true, ) .is_err() {