From b1771b92ecd4811edc81e4206455f69360e0d16e Mon Sep 17 00:00:00 2001 From: sakridge Date: Sun, 29 Mar 2020 14:42:34 -0700 Subject: [PATCH] Calculate ref counts earlier to prevent bad clean (#9147) --- runtime/src/accounts_db.rs | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 6e31336398..245793f584 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -775,14 +775,23 @@ impl AccountsDB { } } - for account_infos in purges.values() { - let mut no_delete = false; - for (_slot, account_info) in account_infos { - if *store_counts.get(&account_info.store_id).unwrap() != 0 { - no_delete = true; - break; - } - } + // Another pass to check if there are some filtered accounts which + // do not match the criteria of deleting all appendvecs which contain them + // then increment their storage count. + for (pubkey, account_infos) in &purges { + let no_delete = + if account_infos.len() as u64 != accounts_index.ref_count_from_storage(&pubkey) { + true + } else { + let mut no_delete = false; + for (_slot, account_info) in account_infos { + if *store_counts.get(&account_info.store_id).unwrap() != 0 { + no_delete = true; + break; + } + } + no_delete + }; if no_delete { for (_slot, account_info) in account_infos { *store_counts.get_mut(&account_info.store_id).unwrap() += 1; @@ -794,17 +803,13 @@ impl AccountsDB { // Only keep purges where the entire history of the account in the root set // can be purged. All AppendVecs for those updates are dead. let mut purge_filter = Measure::start("purge_filter"); - purges.retain(|pubkey, account_infos| { - let mut would_unref_count = 0; - for (_slot, account_info) in account_infos { - if *store_counts.get(&account_info.store_id).unwrap() == 0 { - would_unref_count += 1; - } else { + purges.retain(|_pubkey, account_infos| { + for (_slot, account_info) in account_infos.iter() { + if *store_counts.get(&account_info.store_id).unwrap() != 0 { return false; } } - - would_unref_count == accounts_index.ref_count_from_storage(&pubkey) + true }); purge_filter.stop();