refactor/document calc_delete_dependencies (#27272)
This commit is contained in:
parent
7bdeea10ad
commit
97036b1c75
|
@ -2211,6 +2211,10 @@ impl AccountsDb {
|
|||
.fetch_add(measure.as_us(), Ordering::Relaxed);
|
||||
}
|
||||
|
||||
/// increment store_counts to non-zero for all stores that can not be deleted.
|
||||
/// a store cannot be deleted if:
|
||||
/// 1. one of the pubkeys in the store has account info to a store whose store count is not going to zero
|
||||
/// 2. a pubkey we were planning to remove is not removing all stores that contain the account
|
||||
fn calc_delete_dependencies(
|
||||
purges: &HashMap<Pubkey, (SlotList<AccountInfo>, RefCount)>,
|
||||
store_counts: &mut HashMap<AppendVecId, (usize, HashSet<Pubkey>)>,
|
||||
|
@ -2220,7 +2224,28 @@ impl AccountsDb {
|
|||
// then increment their storage count.
|
||||
let mut already_counted = HashSet::new();
|
||||
for (pubkey, (account_infos, ref_count_from_storage)) in purges.iter() {
|
||||
let no_delete = if account_infos.len() as RefCount != *ref_count_from_storage {
|
||||
if account_infos.len() as RefCount == *ref_count_from_storage {
|
||||
let mut delete = true;
|
||||
for (_slot, account_info) in account_infos {
|
||||
debug!(
|
||||
"calc_delete_dependencies()
|
||||
storage id: {},
|
||||
count len: {}",
|
||||
account_info.store_id(),
|
||||
store_counts.get(&account_info.store_id()).unwrap().0,
|
||||
);
|
||||
if store_counts.get(&account_info.store_id()).unwrap().0 != 0 {
|
||||
// one of the pubkeys in the store has account info to a store whose store count is not going to zero
|
||||
delete = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if delete {
|
||||
// this pubkey can be deleted from all stores it is in
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
// a pubkey we were planning to remove is not removing all stores that contain the account
|
||||
debug!(
|
||||
"calc_delete_dependencies(),
|
||||
pubkey: {},
|
||||
|
@ -2232,45 +2257,29 @@ impl AccountsDb {
|
|||
account_infos.len(),
|
||||
ref_count_from_storage,
|
||||
);
|
||||
true
|
||||
} else {
|
||||
let mut no_delete = false;
|
||||
for (_slot, account_info) in account_infos {
|
||||
debug!(
|
||||
"calc_delete_dependencies()
|
||||
storage id: {},
|
||||
count len: {}",
|
||||
account_info.store_id(),
|
||||
store_counts.get(&account_info.store_id()).unwrap().0,
|
||||
);
|
||||
if store_counts.get(&account_info.store_id()).unwrap().0 != 0 {
|
||||
no_delete = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
no_delete
|
||||
};
|
||||
if no_delete {
|
||||
let mut pending_store_ids = HashSet::new();
|
||||
for (_slot, account_info) in account_infos {
|
||||
if !already_counted.contains(&account_info.store_id()) {
|
||||
pending_store_ids.insert(account_info.store_id());
|
||||
}
|
||||
}
|
||||
while !pending_store_ids.is_empty() {
|
||||
let id = pending_store_ids.iter().next().cloned().unwrap();
|
||||
pending_store_ids.remove(&id);
|
||||
if !already_counted.insert(id) {
|
||||
continue;
|
||||
}
|
||||
store_counts.get_mut(&id).unwrap().0 += 1;
|
||||
}
|
||||
|
||||
let affected_pubkeys = &store_counts.get(&id).unwrap().1;
|
||||
for key in affected_pubkeys {
|
||||
for (_slot, account_info) in &purges.get(key).unwrap().0 {
|
||||
if !already_counted.contains(&account_info.store_id()) {
|
||||
pending_store_ids.insert(account_info.store_id());
|
||||
}
|
||||
// increment store_counts to non-zero for all stores that can not be deleted.
|
||||
let mut pending_store_ids = HashSet::new();
|
||||
for (_slot, account_info) in account_infos {
|
||||
if !already_counted.contains(&account_info.store_id()) {
|
||||
pending_store_ids.insert(account_info.store_id());
|
||||
}
|
||||
}
|
||||
while !pending_store_ids.is_empty() {
|
||||
let id = pending_store_ids.iter().next().cloned().unwrap();
|
||||
pending_store_ids.remove(&id);
|
||||
if !already_counted.insert(id) {
|
||||
continue;
|
||||
}
|
||||
// the point of all this code: increment the store count to non-zero
|
||||
store_counts.get_mut(&id).unwrap().0 += 1;
|
||||
|
||||
let affected_pubkeys = &store_counts.get(&id).unwrap().1;
|
||||
for key in affected_pubkeys {
|
||||
for (_slot, account_info) in &purges.get(key).unwrap().0 {
|
||||
if !already_counted.contains(&account_info.store_id()) {
|
||||
pending_store_ids.insert(account_info.store_id());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue