remove SnapshotStorageOne (#29747)
This commit is contained in:
parent
6e4ecc6758
commit
aef8692c8f
|
@ -1,7 +1,7 @@
|
||||||
//! Manage the map of slot -> append vec
|
//! Manage the map of slot -> append vec
|
||||||
|
|
||||||
use {
|
use {
|
||||||
crate::accounts_db::{AccountStorageEntry, AppendVecId, SnapshotStorageOne},
|
crate::accounts_db::{AccountStorageEntry, AppendVecId},
|
||||||
dashmap::DashMap,
|
dashmap::DashMap,
|
||||||
solana_sdk::clock::Slot,
|
solana_sdk::clock::Slot,
|
||||||
std::sync::Arc,
|
std::sync::Arc,
|
||||||
|
@ -10,7 +10,7 @@ use {
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct AccountStorageReference {
|
pub struct AccountStorageReference {
|
||||||
/// the single storage for a given slot
|
/// 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 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'
|
/// 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,
|
pub(crate) id: AppendVecId,
|
||||||
|
@ -92,7 +92,7 @@ impl AccountStorage {
|
||||||
|
|
||||||
/// remove the append vec at 'slot'
|
/// remove the append vec at 'slot'
|
||||||
/// returns the current contents
|
/// 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());
|
assert!(self.shrink_in_progress_map.is_empty());
|
||||||
self.map.remove(slot).map(|(_, entry)| entry.storage)
|
self.map.remove(slot).map(|(_, entry)| entry.storage)
|
||||||
}
|
}
|
||||||
|
@ -192,7 +192,7 @@ impl<'a> AccountStorageIter<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Iterator for AccountStorageIter<'a> {
|
impl<'a> Iterator for AccountStorageIter<'a> {
|
||||||
type Item = (Slot, SnapshotStorageOne);
|
type Item = (Slot, Arc<AccountStorageEntry>);
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
if let Some(entry) = self.iter.next() {
|
if let Some(entry) = self.iter.next() {
|
||||||
|
|
|
@ -600,10 +600,9 @@ impl<'a> MultiThreadProgress<'a> {
|
||||||
/// An offset into the AccountsDb::storage vector
|
/// An offset into the AccountsDb::storage vector
|
||||||
pub type AtomicAppendVecId = AtomicU32;
|
pub type AtomicAppendVecId = AtomicU32;
|
||||||
pub type AppendVecId = u32;
|
pub type AppendVecId = u32;
|
||||||
pub type SnapshotStorageOne = Arc<AccountStorageEntry>;
|
pub type SnapshotStorages = Vec<Vec<Arc<AccountStorageEntry>>>;
|
||||||
pub type SnapshotStorages = Vec<Vec<SnapshotStorageOne>>;
|
|
||||||
/// exactly 1 append vec per slot
|
/// exactly 1 append vec per slot
|
||||||
pub type SnapshotStoragesOne = Vec<SnapshotStorageOne>;
|
pub type SnapshotStoragesOne = Vec<Arc<AccountStorageEntry>>;
|
||||||
|
|
||||||
type AccountSlots = HashMap<Pubkey, HashSet<Slot>>;
|
type AccountSlots = HashMap<Pubkey, HashSet<Slot>>;
|
||||||
type AppendVecOffsets = HashMap<AppendVecId, HashSet<usize>>;
|
type AppendVecOffsets = HashMap<AppendVecId, HashSet<usize>>;
|
||||||
|
@ -1121,7 +1120,7 @@ impl RecycleStores {
|
||||||
self.entries.iter()
|
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();
|
let now = Instant::now();
|
||||||
for new_entry in new_entries {
|
for new_entry in new_entries {
|
||||||
self.total_bytes += new_entry.total_bytes();
|
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 mut expired = vec![];
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
let mut expired_bytes = 0;
|
let mut expired_bytes = 0;
|
||||||
|
@ -3888,7 +3887,7 @@ impl AccountsDb {
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
add_dirty_stores: bool,
|
add_dirty_stores: bool,
|
||||||
shrink_in_progress: Option<ShrinkInProgress>,
|
shrink_in_progress: Option<ShrinkInProgress>,
|
||||||
) -> Vec<SnapshotStorageOne> {
|
) -> Vec<Arc<AccountStorageEntry>> {
|
||||||
let mut dead_storages = Vec::default();
|
let mut dead_storages = Vec::default();
|
||||||
|
|
||||||
let mut not_retaining_store = |store: &Arc<AccountStorageEntry>| {
|
let mut not_retaining_store = |store: &Arc<AccountStorageEntry>| {
|
||||||
|
@ -3913,7 +3912,7 @@ impl AccountsDb {
|
||||||
|
|
||||||
pub(crate) fn drop_or_recycle_stores(
|
pub(crate) fn drop_or_recycle_stores(
|
||||||
&self,
|
&self,
|
||||||
dead_storages: Vec<SnapshotStorageOne>,
|
dead_storages: Vec<Arc<AccountStorageEntry>>,
|
||||||
stats: &ShrinkStats,
|
stats: &ShrinkStats,
|
||||||
) {
|
) {
|
||||||
let mut recycle_stores_write_elapsed = Measure::start("recycle_stores_write_time");
|
let mut recycle_stores_write_elapsed = Measure::start("recycle_stores_write_time");
|
||||||
|
@ -5457,7 +5456,7 @@ impl AccountsDb {
|
||||||
fn recycle_slot_stores(
|
fn recycle_slot_stores(
|
||||||
&self,
|
&self,
|
||||||
total_removed_storage_entries: usize,
|
total_removed_storage_entries: usize,
|
||||||
slot_stores: &[SnapshotStorageOne],
|
slot_stores: &[Arc<AccountStorageEntry>],
|
||||||
) -> u64 {
|
) -> u64 {
|
||||||
let mut recycle_stores_write_elapsed = Measure::start("recycle_stores_write_elapsed");
|
let mut recycle_stores_write_elapsed = Measure::start("recycle_stores_write_elapsed");
|
||||||
let mut recycle_stores = self.recycle_stores.write().unwrap();
|
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
|
/// 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
|
where
|
||||||
S: AppendVecScan,
|
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 {
|
if let Some(storage) = storage {
|
||||||
stats.roots_older_than_epoch.fetch_add(1, Ordering::Relaxed);
|
stats.roots_older_than_epoch.fetch_add(1, Ordering::Relaxed);
|
||||||
let mut ancients = 0;
|
let mut ancients = 0;
|
||||||
|
@ -6802,7 +6801,7 @@ impl AccountsDb {
|
||||||
/// return true iff storage is valid for loading from cache
|
/// return true iff storage is valid for loading from cache
|
||||||
fn hash_storage_info(
|
fn hash_storage_info(
|
||||||
hasher: &mut impl StdHasher,
|
hasher: &mut impl StdHasher,
|
||||||
storage: Option<&SnapshotStorageOne>,
|
storage: Option<&Arc<AccountStorageEntry>>,
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if let Some(append_vec) = storage {
|
if let Some(append_vec) = storage {
|
||||||
|
@ -8289,7 +8288,7 @@ impl AccountsDb {
|
||||||
let store = std::mem::take(store).unwrap();
|
let store = std::mem::take(store).unwrap();
|
||||||
store.has_accounts().then_some((store, *slot))
|
store.has_accounts().then_some((store, *slot))
|
||||||
})
|
})
|
||||||
.collect::<Vec<(SnapshotStorageOne, Slot)>>()
|
.collect::<Vec<(Arc<AccountStorageEntry>, Slot)>>()
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
});
|
});
|
||||||
|
@ -9623,7 +9622,7 @@ pub mod tests {
|
||||||
sample_storages_and_account_in_slot(1, accounts)
|
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)
|
SortedStorages::new(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ use {
|
||||||
accounts::Accounts,
|
accounts::Accounts,
|
||||||
accounts_db::{
|
accounts_db::{
|
||||||
AccountShrinkThreshold, AccountStorageEntry, AccountsDb, AccountsDbConfig, AppendVecId,
|
AccountShrinkThreshold, AccountStorageEntry, AccountsDb, AccountsDbConfig, AppendVecId,
|
||||||
AtomicAppendVecId, BankHashInfo, IndexGenerationInfo, SnapshotStorageOne,
|
AtomicAppendVecId, BankHashInfo, IndexGenerationInfo,
|
||||||
},
|
},
|
||||||
accounts_hash::AccountsHash,
|
accounts_hash::AccountsHash,
|
||||||
accounts_index::AccountSecondaryIndexes,
|
accounts_index::AccountSecondaryIndexes,
|
||||||
|
@ -345,7 +345,7 @@ pub(crate) fn bank_to_stream<W>(
|
||||||
serde_style: SerdeStyle,
|
serde_style: SerdeStyle,
|
||||||
stream: &mut BufWriter<W>,
|
stream: &mut BufWriter<W>,
|
||||||
bank: &Bank,
|
bank: &Bank,
|
||||||
snapshot_storages: &[Vec<SnapshotStorageOne>],
|
snapshot_storages: &[Vec<Arc<AccountStorageEntry>>],
|
||||||
) -> Result<(), Error>
|
) -> Result<(), Error>
|
||||||
where
|
where
|
||||||
W: Write,
|
W: Write,
|
||||||
|
@ -367,7 +367,7 @@ pub(crate) fn bank_to_stream_no_extra_fields<W>(
|
||||||
serde_style: SerdeStyle,
|
serde_style: SerdeStyle,
|
||||||
stream: &mut BufWriter<W>,
|
stream: &mut BufWriter<W>,
|
||||||
bank: &Bank,
|
bank: &Bank,
|
||||||
snapshot_storages: &[Vec<SnapshotStorageOne>],
|
snapshot_storages: &[Vec<Arc<AccountStorageEntry>>],
|
||||||
) -> Result<(), Error>
|
) -> Result<(), Error>
|
||||||
where
|
where
|
||||||
W: Write,
|
W: Write,
|
||||||
|
@ -445,7 +445,7 @@ pub fn reserialize_bank_with_new_accounts_hash(
|
||||||
|
|
||||||
struct SerializableBankAndStorage<'a, C> {
|
struct SerializableBankAndStorage<'a, C> {
|
||||||
bank: &'a Bank,
|
bank: &'a Bank,
|
||||||
snapshot_storages: &'a [Vec<SnapshotStorageOne>],
|
snapshot_storages: &'a [Vec<Arc<AccountStorageEntry>>],
|
||||||
phantom: std::marker::PhantomData<C>,
|
phantom: std::marker::PhantomData<C>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -461,7 +461,7 @@ impl<'a, C: TypeContext<'a>> Serialize for SerializableBankAndStorage<'a, C> {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
struct SerializableBankAndStorageNoExtra<'a, C> {
|
struct SerializableBankAndStorageNoExtra<'a, C> {
|
||||||
bank: &'a Bank,
|
bank: &'a Bank,
|
||||||
snapshot_storages: &'a [Vec<SnapshotStorageOne>],
|
snapshot_storages: &'a [Vec<Arc<AccountStorageEntry>>],
|
||||||
phantom: std::marker::PhantomData<C>,
|
phantom: std::marker::PhantomData<C>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -494,7 +494,7 @@ impl<'a, C> From<SerializableBankAndStorageNoExtra<'a, C>> for SerializableBankA
|
||||||
struct SerializableAccountsDb<'a, C> {
|
struct SerializableAccountsDb<'a, C> {
|
||||||
accounts_db: &'a AccountsDb,
|
accounts_db: &'a AccountsDb,
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
account_storage_entries: &'a [Vec<SnapshotStorageOne>],
|
account_storage_entries: &'a [Vec<Arc<AccountStorageEntry>>],
|
||||||
phantom: std::marker::PhantomData<C>,
|
phantom: std::marker::PhantomData<C>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -146,7 +146,7 @@ fn accountsdb_to_stream<W>(
|
||||||
stream: &mut W,
|
stream: &mut W,
|
||||||
accounts_db: &AccountsDb,
|
accounts_db: &AccountsDb,
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
account_storage_entries: &[Vec<SnapshotStorageOne>],
|
account_storage_entries: &[Vec<Arc<AccountStorageEntry>>],
|
||||||
) -> Result<(), Error>
|
) -> Result<(), Error>
|
||||||
where
|
where
|
||||||
W: Write,
|
W: Write,
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
use {
|
use {
|
||||||
crate::{
|
crate::{
|
||||||
accounts_db::{
|
accounts_db::{
|
||||||
AccountsDb, GetUniqueAccountsResult, PurgeStats, SnapshotStorageOne, StoreReclaims,
|
AccountStorageEntry, AccountsDb, GetUniqueAccountsResult, PurgeStats, StoreReclaims,
|
||||||
},
|
},
|
||||||
bank::Bank,
|
bank::Bank,
|
||||||
builtins, static_ids,
|
builtins, static_ids,
|
||||||
|
@ -27,7 +27,7 @@ use {
|
||||||
collections::HashSet,
|
collections::HashSet,
|
||||||
sync::{
|
sync::{
|
||||||
atomic::{AtomicUsize, Ordering},
|
atomic::{AtomicUsize, Ordering},
|
||||||
Mutex,
|
Arc, Mutex,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -273,7 +273,7 @@ impl<'a> SnapshotMinimizer<'a> {
|
||||||
fn process_snapshot_storages(
|
fn process_snapshot_storages(
|
||||||
&self,
|
&self,
|
||||||
minimized_slot_set: DashSet<Slot>,
|
minimized_slot_set: DashSet<Slot>,
|
||||||
) -> (Vec<Slot>, Vec<SnapshotStorageOne>) {
|
) -> (Vec<Slot>, Vec<Arc<AccountStorageEntry>>) {
|
||||||
let snapshot_storages = self
|
let snapshot_storages = self
|
||||||
.accounts_db()
|
.accounts_db()
|
||||||
.get_snapshot_storages(..=self.starting_slot, None)
|
.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`.
|
/// Creates new storage replacing `storages` that contains only accounts in `minimized_account_set`.
|
||||||
fn filter_storage(
|
fn filter_storage(
|
||||||
&self,
|
&self,
|
||||||
storage: &SnapshotStorageOne,
|
storage: &Arc<AccountStorageEntry>,
|
||||||
dead_storages: &Mutex<Vec<SnapshotStorageOne>>,
|
dead_storages: &Mutex<Vec<Arc<AccountStorageEntry>>>,
|
||||||
) {
|
) {
|
||||||
let slot = storage.slot();
|
let slot = storage.slot();
|
||||||
let GetUniqueAccountsResult {
|
let GetUniqueAccountsResult {
|
||||||
|
|
|
@ -2,8 +2,8 @@ use {
|
||||||
crate::{
|
crate::{
|
||||||
account_storage::AccountStorageMap,
|
account_storage::AccountStorageMap,
|
||||||
accounts_db::{
|
accounts_db::{
|
||||||
AccountShrinkThreshold, AccountsDbConfig, AtomicAppendVecId,
|
AccountShrinkThreshold, AccountStorageEntry, AccountsDbConfig, AtomicAppendVecId,
|
||||||
CalcAccountsHashDataSource, SnapshotStorageOne, SnapshotStoragesOne,
|
CalcAccountsHashDataSource, SnapshotStoragesOne,
|
||||||
},
|
},
|
||||||
accounts_index::AccountSecondaryIndexes,
|
accounts_index::AccountSecondaryIndexes,
|
||||||
accounts_update_notifier_interface::AccountsUpdateNotifier,
|
accounts_update_notifier_interface::AccountsUpdateNotifier,
|
||||||
|
@ -847,7 +847,7 @@ where
|
||||||
pub fn add_bank_snapshot(
|
pub fn add_bank_snapshot(
|
||||||
bank_snapshots_dir: impl AsRef<Path>,
|
bank_snapshots_dir: impl AsRef<Path>,
|
||||||
bank: &Bank,
|
bank: &Bank,
|
||||||
snapshot_storages: &[SnapshotStorageOne],
|
snapshot_storages: &[Arc<AccountStorageEntry>],
|
||||||
snapshot_version: SnapshotVersion,
|
snapshot_version: SnapshotVersion,
|
||||||
) -> Result<BankSnapshotInfo> {
|
) -> Result<BankSnapshotInfo> {
|
||||||
let mut add_snapshot_time = Measure::start("add-snapshot-ms");
|
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
|
/// translates to what we need
|
||||||
pub(crate) fn get_storages_to_serialize(
|
pub(crate) fn get_storages_to_serialize(
|
||||||
snapshot_storages: &[SnapshotStorageOne],
|
snapshot_storages: &[Arc<AccountStorageEntry>],
|
||||||
) -> Vec<Vec<SnapshotStorageOne>> {
|
) -> Vec<Vec<Arc<AccountStorageEntry>>> {
|
||||||
snapshot_storages
|
snapshot_storages
|
||||||
.iter()
|
.iter()
|
||||||
.map(|storage| vec![Arc::clone(storage)])
|
.map(|storage| vec![Arc::clone(storage)])
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
use {
|
use {
|
||||||
crate::accounts_db::SnapshotStorageOne,
|
crate::accounts_db::AccountStorageEntry,
|
||||||
log::*,
|
log::*,
|
||||||
solana_measure::measure::Measure,
|
solana_measure::measure::Measure,
|
||||||
solana_sdk::clock::Slot,
|
solana_sdk::clock::Slot,
|
||||||
std::{
|
std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
ops::{Bound, Range, RangeBounds},
|
ops::{Bound, Range, RangeBounds},
|
||||||
|
sync::Arc,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -16,7 +17,7 @@ pub struct SortedStorages<'a> {
|
||||||
/// the actual storages
|
/// the actual storages
|
||||||
/// A HashMap allows sparse storage and fast lookup of Slot -> Storage.
|
/// A HashMap allows sparse storage and fast lookup of Slot -> Storage.
|
||||||
/// We expect ~432k slots.
|
/// We expect ~432k slots.
|
||||||
storages: HashMap<Slot, &'a SnapshotStorageOne>,
|
storages: HashMap<Slot, &'a Arc<AccountStorageEntry>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> SortedStorages<'a> {
|
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>
|
pub fn iter_range<R>(&'a self, range: &R) -> SortedStoragesIter<'a>
|
||||||
where
|
where
|
||||||
R: RangeBounds<Slot>,
|
R: RangeBounds<Slot>,
|
||||||
|
@ -36,7 +37,7 @@ impl<'a> SortedStorages<'a> {
|
||||||
SortedStoragesIter::new(self, range)
|
SortedStoragesIter::new(self, range)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get(&self, slot: Slot) -> Option<&SnapshotStorageOne> {
|
fn get(&self, slot: Slot) -> Option<&Arc<AccountStorageEntry>> {
|
||||||
self.storages.get(&slot).copied()
|
self.storages.get(&slot).copied()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +63,7 @@ impl<'a> SortedStorages<'a> {
|
||||||
|
|
||||||
// assumption:
|
// assumption:
|
||||||
// source.slot() is unique from all other items in 'source'
|
// 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| {
|
let slots = source.iter().map(|storage| {
|
||||||
storage.slot() // this must be unique. Will be enforced in new_with_slots
|
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.
|
/// 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
|
/// 'source' does not have to be sorted in any way, but is assumed to not have duplicate slot #s
|
||||||
pub fn new_with_slots(
|
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
|
// A slot used as a lower bound, but potentially smaller than the smallest slot in the given 'source' iterator
|
||||||
min_slot: Option<Slot>,
|
min_slot: Option<Slot>,
|
||||||
// highest valid slot. Only matters if source array does not contain a slot >= max_slot_inclusive.
|
// 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> {
|
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> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
let slot = self.next_slot;
|
let slot = self.next_slot;
|
||||||
|
@ -194,13 +195,17 @@ pub mod tests {
|
||||||
use {
|
use {
|
||||||
super::*,
|
super::*,
|
||||||
crate::{
|
crate::{
|
||||||
accounts_db::{AccountStorageEntry, AppendVecId, SnapshotStorageOne},
|
accounts_db::{AccountStorageEntry, AppendVecId},
|
||||||
append_vec::AppendVec,
|
append_vec::AppendVec,
|
||||||
},
|
},
|
||||||
std::sync::Arc,
|
std::sync::Arc,
|
||||||
};
|
};
|
||||||
impl<'a> SortedStorages<'a> {
|
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 mut storages = HashMap::default();
|
||||||
let range = Range {
|
let range = Range {
|
||||||
start: min,
|
start: min,
|
||||||
|
@ -213,7 +218,7 @@ pub mod tests {
|
||||||
Self { range, storages }
|
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());
|
assert_eq!(storages.len(), slots.len());
|
||||||
SortedStorages::new_with_slots(
|
SortedStorages::new_with_slots(
|
||||||
storages.iter().cloned().zip(slots.iter().cloned()),
|
storages.iter().cloned().zip(slots.iter().cloned()),
|
||||||
|
@ -226,7 +231,7 @@ pub mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_sorted_storages_range_iter() {
|
fn test_sorted_storages_range_iter() {
|
||||||
let storages = SortedStorages::empty();
|
let storages = SortedStorages::empty();
|
||||||
let check = |(slot, storages): (Slot, Option<&SnapshotStorageOne>)| {
|
let check = |(slot, storages): (Slot, Option<&Arc<AccountStorageEntry>>)| {
|
||||||
assert!(storages.is_none());
|
assert!(storages.is_none());
|
||||||
slot
|
slot
|
||||||
};
|
};
|
||||||
|
@ -250,7 +255,7 @@ pub mod tests {
|
||||||
// only item is slot 3
|
// only item is slot 3
|
||||||
let s1 = create_sample_store(1);
|
let s1 = create_sample_store(1);
|
||||||
let storages = SortedStorages::new_for_tests(&[&s1], &[3]);
|
let storages = SortedStorages::new_for_tests(&[&s1], &[3]);
|
||||||
let check = |(slot, storages): (Slot, Option<&SnapshotStorageOne>)| {
|
let check = |(slot, storages): (Slot, Option<&Arc<AccountStorageEntry>>)| {
|
||||||
assert!(
|
assert!(
|
||||||
(slot != 3) ^ storages.is_some(),
|
(slot != 3) ^ storages.is_some(),
|
||||||
"slot: {slot}, storages: {storages:?}"
|
"slot: {slot}, storages: {storages:?}"
|
||||||
|
@ -286,7 +291,7 @@ pub mod tests {
|
||||||
let store4 = create_sample_store(4);
|
let store4 = create_sample_store(4);
|
||||||
|
|
||||||
let storages = SortedStorages::new_for_tests(&[&store2, &store4], &[2, 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!(
|
assert!(
|
||||||
(slot != 2 && slot != 4)
|
(slot != 2 && slot != 4)
|
||||||
^ storage
|
^ 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 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 (_temp_dirs, paths) = crate::accounts_db::get_temp_accounts_paths(1).unwrap();
|
||||||
let size: usize = 123;
|
let size: usize = 123;
|
||||||
|
|
Loading…
Reference in New Issue