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..88002e0b 100644 --- a/src/tree_store/page_store/page_manager.rs +++ b/src/tree_store/page_store/page_manager.rs @@ -464,6 +464,7 @@ impl TransactionalMemory { transaction_id: TransactionId, eventual: bool, two_phase: bool, + allow_trim: bool, ) -> Result { let result = self.commit_inner( data_root, @@ -472,6 +473,7 @@ impl TransactionalMemory { transaction_id, eventual, two_phase, + allow_trim, ); if result.is_err() { self.needs_recovery.store(true, Ordering::Release); @@ -487,6 +489,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 +500,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 +1030,7 @@ impl Drop for TransactionalMemory { non_durable_transaction_id, false, true, + true, ) .is_err() {