From fa58825d5e7514e9676c726fef19c2b308769781 Mon Sep 17 00:00:00 2001 From: Christopher Berner Date: Sat, 21 Oct 2023 19:03:31 -0700 Subject: [PATCH] Fix errant panic with debug_assertions The read ref count tracking could leak if a storage error occurred --- src/tree_store/page_store/page_manager.rs | 29 +++++++++++------------ 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/tree_store/page_store/page_manager.rs b/src/tree_store/page_store/page_manager.rs index a794e46b..1741702a 100644 --- a/src/tree_store/page_store/page_manager.rs +++ b/src/tree_store/page_store/page_manager.rs @@ -665,21 +665,6 @@ impl TransactionalMemory { page_number: PageNumber, hint: PageHint, ) -> Result { - // We must not retrieve an immutable reference to a page which already has a mutable ref to it - #[cfg(debug_assertions)] - { - debug_assert!( - !self.open_dirty_pages.lock().unwrap().contains(&page_number), - "{page_number:?}", - ); - *(self - .read_page_ref_counts - .lock() - .unwrap() - .entry(page_number) - .or_default()) += 1; - } - let range = page_number.address_range( self.page_size as u64, self.region_size, @@ -691,6 +676,20 @@ impl TransactionalMemory { .storage .read(range.start, len, hint, CachePriority::default_btree)?; + // We must not retrieve an immutable reference to a page which already has a mutable ref to it + #[cfg(debug_assertions)] + { + let dirty_pages = self.open_dirty_pages.lock().unwrap(); + debug_assert!(!dirty_pages.contains(&page_number), "{page_number:?}"); + *(self + .read_page_ref_counts + .lock() + .unwrap() + .entry(page_number) + .or_default()) += 1; + drop(dirty_pages); + } + Ok(PageImpl { mem, page_number,