From 140c21f8a906fda41feb251d0b32b82ea8760652 Mon Sep 17 00:00:00 2001 From: Brooks Date: Wed, 28 Feb 2024 16:08:00 -0500 Subject: [PATCH] Removes ReadAccountMapEntry (#35351) --- accounts-db/src/accounts_index.rs | 95 +------------------------------ 1 file changed, 1 insertion(+), 94 deletions(-) diff --git a/accounts-db/src/accounts_index.rs b/accounts-db/src/accounts_index.rs index 5221ac434..7c4baf1ee 100644 --- a/accounts-db/src/accounts_index.rs +++ b/accounts-db/src/accounts_index.rs @@ -13,7 +13,6 @@ use { secondary_index::*, }, log::*, - ouroboros::self_referencing, rand::{thread_rng, Rng}, rayon::{ iter::{IntoParallelIterator, ParallelIterator}, @@ -37,7 +36,7 @@ use { path::PathBuf, sync::{ atomic::{AtomicBool, AtomicU64, AtomicUsize, Ordering}, - Arc, Mutex, OnceLock, RwLock, RwLockReadGuard, RwLockWriteGuard, + Arc, Mutex, OnceLock, RwLock, RwLockWriteGuard, }, }, thiserror::Error, @@ -339,48 +338,6 @@ impl AccountMapEntryInner { } } -pub enum AccountIndexGetResult { - /// (index entry, index in slot list) - Found(ReadAccountMapEntry, usize), - NotFound, -} - -#[self_referencing] -pub struct ReadAccountMapEntry { - owned_entry: AccountMapEntry, - #[borrows(owned_entry)] - #[covariant] - slot_list_guard: RwLockReadGuard<'this, SlotList>, -} - -impl Debug for ReadAccountMapEntry { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "{:?}", self.borrow_owned_entry()) - } -} - -impl ReadAccountMapEntry { - pub fn from_account_map_entry(account_map_entry: AccountMapEntry) -> Self { - ReadAccountMapEntryBuilder { - owned_entry: account_map_entry, - slot_list_guard_builder: |lock| lock.slot_list.read().unwrap(), - } - .build() - } - - pub fn slot_list(&self) -> &SlotList { - self.borrow_slot_list_guard() - } - - pub fn ref_count(&self) -> RefCount { - self.borrow_owned_entry().ref_count() - } - - pub fn addref(&self) { - self.borrow_owned_entry().addref(); - } -} - /// can be used to pre-allocate structures for insertion into accounts index outside of lock pub enum PreAllocatedAccountMapEntry { Entry(AccountMapEntry), @@ -1490,28 +1447,6 @@ impl + Into> AccountsIndex { }); } - /// Get an account - /// The latest account that appears in `ancestors` or `roots` is returned. - pub fn get( - &self, - pubkey: &Pubkey, - ancestors: Option<&Ancestors>, - max_root: Option, - ) -> AccountIndexGetResult { - let read_account_map_entry = self - .get_bin(pubkey) - .get(pubkey) - .map(ReadAccountMapEntry::from_account_map_entry); - - read_account_map_entry - .and_then(|locked_entry| { - let slot_list = locked_entry.slot_list(); - self.latest_slot(ancestors, slot_list, max_root) - .map(|found_index| AccountIndexGetResult::Found(locked_entry, found_index)) - }) - .unwrap_or(AccountIndexGetResult::NotFound) - } - // Get the maximum root <= `max_allowed_root` from the given `slice` fn get_newest_root_in_slot_list( alive_roots: &RollingBitField, @@ -2076,34 +2011,6 @@ impl + Into> AccountsIndex { } } -// These functions/fields are only usable from a dev context (i.e. tests and benches) -#[cfg(feature = "dev-context-only-utils")] -impl AccountIndexGetResult { - pub fn unwrap(self) -> (ReadAccountMapEntry, usize) { - match self { - AccountIndexGetResult::Found(lock, size) => (lock, size), - _ => { - panic!("trying to unwrap AccountIndexGetResult with non-Success result"); - } - } - } - - pub fn is_none(&self) -> bool { - !self.is_some() - } - - pub fn is_some(&self) -> bool { - matches!(self, AccountIndexGetResult::Found(_lock, _size)) - } - - pub fn map, usize)) -> V>(self, f: F) -> Option { - match self { - AccountIndexGetResult::Found(lock, size) => Some(f((lock, size))), - _ => None, - } - } -} - #[cfg(test)] pub mod tests { use {