just use slot to determine alive while shrinking (#29613)
This commit is contained in:
parent
1c862f0b66
commit
a5106e110a
|
@ -144,13 +144,6 @@ impl AccountInfo {
|
|||
self.stored_size_mask & !ALL_FLAGS
|
||||
}
|
||||
|
||||
/// true iff store_id and offset match self AND self is not cached
|
||||
/// If self is cached, then store_id and offset are meaningless.
|
||||
pub fn matches_storage_location(&self, store_id: AppendVecId, offset: Offset) -> bool {
|
||||
// order is set for best short circuit
|
||||
self.store_id == store_id && self.offset() == offset && !self.is_cached()
|
||||
}
|
||||
|
||||
pub fn storage_location(&self) -> StorageLocation {
|
||||
if self.is_cached() {
|
||||
StorageLocation::Cached
|
||||
|
@ -182,26 +175,4 @@ mod test {
|
|||
let offset = 1; // not aligned
|
||||
AccountInfo::new(StorageLocation::AppendVec(0, offset), 0, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_matches_storage_location() {
|
||||
let offset = 0;
|
||||
let id = 0;
|
||||
let info = AccountInfo::new(StorageLocation::AppendVec(id, offset), 0, 0);
|
||||
assert!(info.matches_storage_location(id, offset));
|
||||
|
||||
// wrong offset
|
||||
let offset = ALIGN_BOUNDARY_OFFSET;
|
||||
assert!(!info.matches_storage_location(id, offset));
|
||||
|
||||
// wrong id
|
||||
let offset = 0;
|
||||
let id = 1;
|
||||
assert!(!info.matches_storage_location(id, offset));
|
||||
|
||||
// is cached
|
||||
let id = CACHE_VIRTUAL_STORAGE_ID;
|
||||
let info = AccountInfo::new(StorageLocation::Cached, 0, 0);
|
||||
assert!(!info.matches_storage_location(id, offset));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3628,12 +3628,9 @@ impl AccountsDb {
|
|||
let mut result = AccountsIndexScanResult::None;
|
||||
if let Some((slot_list, _ref_count)) = slots_refs {
|
||||
let stored_account = &accounts[index];
|
||||
let is_alive = slot_list.iter().any(|(slot, acct_info)| {
|
||||
let is_alive = slot_list.iter().any(|(slot, _acct_info)| {
|
||||
// if the accounts index contains an entry at this slot, then the append vec we're asking about contains this item and thus, it is alive at this slot
|
||||
*slot == slot_to_shrink
|
||||
&& acct_info.matches_storage_location(
|
||||
acct_info.store_id(),
|
||||
stored_account.account.offset,
|
||||
)
|
||||
});
|
||||
if !is_alive {
|
||||
// This pubkey was found in the storage, but no longer exists in the index.
|
||||
|
|
Loading…
Reference in New Issue