Introduce eager rent collection (#9527)
* Switch AccountsIndex.account_maps from HashMap to BTreeMap * Introduce eager rent collection * Start to add tests * Avoid too short eager rent collection cycles * Add more tests * Add more tests... * Refacotr!!!!!! * Refactoring follow up * More tiny cleanups * Don't rewrite 0-lamport accounts to be deterministic * Refactor a bit * Do hard fork, restore tests, and perf. mitigation * Fix build... * Refactor and add switch over for testnet (TdS) * Use to_be_bytes * cleanup * More tiny cleanup * Rebase cleanup * Set Bank::genesis_hash when resuming from snapshot * Reorder fns and clean ups * Better naming and commenting * Yet more naming clarifications * Make prefix width strictly uniform for 2-base partition_count * Fix typo... * Revert cluster-dependent gate * kick ci? * kick ci? * kick ci?
This commit is contained in:
@@ -47,6 +47,7 @@ use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
fmt,
|
||||
io::{BufReader, Cursor, Error as IOError, ErrorKind, Read, Result as IOResult},
|
||||
ops::RangeBounds,
|
||||
path::{Path, PathBuf},
|
||||
sync::atomic::{AtomicBool, AtomicU64, AtomicUsize, Ordering},
|
||||
sync::{Arc, Mutex, RwLock},
|
||||
@@ -173,6 +174,25 @@ impl<'a> Serialize for AccountStorageSerialize<'a> {
|
||||
|
||||
#[derive(Clone, Default, Debug)]
|
||||
pub struct AccountStorage(pub HashMap<Slot, SlotStores>);
|
||||
|
||||
impl AccountStorage {
|
||||
fn scan_accounts(&self, account_info: &AccountInfo, slot: Slot) -> Option<(Account, Slot)> {
|
||||
self.0
|
||||
.get(&slot)
|
||||
.and_then(|storage_map| storage_map.get(&account_info.store_id))
|
||||
.and_then(|store| {
|
||||
Some(
|
||||
store
|
||||
.accounts
|
||||
.get_account(account_info.offset)?
|
||||
.0
|
||||
.clone_account(),
|
||||
)
|
||||
})
|
||||
.map(|account| (account, slot))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for AccountStorage {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
@@ -1107,19 +1127,28 @@ impl AccountsDB {
|
||||
scan_func(
|
||||
&mut collector,
|
||||
storage
|
||||
.0
|
||||
.get(&slot)
|
||||
.and_then(|storage_map| storage_map.get(&account_info.store_id))
|
||||
.and_then(|store| {
|
||||
Some(
|
||||
store
|
||||
.accounts
|
||||
.get_account(account_info.offset)?
|
||||
.0
|
||||
.clone_account(),
|
||||
)
|
||||
})
|
||||
.map(|account| (pubkey, account, slot)),
|
||||
.scan_accounts(account_info, slot)
|
||||
.map(|(account, slot)| (pubkey, account, slot)),
|
||||
)
|
||||
});
|
||||
collector
|
||||
}
|
||||
|
||||
pub fn range_scan_accounts<F, A, R>(&self, ancestors: &Ancestors, range: R, scan_func: F) -> A
|
||||
where
|
||||
F: Fn(&mut A, Option<(&Pubkey, Account, Slot)>) -> (),
|
||||
A: Default,
|
||||
R: RangeBounds<Pubkey>,
|
||||
{
|
||||
let mut collector = A::default();
|
||||
let accounts_index = self.accounts_index.read().unwrap();
|
||||
let storage = self.storage.read().unwrap();
|
||||
accounts_index.range_scan_accounts(ancestors, range, |pubkey, (account_info, slot)| {
|
||||
scan_func(
|
||||
&mut collector,
|
||||
storage
|
||||
.scan_accounts(account_info, slot)
|
||||
.map(|(account, slot)| (pubkey, account, slot)),
|
||||
)
|
||||
});
|
||||
collector
|
||||
|
Reference in New Issue
Block a user