AcctInfo: make offset private, add accessor (#21838)

This commit is contained in:
Jeff Washington (jwash)
2021-12-13 14:43:26 -06:00
committed by GitHub
parent 8aa3d690b5
commit 6155ef6377
2 changed files with 37 additions and 17 deletions

View File

@ -6,7 +6,7 @@ pub struct AccountInfo {
pub store_id: AppendVecId, pub store_id: AppendVecId,
/// offset into the storage /// offset into the storage
pub offset: usize, offset: usize,
/// needed to track shrink candidacy in bytes. Used to update the number /// needed to track shrink candidacy in bytes. Used to update the number
/// of alive bytes in an AppendVec as newer slots purge outdated entries /// of alive bytes in an AppendVec as newer slots purge outdated entries
@ -33,6 +33,10 @@ impl AccountInfo {
} }
} }
pub fn offset(&self) -> usize {
self.offset
}
pub fn stored_size(&self) -> usize { pub fn stored_size(&self) -> usize {
self.stored_size self.stored_size
} }

View File

@ -2233,7 +2233,7 @@ impl AccountsDb {
// `clean_accounts_older_than_root()` // `clean_accounts_older_than_root()`
let was_reclaimed = removed_accounts let was_reclaimed = removed_accounts
.get(&account_info.store_id) .get(&account_info.store_id)
.map(|store_removed| store_removed.contains(&account_info.offset)) .map(|store_removed| store_removed.contains(&account_info.offset()))
.unwrap_or(false); .unwrap_or(false);
if was_reclaimed { if was_reclaimed {
return false; return false;
@ -2589,7 +2589,7 @@ impl AccountsDb {
if let Some(locked_entry) = lookup { if let Some(locked_entry) = lookup {
let is_alive = locked_entry.slot_list().iter().any(|(_slot, i)| { let is_alive = locked_entry.slot_list().iter().any(|(_slot, i)| {
i.store_id == stored_account.store_id i.store_id == stored_account.store_id
&& i.offset == stored_account.account.offset && i.offset() == stored_account.account.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.
@ -3087,7 +3087,12 @@ impl AccountsDb {
bank_id, bank_id,
|pubkey, (account_info, slot)| { |pubkey, (account_info, slot)| {
let account_slot = self let account_slot = self
.get_account_accessor(slot, pubkey, account_info.store_id, account_info.offset) .get_account_accessor(
slot,
pubkey,
account_info.store_id,
account_info.offset(),
)
.get_loaded_account() .get_loaded_account()
.map(|loaded_account| (pubkey, loaded_account.take_account(), slot)); .map(|loaded_account| (pubkey, loaded_account.take_account(), slot));
scan_func(&mut collector, account_slot) scan_func(&mut collector, account_slot)
@ -3115,7 +3120,12 @@ impl AccountsDb {
ancestors, ancestors,
|pubkey, (account_info, slot)| { |pubkey, (account_info, slot)| {
if let Some(loaded_account) = self if let Some(loaded_account) = self
.get_account_accessor(slot, pubkey, account_info.store_id, account_info.offset) .get_account_accessor(
slot,
pubkey,
account_info.store_id,
account_info.offset(),
)
.get_loaded_account() .get_loaded_account()
{ {
scan_func(&mut collector, (pubkey, loaded_account, slot)); scan_func(&mut collector, (pubkey, loaded_account, slot));
@ -3156,7 +3166,12 @@ impl AccountsDb {
// changes to the index entry. // changes to the index entry.
// For details, see the comment in retry_to_get_account_accessor() // For details, see the comment in retry_to_get_account_accessor()
let account_slot = self let account_slot = self
.get_account_accessor(slot, pubkey, account_info.store_id, account_info.offset) .get_account_accessor(
slot,
pubkey,
account_info.store_id,
account_info.offset(),
)
.get_loaded_account() .get_loaded_account()
.map(|loaded_account| (pubkey, loaded_account.take_account(), slot)) .map(|loaded_account| (pubkey, loaded_account.take_account(), slot))
.unwrap(); .unwrap();
@ -3197,7 +3212,12 @@ impl AccountsDb {
index_key, index_key,
|pubkey, (account_info, slot)| { |pubkey, (account_info, slot)| {
let account_slot = self let account_slot = self
.get_account_accessor(slot, pubkey, account_info.store_id, account_info.offset) .get_account_accessor(
slot,
pubkey,
account_info.store_id,
account_info.offset(),
)
.get_loaded_account() .get_loaded_account()
.map(|loaded_account| (pubkey, loaded_account.take_account(), slot)); .map(|loaded_account| (pubkey, loaded_account.take_account(), slot));
scan_func(&mut collector, account_slot) scan_func(&mut collector, account_slot)
@ -3327,13 +3347,9 @@ impl AccountsDb {
}; };
let slot_list = lock.slot_list(); let slot_list = lock.slot_list();
let ( let (slot, info) = slot_list[index];
slot, let store_id = info.store_id;
AccountInfo { let offset = info.offset();
store_id, offset, ..
},
) = slot_list[index];
let some_from_slow_path = if clone_in_lock { let some_from_slow_path = if clone_in_lock {
// the fast path must have failed.... so take the slower approach // the fast path must have failed.... so take the slower approach
// of copying potentially large Account::data inside the lock. // of copying potentially large Account::data inside the lock.
@ -5120,7 +5136,7 @@ impl AccountsDb {
*slot, *slot,
pubkey, pubkey,
account_info.store_id, account_info.store_id,
account_info.offset, account_info.offset(),
) )
.get_loaded_account() .get_loaded_account()
.and_then( .and_then(
@ -6002,7 +6018,7 @@ impl AccountsDb {
reclaimed_offsets reclaimed_offsets
.entry(account_info.store_id) .entry(account_info.store_id)
.or_default() .or_default()
.insert(account_info.offset); .insert(account_info.offset());
} }
if let Some(expected_slot) = expected_slot { if let Some(expected_slot) = expected_slot {
assert_eq!(*slot, expected_slot); assert_eq!(*slot, expected_slot);
@ -7076,7 +7092,7 @@ impl AccountsDb {
.storage .storage
.get_account_storage_entry(*slot, account_info.store_id); .get_account_storage_entry(*slot, account_info.store_id);
let mut accessor = LoadedAccountAccessor::Stored( let mut accessor = LoadedAccountAccessor::Stored(
maybe_storage_entry.map(|entry| (entry, account_info.offset)), maybe_storage_entry.map(|entry| (entry, account_info.offset())),
); );
let loaded_account = accessor.check_and_get_loaded_account(); let loaded_account = accessor.check_and_get_loaded_account();
let account = loaded_account.take_account(); let account = loaded_account.take_account();