Removes ReadAccountMapEntry (#35351)

This commit is contained in:
Brooks 2024-02-28 16:08:00 -05:00 committed by GitHub
parent 6aaaf858c9
commit 140c21f8a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 1 additions and 94 deletions

View File

@ -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<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>),
@ -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,
@ -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 {