Skip to content

Commit

Permalink
Cleanup close() usage of transaction guard cloning
Browse files Browse the repository at this point in the history
  • Loading branch information
cberner committed Jun 2, 2024
1 parent f26cdb2 commit cdd1200
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
8 changes: 3 additions & 5 deletions src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,7 @@ impl ReadTransaction {
definition.name().to_string(),
header.get_root(),
PageHint::Clean,
self.tree.clone_transaction_guard(),
self.tree.transaction_guard().clone(),
self.mem.clone(),
)?)
}
Expand Down Expand Up @@ -1250,7 +1250,7 @@ impl ReadTransaction {
header.get_root(),
header.get_length(),
PageHint::Clean,
self.tree.clone_transaction_guard(),
self.tree.transaction_guard().clone(),
self.mem.clone(),
)?)
}
Expand Down Expand Up @@ -1296,9 +1296,7 @@ impl ReadTransaction {
///
/// Returns `ReadTransactionStillInUse` error if a table or other object retrieved from the transaction still references this transaction
pub fn close(self) -> Result<(), TransactionError> {
let cloned = self.tree.clone_transaction_guard();
// Check for count greater than 2 because we just cloned the guard to get a reference to it
if Arc::strong_count(&cloned) > 2 {
if Arc::strong_count(self.tree.transaction_guard()) > 1 {
return Err(TransactionError::ReadTransactionStillInUse(self));
}
// No-op, just drop ourself
Expand Down
4 changes: 2 additions & 2 deletions src/tree_store/btree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,8 @@ impl<K: Key, V: Value> Btree<K, V> {
})
}

pub(crate) fn clone_transaction_guard(&self) -> Arc<TransactionGuard> {
self.transaction_guard.clone()
pub(crate) fn transaction_guard(&self) -> &Arc<TransactionGuard> {
&self.transaction_guard
}

pub(crate) fn get_root(&self) -> Option<BtreeHeader> {
Expand Down
4 changes: 2 additions & 2 deletions src/tree_store/table_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,8 @@ impl TableTree {
})
}

pub(crate) fn clone_transaction_guard(&self) -> Arc<TransactionGuard> {
self.tree.clone_transaction_guard()
pub(crate) fn transaction_guard(&self) -> &Arc<TransactionGuard> {
self.tree.transaction_guard()
}

// root_page: the root of the master table
Expand Down

0 comments on commit cdd1200

Please sign in to comment.