rename remove_old_roots (#24059)

This commit is contained in:
Jeff Washington (jwash)
2022-04-02 12:01:13 -05:00
committed by GitHub
parent 3ca4fffa78
commit ec97d6d078
2 changed files with 14 additions and 14 deletions

View File

@ -5529,8 +5529,8 @@ impl AccountsDb {
let result = self.calculate_accounts_hash_without_index(config, &storages, timings); let result = self.calculate_accounts_hash_without_index(config, &storages, timings);
// now that calculate_accounts_hash_without_index is complete, we can remove old roots // now that calculate_accounts_hash_without_index is complete, we can remove old historical roots
self.remove_old_roots(slot); self.remove_old_historical_roots(slot, &HashSet::default());
result result
} else { } else {
@ -5771,15 +5771,15 @@ impl AccountsDb {
} }
} }
/// get rid of old original_roots /// get rid of old historical roots
fn remove_old_roots(&self, slot: Slot) { /// except keep those in 'keep'
fn remove_old_historical_roots(&self, current_max_root_inclusive: Slot, keep: &HashSet<Slot>) {
// epoch_schedule::DEFAULT_SLOTS_PER_EPOCH is a sufficient approximation for now // epoch_schedule::DEFAULT_SLOTS_PER_EPOCH is a sufficient approximation for now
let width = solana_sdk::epoch_schedule::DEFAULT_SLOTS_PER_EPOCH * 11 / 10; // a buffer let width = solana_sdk::epoch_schedule::DEFAULT_SLOTS_PER_EPOCH * 11 / 10; // a buffer
if slot > width { if current_max_root_inclusive > width {
let min_root = slot - width; let min_root = current_max_root_inclusive - width;
let valid_slots = HashSet::default();
self.accounts_index self.accounts_index
.remove_old_original_roots(min_root, &valid_slots); .remove_old_historical_roots(min_root, keep);
} }
} }

View File

@ -1751,7 +1751,7 @@ impl<T: IndexValue> AccountsIndex<T> {
/// roots are removed form 'roots' as all entries in the append vec become outdated. /// roots are removed form 'roots' as all entries in the append vec become outdated.
/// This function exists to clean older entries from 'roots_original'. /// This function exists to clean older entries from 'roots_original'.
/// all roots < 'oldest_slot_to_keep' are removed from 'roots_original'. /// all roots < 'oldest_slot_to_keep' are removed from 'roots_original'.
pub fn remove_old_original_roots(&self, oldest_slot_to_keep: Slot, keep: &HashSet<Slot>) { pub fn remove_old_historical_roots(&self, oldest_slot_to_keep: Slot, keep: &HashSet<Slot>) {
let w_roots_tracker = self.roots_tracker.read().unwrap(); let w_roots_tracker = self.roots_tracker.read().unwrap();
let mut roots = w_roots_tracker let mut roots = w_roots_tracker
.roots_original .roots_original
@ -2081,7 +2081,7 @@ pub mod tests {
} }
#[test] #[test]
fn test_remove_old_original_roots() { fn test_remove_old_historical_roots() {
let index = AccountsIndex::<bool>::default_for_tests(); let index = AccountsIndex::<bool>::default_for_tests();
index.add_root(1, true); index.add_root(1, true);
index.add_root(2, true); index.add_root(2, true);
@ -2090,12 +2090,12 @@ pub mod tests {
vec![1, 2] vec![1, 2]
); );
let empty_hash_set = HashSet::default(); let empty_hash_set = HashSet::default();
index.remove_old_original_roots(2, &empty_hash_set); index.remove_old_historical_roots(2, &empty_hash_set);
assert_eq!( assert_eq!(
index.roots_tracker.read().unwrap().roots_original.get_all(), index.roots_tracker.read().unwrap().roots_original.get_all(),
vec![2] vec![2]
); );
index.remove_old_original_roots(3, &empty_hash_set); index.remove_old_historical_roots(3, &empty_hash_set);
assert!( assert!(
index index
.roots_tracker .roots_tracker
@ -2116,12 +2116,12 @@ pub mod tests {
index.roots_tracker.read().unwrap().roots_original.get_all(), index.roots_tracker.read().unwrap().roots_original.get_all(),
vec![1, 2] vec![1, 2]
); );
index.remove_old_original_roots(2, &hash_set_1); index.remove_old_historical_roots(2, &hash_set_1);
assert_eq!( assert_eq!(
index.roots_tracker.read().unwrap().roots_original.get_all(), index.roots_tracker.read().unwrap().roots_original.get_all(),
vec![1, 2] vec![1, 2]
); );
index.remove_old_original_roots(3, &hash_set_1); index.remove_old_historical_roots(3, &hash_set_1);
assert_eq!( assert_eq!(
index.roots_tracker.read().unwrap().roots_original.get_all(), index.roots_tracker.read().unwrap().roots_original.get_all(),
vec![1] vec![1]