ancient_append_vec refactoring (#25203)

This commit is contained in:
Jeff Washington (jwash) 2022-05-13 16:40:26 -05:00 committed by GitHub
parent cb037e49ea
commit d7dcb62fe1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 27 deletions

View File

@ -6,11 +6,10 @@
#![allow(dead_code)]
use {
crate::{
accounts_db::{AccountStorageEntry, FoundStoredAccount, SnapshotStorage},
accounts_db::FoundStoredAccount,
append_vec::{AppendVec, StoredAccountMeta},
},
solana_sdk::{clock::Slot, hash::Hash, pubkey::Pubkey},
std::{collections::HashMap, sync::Arc},
};
/// a set of accounts need to be stored.
@ -39,7 +38,7 @@ impl<'a> AccountsToStore<'a> {
/// available_bytes: how many bytes remain in the primary storage. Excess accounts will be directed to an overflow storage
pub fn new(
mut available_bytes: u64,
stored_accounts: &'a HashMap<Pubkey, FoundStoredAccount>,
stored_accounts: &'a Vec<(&'a Pubkey, &'a FoundStoredAccount<'a>)>,
slot: Slot,
) -> Self {
let num_accounts = stored_accounts.len();
@ -110,28 +109,6 @@ pub fn is_ancient(storage: &AppendVec) -> bool {
storage.capacity() >= get_ancient_append_vec_capacity()
}
/// return true if the accounts in this slot should be moved to an ancient append vec
/// otherwise, return false and the caller can skip this slot
/// side effect could be updating 'current_ancient'
pub fn should_move_to_ancient_append_vec(
all_storages: &SnapshotStorage,
current_ancient: &mut Option<(Slot, Arc<AccountStorageEntry>)>,
slot: Slot,
) -> bool {
if current_ancient.is_none() && all_storages.len() == 1 {
let first_storage = all_storages.first().unwrap();
if is_ancient(&first_storage.accounts) {
if is_full_ancient(&first_storage.accounts) {
return false; // skip this full ancient append vec completely
}
// this slot is ancient and can become the 'current' ancient for other slots to be squashed into
*current_ancient = Some((slot, Arc::clone(first_storage)));
return false; // we're done with this slot - this slot IS the ancient append vec
}
}
true
}
#[cfg(test)]
pub mod tests {
use {
@ -195,7 +172,8 @@ pub mod tests {
store_id,
account_size,
};
let map = vec![(pubkey, found)].into_iter().collect();
let src = vec![(pubkey, found)];
let map = src.iter().map(|(a, b)| (a, b)).collect();
for (selector, available_bytes) in [
(StorageSelector::Primary, account_size),
(StorageSelector::Overflow, account_size - 1),
@ -206,7 +184,7 @@ pub mod tests {
assert_eq!(
accounts,
map.iter()
.map(|(a, b)| (a, &b.account, slot))
.map(|(a, b)| (*a, &b.account, slot))
.collect::<Vec<_>>(),
"mismatch"
);