simplify do_shrink_slot_stores, delay/reduce account clone (#16691)

This commit is contained in:
Jeff Washington (jwash) 2021-04-21 11:17:38 -05:00 committed by GitHub
parent 37b8587d4e
commit 189d2121e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 30 additions and 41 deletions

View File

@ -1840,13 +1840,10 @@ impl AccountsDb {
where where
I: Iterator<Item = &'a Arc<AccountStorageEntry>>, I: Iterator<Item = &'a Arc<AccountStorageEntry>>,
{ {
struct FoundStoredAccount { struct FoundStoredAccount<'a> {
account: AccountSharedData, pub account: StoredAccountMeta<'a>,
account_hash: Hash, pub store_id: AppendVecId,
account_size: usize, pub account_size: usize,
store_id: AppendVecId,
offset: usize,
write_version: u64,
} }
debug!("do_shrink_slot_stores: slot: {}", slot); debug!("do_shrink_slot_stores: slot: {}", slot);
let mut stored_accounts: HashMap<Pubkey, FoundStoredAccount> = HashMap::new(); let mut stored_accounts: HashMap<Pubkey, FoundStoredAccount> = HashMap::new();
@ -1855,28 +1852,21 @@ impl AccountsDb {
let mut start = 0; let mut start = 0;
original_bytes += store.total_bytes(); original_bytes += store.total_bytes();
while let Some((account, next)) = store.accounts.get_account(start) { while let Some((account, next)) = store.accounts.get_account(start) {
match stored_accounts.entry(account.meta.pubkey) { let new_entry = FoundStoredAccount {
account,
store_id: store.append_vec_id(),
account_size: next - start,
};
match stored_accounts.entry(new_entry.account.meta.pubkey) {
Entry::Occupied(mut occupied_entry) => { Entry::Occupied(mut occupied_entry) => {
if account.meta.write_version > occupied_entry.get().write_version { if new_entry.account.meta.write_version
occupied_entry.insert(FoundStoredAccount { > occupied_entry.get().account.meta.write_version
account: account.clone_account(), {
account_hash: *account.hash, occupied_entry.insert(new_entry);
account_size: next - start,
store_id: store.append_vec_id(),
offset: account.offset,
write_version: account.meta.write_version,
});
} }
} }
Entry::Vacant(vacant_entry) => { Entry::Vacant(vacant_entry) => {
vacant_entry.insert(FoundStoredAccount { vacant_entry.insert(new_entry);
account: account.clone_account(),
account_hash: *account.hash,
account_size: next - start,
store_id: store.append_vec_id(),
offset: account.offset,
write_version: account.meta.write_version,
});
} }
} }
start = next; start = next;
@ -1889,17 +1879,11 @@ impl AccountsDb {
stored_accounts stored_accounts
.iter() .iter()
.filter(|(pubkey, stored_account)| { .filter(|(pubkey, stored_account)| {
let FoundStoredAccount {
account_size,
store_id,
offset,
..
} = stored_account;
if let Some((locked_entry, _)) = self.accounts_index.get(pubkey, None, None) { if let Some((locked_entry, _)) = self.accounts_index.get(pubkey, None, None) {
let is_alive = locked_entry let is_alive = locked_entry.slot_list().iter().any(|(_slot, i)| {
.slot_list() i.store_id == stored_account.store_id
.iter() && i.offset == stored_account.account.offset
.any(|(_slot, i)| i.store_id == *store_id && i.offset == *offset); });
if !is_alive { if !is_alive {
// This pubkey was found in the storage, but no longer exists in the index. // This pubkey was found in the storage, but no longer exists in the index.
// It would have had a ref to the storage from the initial store, but it will // It would have had a ref to the storage from the initial store, but it will
@ -1907,7 +1891,7 @@ impl AccountsDb {
// rewriting the storage entries. // rewriting the storage entries.
locked_entry.unref() locked_entry.unref()
} else { } else {
alive_total += *account_size as u64; alive_total += stored_account.account_size as u64;
} }
is_alive is_alive
} else { } else {
@ -1938,15 +1922,20 @@ impl AccountsDb {
let mut store_accounts_timing = StoreAccountsTiming::default(); let mut store_accounts_timing = StoreAccountsTiming::default();
if aligned_total > 0 { if aligned_total > 0 {
let mut start = Measure::start("find_alive_elapsed"); let mut start = Measure::start("find_alive_elapsed");
let mut accounts = Vec::with_capacity(alive_accounts.len()); let mut stored_accounts = Vec::with_capacity(alive_accounts.len());
let mut hashes = Vec::with_capacity(alive_accounts.len()); let mut hashes = Vec::with_capacity(alive_accounts.len());
let mut write_versions = Vec::with_capacity(alive_accounts.len()); let mut write_versions = Vec::with_capacity(alive_accounts.len());
for (pubkey, alive_account) in alive_accounts { for (_pubkey, alive_account) in alive_accounts.iter() {
accounts.push((pubkey, &alive_account.account)); stored_accounts.push(alive_account.account.clone_account());
hashes.push(alive_account.account_hash); hashes.push(*alive_account.account.hash);
write_versions.push(alive_account.write_version); write_versions.push(alive_account.account.meta.write_version);
} }
let accounts = alive_accounts
.iter()
.map(|(pubkey, _)| *pubkey)
.zip(stored_accounts.iter())
.collect::<Vec<_>>();
start.stop(); start.stop();
find_alive_elapsed = start.as_us(); find_alive_elapsed = start.as_us();