Removes ReadAccountMapEntry (#35351)
This commit is contained in:
parent
6aaaf858c9
commit
140c21f8a9
|
@ -13,7 +13,6 @@ use {
|
||||||
secondary_index::*,
|
secondary_index::*,
|
||||||
},
|
},
|
||||||
log::*,
|
log::*,
|
||||||
ouroboros::self_referencing,
|
|
||||||
rand::{thread_rng, Rng},
|
rand::{thread_rng, Rng},
|
||||||
rayon::{
|
rayon::{
|
||||||
iter::{IntoParallelIterator, ParallelIterator},
|
iter::{IntoParallelIterator, ParallelIterator},
|
||||||
|
@ -37,7 +36,7 @@ use {
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
sync::{
|
sync::{
|
||||||
atomic::{AtomicBool, AtomicU64, AtomicUsize, Ordering},
|
atomic::{AtomicBool, AtomicU64, AtomicUsize, Ordering},
|
||||||
Arc, Mutex, OnceLock, RwLock, RwLockReadGuard, RwLockWriteGuard,
|
Arc, Mutex, OnceLock, RwLock, RwLockWriteGuard,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
thiserror::Error,
|
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
|
/// can be used to pre-allocate structures for insertion into accounts index outside of lock
|
||||||
pub enum PreAllocatedAccountMapEntry<T: IndexValue> {
|
pub enum PreAllocatedAccountMapEntry<T: IndexValue> {
|
||||||
Entry(AccountMapEntry<T>),
|
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`
|
// Get the maximum root <= `max_allowed_root` from the given `slice`
|
||||||
fn get_newest_root_in_slot_list(
|
fn get_newest_root_in_slot_list(
|
||||||
alive_roots: &RollingBitField,
|
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)]
|
#[cfg(test)]
|
||||||
pub mod tests {
|
pub mod tests {
|
||||||
use {
|
use {
|
||||||
|
|
Loading…
Reference in New Issue