add <T> through accounts index (#19852)
This commit is contained in:
parent
4fdd70c931
commit
910f241c3f
|
@ -48,7 +48,9 @@ pub type AccountMap<V> = InMemAccountsIndex<V>;
|
|||
|
||||
pub(crate) type AccountMapEntry<T> = Arc<AccountMapEntryInner<T>>;
|
||||
|
||||
pub trait IsCached: 'static + Clone + Debug + PartialEq + ZeroLamport + Copy + Default {
|
||||
pub trait IsCached:
|
||||
'static + Clone + Debug + PartialEq + ZeroLamport + Copy + Default + Sync + Send
|
||||
{
|
||||
fn is_cached(&self) -> bool;
|
||||
}
|
||||
|
||||
|
@ -694,7 +696,7 @@ pub struct AccountsIndex<T: IsCached> {
|
|||
// scanning the fork with that Bank at the tip is no longer possible.
|
||||
pub removed_bank_ids: Mutex<HashSet<BankId>>,
|
||||
|
||||
storage: AccountsIndexStorage,
|
||||
storage: AccountsIndexStorage<T>,
|
||||
}
|
||||
|
||||
impl<T: IsCached> AccountsIndex<T> {
|
||||
|
@ -725,7 +727,11 @@ impl<T: IsCached> AccountsIndex<T> {
|
|||
|
||||
fn allocate_accounts_index(
|
||||
config: Option<AccountsIndexConfig>,
|
||||
) -> (LockMapType<T>, PubkeyBinCalculator16, AccountsIndexStorage) {
|
||||
) -> (
|
||||
LockMapType<T>,
|
||||
PubkeyBinCalculator16,
|
||||
AccountsIndexStorage<T>,
|
||||
) {
|
||||
let bins = config
|
||||
.and_then(|config| config.bins)
|
||||
.unwrap_or(BINS_DEFAULT);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::accounts_index::IsCached;
|
||||
use crate::bucket_map_holder::BucketMapHolder;
|
||||
use crate::waitable_condvar::WaitableCondvar;
|
||||
use std::{
|
||||
|
@ -14,17 +15,17 @@ use std::{
|
|||
// and it will stop all the background threads and join them.
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct AccountsIndexStorage {
|
||||
pub struct AccountsIndexStorage<T: IsCached> {
|
||||
// for managing the bg threads
|
||||
exit: Arc<AtomicBool>,
|
||||
wait: Arc<WaitableCondvar>,
|
||||
handle: Option<JoinHandle<()>>,
|
||||
|
||||
// eventually the backing storage
|
||||
storage: Arc<BucketMapHolder>,
|
||||
storage: Arc<BucketMapHolder<T>>,
|
||||
}
|
||||
|
||||
impl Drop for AccountsIndexStorage {
|
||||
impl<T: IsCached> Drop for AccountsIndexStorage<T> {
|
||||
fn drop(&mut self) {
|
||||
self.exit.store(true, Ordering::Relaxed);
|
||||
self.wait.notify_all();
|
||||
|
@ -34,8 +35,8 @@ impl Drop for AccountsIndexStorage {
|
|||
}
|
||||
}
|
||||
|
||||
impl AccountsIndexStorage {
|
||||
pub fn new() -> AccountsIndexStorage {
|
||||
impl<T: IsCached> AccountsIndexStorage<T> {
|
||||
pub fn new() -> AccountsIndexStorage<T> {
|
||||
let storage = Arc::new(BucketMapHolder::new());
|
||||
let storage_ = storage.clone();
|
||||
let exit = Arc::new(AtomicBool::default());
|
||||
|
@ -59,7 +60,7 @@ impl AccountsIndexStorage {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn storage(&self) -> &Arc<BucketMapHolder> {
|
||||
pub fn storage(&self) -> &Arc<BucketMapHolder<T>> {
|
||||
&self.storage
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::accounts_index::IsCached;
|
||||
use crate::bucket_map_holder_stats::BucketMapHolderStats;
|
||||
use crate::waitable_condvar::WaitableCondvar;
|
||||
use std::fmt::Debug;
|
||||
|
@ -7,15 +8,14 @@ use std::time::Duration;
|
|||
|
||||
// will eventually hold the bucket map
|
||||
#[derive(Debug, Default)]
|
||||
pub struct BucketMapHolder {
|
||||
pub struct BucketMapHolder<T: IsCached> {
|
||||
pub stats: BucketMapHolderStats,
|
||||
_phantom: std::marker::PhantomData<T>,
|
||||
}
|
||||
|
||||
impl BucketMapHolder {
|
||||
impl<T: IsCached> BucketMapHolder<T> {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
stats: BucketMapHolderStats::default(),
|
||||
}
|
||||
Self::default()
|
||||
}
|
||||
|
||||
// intended to execute in a bg thread
|
||||
|
|
|
@ -22,12 +22,12 @@ type K = Pubkey;
|
|||
pub struct InMemAccountsIndex<T: IsCached> {
|
||||
// backing store
|
||||
map: HashMap<Pubkey, AccountMapEntry<T>>,
|
||||
storage: Arc<BucketMapHolder>,
|
||||
storage: Arc<BucketMapHolder<T>>,
|
||||
bin: usize,
|
||||
}
|
||||
|
||||
impl<T: IsCached> InMemAccountsIndex<T> {
|
||||
pub fn new(storage: &AccountsIndexStorage, bin: usize) -> Self {
|
||||
pub fn new(storage: &AccountsIndexStorage<T>, bin: usize) -> Self {
|
||||
Self {
|
||||
map: HashMap::new(),
|
||||
storage: storage.storage().clone(),
|
||||
|
@ -35,7 +35,7 @@ impl<T: IsCached> InMemAccountsIndex<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn new_bucket_map_holder() -> Arc<BucketMapHolder> {
|
||||
pub fn new_bucket_map_holder() -> Arc<BucketMapHolder<T>> {
|
||||
Arc::new(BucketMapHolder::new())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue