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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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);
// now that calculate_accounts_hash_without_index is complete, we can remove old roots
self.remove_old_roots(slot);
// now that calculate_accounts_hash_without_index is complete, we can remove old historical roots
self.remove_old_historical_roots(slot, &HashSet::default());
result
} else {
@ -5771,15 +5771,15 @@ impl AccountsDb {
}
}
/// get rid of old original_roots
fn remove_old_roots(&self, slot: Slot) {
/// get rid of old historical roots
/// 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
let width = solana_sdk::epoch_schedule::DEFAULT_SLOTS_PER_EPOCH * 11 / 10; // a buffer
if slot > width {
let min_root = slot - width;
let valid_slots = HashSet::default();
if current_max_root_inclusive > width {
let min_root = current_max_root_inclusive - width;
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.
/// This function exists to clean older entries 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 mut roots = w_roots_tracker
.roots_original
@ -2081,7 +2081,7 @@ pub mod tests {
}
#[test]
fn test_remove_old_original_roots() {
fn test_remove_old_historical_roots() {
let index = AccountsIndex::<bool>::default_for_tests();
index.add_root(1, true);
index.add_root(2, true);
@ -2090,12 +2090,12 @@ pub mod tests {
vec![1, 2]
);
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!(
index.roots_tracker.read().unwrap().roots_original.get_all(),
vec![2]
);
index.remove_old_original_roots(3, &empty_hash_set);
index.remove_old_historical_roots(3, &empty_hash_set);
assert!(
index
.roots_tracker
@ -2116,12 +2116,12 @@ pub mod tests {
index.roots_tracker.read().unwrap().roots_original.get_all(),
vec![1, 2]
);
index.remove_old_original_roots(2, &hash_set_1);
index.remove_old_historical_roots(2, &hash_set_1);
assert_eq!(
index.roots_tracker.read().unwrap().roots_original.get_all(),
vec![1, 2]
);
index.remove_old_original_roots(3, &hash_set_1);
index.remove_old_historical_roots(3, &hash_set_1);
assert_eq!(
index.roots_tracker.read().unwrap().roots_original.get_all(),
vec![1]