Skip to content

Commit

Permalink
Removes ReadAccountMapEntry (#35351)
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo authored Feb 28, 2024
1 parent 6aaaf85 commit 140c21f
Showing 1 changed file with 1 addition and 94 deletions.
95 changes: 1 addition & 94 deletions accounts-db/src/accounts_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use {
secondary_index::*,
},
log::*,
ouroboros::self_referencing,
rand::{thread_rng, Rng},
rayon::{
iter::{IntoParallelIterator, ParallelIterator},
Expand All @@ -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,
Expand Down Expand Up @@ -339,48 +338,6 @@ impl<T: IndexValue> AccountMapEntryInner<T> {
}
}

pub enum AccountIndexGetResult<T: IndexValue> {
/// (index entry, index in slot list)
Found(ReadAccountMapEntry<T>, usize),
NotFound,
}

#[self_referencing]
pub struct ReadAccountMapEntry<T: IndexValue> {
owned_entry: AccountMapEntry<T>,
#[borrows(owned_entry)]
#[covariant]
slot_list_guard: RwLockReadGuard<'this, SlotList<T>>,
}

impl<T: IndexValue> Debug for ReadAccountMapEntry<T> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{:?}", self.borrow_owned_entry())
}
}

impl<T: IndexValue> ReadAccountMapEntry<T> {
pub fn from_account_map_entry(account_map_entry: AccountMapEntry<T>) -> Self {
ReadAccountMapEntryBuilder {
owned_entry: account_map_entry,
slot_list_guard_builder: |lock| lock.slot_list.read().unwrap(),
}
.build()
}

pub fn slot_list(&self) -> &SlotList<T> {
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<T: IndexValue> {
Entry(AccountMapEntry<T>),
Expand Down Expand Up @@ -1490,28 +1447,6 @@ impl<T: IndexValue, U: DiskIndexValue + From<T> + Into<T>> AccountsIndex<T, U> {
});
}

/// 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<Slot>,
) -> AccountIndexGetResult<T> {
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,
Expand Down Expand Up @@ -2076,34 +2011,6 @@ impl<T: IndexValue, U: DiskIndexValue + From<T> + Into<T>> AccountsIndex<T, U> {
}
}

// These functions/fields are only usable from a dev context (i.e. tests and benches)
#[cfg(feature = "dev-context-only-utils")]
impl<T: IndexValue> AccountIndexGetResult<T> {
pub fn unwrap(self) -> (ReadAccountMapEntry<T>, 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<V, F: FnOnce((ReadAccountMapEntry<T>, usize)) -> V>(self, f: F) -> Option<V> {
match self {
AccountIndexGetResult::Found(lock, size) => Some(f((lock, size))),
_ => None,
}
}
}

#[cfg(test)]
pub mod tests {
use {
Expand Down

0 comments on commit 140c21f

Please sign in to comment.