remove SnapshotStorageOne (#29747)

This commit is contained in:
Jeff Washington (jwash) 2023-01-18 09:10:56 -06:00 committed by GitHub
parent 6e4ecc6758
commit aef8692c8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 54 additions and 50 deletions

View File

@ -1,7 +1,7 @@
//! Manage the map of slot -> append vec
use {
crate::accounts_db::{AccountStorageEntry, AppendVecId, SnapshotStorageOne},
crate::accounts_db::{AccountStorageEntry, AppendVecId},
dashmap::DashMap,
solana_sdk::clock::Slot,
std::sync::Arc,
@ -10,7 +10,7 @@ use {
#[derive(Clone, Debug)]
pub struct AccountStorageReference {
/// the single storage for a given slot
pub(crate) storage: SnapshotStorageOne,
pub(crate) storage: Arc<AccountStorageEntry>,
/// id can be read from 'storage', but it is an atomic read.
/// id will never change while a storage is held, so we store it separately here for faster runtime lookup in 'get_account_storage_entry'
pub(crate) id: AppendVecId,
@ -92,7 +92,7 @@ impl AccountStorage {
/// remove the append vec at 'slot'
/// returns the current contents
pub(crate) fn remove(&self, slot: &Slot) -> Option<SnapshotStorageOne> {
pub(crate) fn remove(&self, slot: &Slot) -> Option<Arc<AccountStorageEntry>> {
assert!(self.shrink_in_progress_map.is_empty());
self.map.remove(slot).map(|(_, entry)| entry.storage)
}
@ -192,7 +192,7 @@ impl<'a> AccountStorageIter<'a> {
}
impl<'a> Iterator for AccountStorageIter<'a> {
type Item = (Slot, SnapshotStorageOne);
type Item = (Slot, Arc<AccountStorageEntry>);
fn next(&mut self) -> Option<Self::Item> {
if let Some(entry) = self.iter.next() {

View File

@ -600,10 +600,9 @@ impl<'a> MultiThreadProgress<'a> {
/// An offset into the AccountsDb::storage vector
pub type AtomicAppendVecId = AtomicU32;
pub type AppendVecId = u32;
pub type SnapshotStorageOne = Arc<AccountStorageEntry>;
pub type SnapshotStorages = Vec<Vec<SnapshotStorageOne>>;
pub type SnapshotStorages = Vec<Vec<Arc<AccountStorageEntry>>>;
/// exactly 1 append vec per slot
pub type SnapshotStoragesOne = Vec<SnapshotStorageOne>;
pub type SnapshotStoragesOne = Vec<Arc<AccountStorageEntry>>;
type AccountSlots = HashMap<Pubkey, HashSet<Slot>>;
type AppendVecOffsets = HashMap<AppendVecId, HashSet<usize>>;
@ -1121,7 +1120,7 @@ impl RecycleStores {
self.entries.iter()
}
fn add_entries(&mut self, new_entries: Vec<SnapshotStorageOne>) {
fn add_entries(&mut self, new_entries: Vec<Arc<AccountStorageEntry>>) {
let now = Instant::now();
for new_entry in new_entries {
self.total_bytes += new_entry.total_bytes();
@ -1129,7 +1128,7 @@ impl RecycleStores {
}
}
fn expire_old_entries(&mut self) -> Vec<SnapshotStorageOne> {
fn expire_old_entries(&mut self) -> Vec<Arc<AccountStorageEntry>> {
let mut expired = vec![];
let now = Instant::now();
let mut expired_bytes = 0;
@ -3888,7 +3887,7 @@ impl AccountsDb {
slot: Slot,
add_dirty_stores: bool,
shrink_in_progress: Option<ShrinkInProgress>,
) -> Vec<SnapshotStorageOne> {
) -> Vec<Arc<AccountStorageEntry>> {
let mut dead_storages = Vec::default();
let mut not_retaining_store = |store: &Arc<AccountStorageEntry>| {
@ -3913,7 +3912,7 @@ impl AccountsDb {
pub(crate) fn drop_or_recycle_stores(
&self,
dead_storages: Vec<SnapshotStorageOne>,
dead_storages: Vec<Arc<AccountStorageEntry>>,
stats: &ShrinkStats,
) {
let mut recycle_stores_write_elapsed = Measure::start("recycle_stores_write_time");
@ -5457,7 +5456,7 @@ impl AccountsDb {
fn recycle_slot_stores(
&self,
total_removed_storage_entries: usize,
slot_stores: &[SnapshotStorageOne],
slot_stores: &[Arc<AccountStorageEntry>],
) -> u64 {
let mut recycle_stores_write_elapsed = Measure::start("recycle_stores_write_elapsed");
let mut recycle_stores = self.recycle_stores.write().unwrap();
@ -6735,7 +6734,7 @@ impl AccountsDb {
}
/// iterate over a single storage, calling scanner on each item
fn scan_single_account_storage<S>(storage: &SnapshotStorageOne, scanner: &mut S)
fn scan_single_account_storage<S>(storage: &Arc<AccountStorageEntry>, scanner: &mut S)
where
S: AppendVecScan,
{
@ -6746,7 +6745,7 @@ impl AccountsDb {
});
}
fn update_old_slot_stats(&self, stats: &HashStats, storage: Option<&SnapshotStorageOne>) {
fn update_old_slot_stats(&self, stats: &HashStats, storage: Option<&Arc<AccountStorageEntry>>) {
if let Some(storage) = storage {
stats.roots_older_than_epoch.fetch_add(1, Ordering::Relaxed);
let mut ancients = 0;
@ -6802,7 +6801,7 @@ impl AccountsDb {
/// return true iff storage is valid for loading from cache
fn hash_storage_info(
hasher: &mut impl StdHasher,
storage: Option<&SnapshotStorageOne>,
storage: Option<&Arc<AccountStorageEntry>>,
slot: Slot,
) -> bool {
if let Some(append_vec) = storage {
@ -8289,7 +8288,7 @@ impl AccountsDb {
let store = std::mem::take(store).unwrap();
store.has_accounts().then_some((store, *slot))
})
.collect::<Vec<(SnapshotStorageOne, Slot)>>()
.collect::<Vec<(Arc<AccountStorageEntry>, Slot)>>()
})
.collect::<Vec<_>>()
});
@ -9623,7 +9622,7 @@ pub mod tests {
sample_storages_and_account_in_slot(1, accounts)
}
fn get_storage_refs(input: &[SnapshotStorageOne]) -> SortedStorages {
fn get_storage_refs(input: &[Arc<AccountStorageEntry>]) -> SortedStorages {
SortedStorages::new(input)
}

View File

@ -3,7 +3,7 @@ use {
accounts::Accounts,
accounts_db::{
AccountShrinkThreshold, AccountStorageEntry, AccountsDb, AccountsDbConfig, AppendVecId,
AtomicAppendVecId, BankHashInfo, IndexGenerationInfo, SnapshotStorageOne,
AtomicAppendVecId, BankHashInfo, IndexGenerationInfo,
},
accounts_hash::AccountsHash,
accounts_index::AccountSecondaryIndexes,
@ -345,7 +345,7 @@ pub(crate) fn bank_to_stream<W>(
serde_style: SerdeStyle,
stream: &mut BufWriter<W>,
bank: &Bank,
snapshot_storages: &[Vec<SnapshotStorageOne>],
snapshot_storages: &[Vec<Arc<AccountStorageEntry>>],
) -> Result<(), Error>
where
W: Write,
@ -367,7 +367,7 @@ pub(crate) fn bank_to_stream_no_extra_fields<W>(
serde_style: SerdeStyle,
stream: &mut BufWriter<W>,
bank: &Bank,
snapshot_storages: &[Vec<SnapshotStorageOne>],
snapshot_storages: &[Vec<Arc<AccountStorageEntry>>],
) -> Result<(), Error>
where
W: Write,
@ -445,7 +445,7 @@ pub fn reserialize_bank_with_new_accounts_hash(
struct SerializableBankAndStorage<'a, C> {
bank: &'a Bank,
snapshot_storages: &'a [Vec<SnapshotStorageOne>],
snapshot_storages: &'a [Vec<Arc<AccountStorageEntry>>],
phantom: std::marker::PhantomData<C>,
}
@ -461,7 +461,7 @@ impl<'a, C: TypeContext<'a>> Serialize for SerializableBankAndStorage<'a, C> {
#[cfg(test)]
struct SerializableBankAndStorageNoExtra<'a, C> {
bank: &'a Bank,
snapshot_storages: &'a [Vec<SnapshotStorageOne>],
snapshot_storages: &'a [Vec<Arc<AccountStorageEntry>>],
phantom: std::marker::PhantomData<C>,
}
@ -494,7 +494,7 @@ impl<'a, C> From<SerializableBankAndStorageNoExtra<'a, C>> for SerializableBankA
struct SerializableAccountsDb<'a, C> {
accounts_db: &'a AccountsDb,
slot: Slot,
account_storage_entries: &'a [Vec<SnapshotStorageOne>],
account_storage_entries: &'a [Vec<Arc<AccountStorageEntry>>],
phantom: std::marker::PhantomData<C>,
}

View File

@ -146,7 +146,7 @@ fn accountsdb_to_stream<W>(
stream: &mut W,
accounts_db: &AccountsDb,
slot: Slot,
account_storage_entries: &[Vec<SnapshotStorageOne>],
account_storage_entries: &[Vec<Arc<AccountStorageEntry>>],
) -> Result<(), Error>
where
W: Write,

View File

@ -3,7 +3,7 @@
use {
crate::{
accounts_db::{
AccountsDb, GetUniqueAccountsResult, PurgeStats, SnapshotStorageOne, StoreReclaims,
AccountStorageEntry, AccountsDb, GetUniqueAccountsResult, PurgeStats, StoreReclaims,
},
bank::Bank,
builtins, static_ids,
@ -27,7 +27,7 @@ use {
collections::HashSet,
sync::{
atomic::{AtomicUsize, Ordering},
Mutex,
Arc, Mutex,
},
},
};
@ -273,7 +273,7 @@ impl<'a> SnapshotMinimizer<'a> {
fn process_snapshot_storages(
&self,
minimized_slot_set: DashSet<Slot>,
) -> (Vec<Slot>, Vec<SnapshotStorageOne>) {
) -> (Vec<Slot>, Vec<Arc<AccountStorageEntry>>) {
let snapshot_storages = self
.accounts_db()
.get_snapshot_storages(..=self.starting_slot, None)
@ -301,8 +301,8 @@ impl<'a> SnapshotMinimizer<'a> {
/// Creates new storage replacing `storages` that contains only accounts in `minimized_account_set`.
fn filter_storage(
&self,
storage: &SnapshotStorageOne,
dead_storages: &Mutex<Vec<SnapshotStorageOne>>,
storage: &Arc<AccountStorageEntry>,
dead_storages: &Mutex<Vec<Arc<AccountStorageEntry>>>,
) {
let slot = storage.slot();
let GetUniqueAccountsResult {

View File

@ -2,8 +2,8 @@ use {
crate::{
account_storage::AccountStorageMap,
accounts_db::{
AccountShrinkThreshold, AccountsDbConfig, AtomicAppendVecId,
CalcAccountsHashDataSource, SnapshotStorageOne, SnapshotStoragesOne,
AccountShrinkThreshold, AccountStorageEntry, AccountsDbConfig, AtomicAppendVecId,
CalcAccountsHashDataSource, SnapshotStoragesOne,
},
accounts_index::AccountSecondaryIndexes,
accounts_update_notifier_interface::AccountsUpdateNotifier,
@ -847,7 +847,7 @@ where
pub fn add_bank_snapshot(
bank_snapshots_dir: impl AsRef<Path>,
bank: &Bank,
snapshot_storages: &[SnapshotStorageOne],
snapshot_storages: &[Arc<AccountStorageEntry>],
snapshot_version: SnapshotVersion,
) -> Result<BankSnapshotInfo> {
let mut add_snapshot_time = Measure::start("add-snapshot-ms");
@ -908,11 +908,11 @@ pub fn add_bank_snapshot(
})
}
/// serializing needs Vec<Vec<SnapshotStorageOne>>, but data structure at runtime is Vec<SnapshotStorageOne>
/// serializing needs Vec<Vec<Arc<AccountStorageEntry>>>, but data structure at runtime is Vec<Arc<AccountStorageEntry>>
/// translates to what we need
pub(crate) fn get_storages_to_serialize(
snapshot_storages: &[SnapshotStorageOne],
) -> Vec<Vec<SnapshotStorageOne>> {
snapshot_storages: &[Arc<AccountStorageEntry>],
) -> Vec<Vec<Arc<AccountStorageEntry>>> {
snapshot_storages
.iter()
.map(|storage| vec![Arc::clone(storage)])

View File

@ -1,11 +1,12 @@
use {
crate::accounts_db::SnapshotStorageOne,
crate::accounts_db::AccountStorageEntry,
log::*,
solana_measure::measure::Measure,
solana_sdk::clock::Slot,
std::{
collections::HashMap,
ops::{Bound, Range, RangeBounds},
sync::Arc,
},
};
@ -16,7 +17,7 @@ pub struct SortedStorages<'a> {
/// the actual storages
/// A HashMap allows sparse storage and fast lookup of Slot -> Storage.
/// We expect ~432k slots.
storages: HashMap<Slot, &'a SnapshotStorageOne>,
storages: HashMap<Slot, &'a Arc<AccountStorageEntry>>,
}
impl<'a> SortedStorages<'a> {
@ -28,7 +29,7 @@ impl<'a> SortedStorages<'a> {
}
}
/// primary method of retrieving (Slot, SnapshotStorageOne)
/// primary method of retrieving (Slot, Arc<AccountStorageEntry>)
pub fn iter_range<R>(&'a self, range: &R) -> SortedStoragesIter<'a>
where
R: RangeBounds<Slot>,
@ -36,7 +37,7 @@ impl<'a> SortedStorages<'a> {
SortedStoragesIter::new(self, range)
}
fn get(&self, slot: Slot) -> Option<&SnapshotStorageOne> {
fn get(&self, slot: Slot) -> Option<&Arc<AccountStorageEntry>> {
self.storages.get(&slot).copied()
}
@ -62,7 +63,7 @@ impl<'a> SortedStorages<'a> {
// assumption:
// source.slot() is unique from all other items in 'source'
pub fn new(source: &'a [SnapshotStorageOne]) -> Self {
pub fn new(source: &'a [Arc<AccountStorageEntry>]) -> Self {
let slots = source.iter().map(|storage| {
storage.slot() // this must be unique. Will be enforced in new_with_slots
});
@ -70,10 +71,10 @@ impl<'a> SortedStorages<'a> {
}
/// create `SortedStorages` from 'source' iterator.
/// 'source' contains a SnapshotStorageOne and its associated slot
/// 'source' contains a Arc<AccountStorageEntry> and its associated slot
/// 'source' does not have to be sorted in any way, but is assumed to not have duplicate slot #s
pub fn new_with_slots(
source: impl Iterator<Item = (&'a SnapshotStorageOne, Slot)> + Clone,
source: impl Iterator<Item = (&'a Arc<AccountStorageEntry>, Slot)> + Clone,
// A slot used as a lower bound, but potentially smaller than the smallest slot in the given 'source' iterator
min_slot: Option<Slot>,
// highest valid slot. Only matters if source array does not contain a slot >= max_slot_inclusive.
@ -142,7 +143,7 @@ pub struct SortedStoragesIter<'a> {
}
impl<'a> Iterator for SortedStoragesIter<'a> {
type Item = (Slot, Option<&'a SnapshotStorageOne>);
type Item = (Slot, Option<&'a Arc<AccountStorageEntry>>);
fn next(&mut self) -> Option<Self::Item> {
let slot = self.next_slot;
@ -194,13 +195,17 @@ pub mod tests {
use {
super::*,
crate::{
accounts_db::{AccountStorageEntry, AppendVecId, SnapshotStorageOne},
accounts_db::{AccountStorageEntry, AppendVecId},
append_vec::AppendVec,
},
std::sync::Arc,
};
impl<'a> SortedStorages<'a> {
pub fn new_debug(source: &[(&'a SnapshotStorageOne, Slot)], min: Slot, len: usize) -> Self {
pub fn new_debug(
source: &[(&'a Arc<AccountStorageEntry>, Slot)],
min: Slot,
len: usize,
) -> Self {
let mut storages = HashMap::default();
let range = Range {
start: min,
@ -213,7 +218,7 @@ pub mod tests {
Self { range, storages }
}
pub fn new_for_tests(storages: &[&'a SnapshotStorageOne], slots: &[Slot]) -> Self {
pub fn new_for_tests(storages: &[&'a Arc<AccountStorageEntry>], slots: &[Slot]) -> Self {
assert_eq!(storages.len(), slots.len());
SortedStorages::new_with_slots(
storages.iter().cloned().zip(slots.iter().cloned()),
@ -226,7 +231,7 @@ pub mod tests {
#[test]
fn test_sorted_storages_range_iter() {
let storages = SortedStorages::empty();
let check = |(slot, storages): (Slot, Option<&SnapshotStorageOne>)| {
let check = |(slot, storages): (Slot, Option<&Arc<AccountStorageEntry>>)| {
assert!(storages.is_none());
slot
};
@ -250,7 +255,7 @@ pub mod tests {
// only item is slot 3
let s1 = create_sample_store(1);
let storages = SortedStorages::new_for_tests(&[&s1], &[3]);
let check = |(slot, storages): (Slot, Option<&SnapshotStorageOne>)| {
let check = |(slot, storages): (Slot, Option<&Arc<AccountStorageEntry>>)| {
assert!(
(slot != 3) ^ storages.is_some(),
"slot: {slot}, storages: {storages:?}"
@ -286,7 +291,7 @@ pub mod tests {
let store4 = create_sample_store(4);
let storages = SortedStorages::new_for_tests(&[&store2, &store4], &[2, 4]);
let check = |(slot, storage): (Slot, Option<&SnapshotStorageOne>)| {
let check = |(slot, storage): (Slot, Option<&Arc<AccountStorageEntry>>)| {
assert!(
(slot != 2 && slot != 4)
^ storage
@ -358,7 +363,7 @@ pub mod tests {
);
}
fn create_sample_store(id: AppendVecId) -> SnapshotStorageOne {
fn create_sample_store(id: AppendVecId) -> Arc<AccountStorageEntry> {
let tf = crate::append_vec::test_utils::get_append_vec_path("create_sample_store");
let (_temp_dirs, paths) = crate::accounts_db::get_temp_accounts_paths(1).unwrap();
let size: usize = 123;