From ec1f95119402e0dd5821ddd619f51f0f63bcfb16 Mon Sep 17 00:00:00 2001 From: Christopher Berner Date: Sun, 2 Jun 2024 09:46:05 -0700 Subject: [PATCH] Cleanup close() usage of transaction guard cloning --- src/transactions.rs | 8 +++----- src/tree_store/btree.rs | 4 ++-- src/tree_store/table_tree.rs | 4 ++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/transactions.rs b/src/transactions.rs index 9e22f5f2..871bd6b8 100644 --- a/src/transactions.rs +++ b/src/transactions.rs @@ -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(), )?) } @@ -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(), )?) } @@ -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 diff --git a/src/tree_store/btree.rs b/src/tree_store/btree.rs index bedcd631..23229956 100644 --- a/src/tree_store/btree.rs +++ b/src/tree_store/btree.rs @@ -575,8 +575,8 @@ impl Btree { }) } - pub(crate) fn clone_transaction_guard(&self) -> Arc { - self.transaction_guard.clone() + pub(crate) fn transaction_guard(&self) -> &Arc { + &self.transaction_guard } pub(crate) fn get_root(&self) -> Option { diff --git a/src/tree_store/table_tree.rs b/src/tree_store/table_tree.rs index 909bba8d..b9e2051f 100644 --- a/src/tree_store/table_tree.rs +++ b/src/tree_store/table_tree.rs @@ -439,8 +439,8 @@ impl TableTree { }) } - pub(crate) fn clone_transaction_guard(&self) -> Arc { - self.tree.clone_transaction_guard() + pub(crate) fn transaction_guard(&self) -> &Arc { + self.tree.transaction_guard() } // root_page: the root of the master table