Skip to content

Commit

Permalink
Fix false positive in check_integrity()
Browse files Browse the repository at this point in the history
If the database file was truncated because there was excess space,
during the repair, check_integrity() returned Ok(false)
  • Loading branch information
cberner committed Aug 16, 2024
1 parent 82cf694 commit 81d077f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
1 change: 1 addition & 0 deletions src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,7 @@ impl WriteTransaction {
self.transaction_id,
eventual,
two_phase,
true,
)?;

// Mark any pending non-durable commits as fully committed.
Expand Down
12 changes: 11 additions & 1 deletion src/tree_store/page_store/page_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BtreeHeader>,
Expand All @@ -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,
Expand All @@ -472,13 +474,15 @@ impl TransactionalMemory {
transaction_id,
eventual,
two_phase,
allow_trim,
);
if result.is_err() {
self.needs_recovery.store(true, Ordering::Release);
}
result
}

#[allow(clippy::too_many_arguments)]
fn commit_inner(
&self,
data_root: Option<BtreeHeader>,
Expand All @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -1023,6 +1032,7 @@ impl Drop for TransactionalMemory {
non_durable_transaction_id,
false,
true,
true,
)
.is_err()
{
Expand Down

0 comments on commit 81d077f

Please sign in to comment.