remove add_root(caching_enabled) (#29245)
This commit is contained in:
parent
8da82e68fc
commit
3e649d2aa0
|
@ -60,7 +60,7 @@ fn bench_accounts_index(bencher: &mut Bencher) {
|
||||||
);
|
);
|
||||||
reclaims.clear();
|
reclaims.clear();
|
||||||
}
|
}
|
||||||
index.add_root(root, false);
|
index.add_root(root);
|
||||||
root += 1;
|
root += 1;
|
||||||
fork += 1;
|
fork += 1;
|
||||||
});
|
});
|
||||||
|
|
|
@ -8561,7 +8561,7 @@ impl AccountsDb {
|
||||||
|
|
||||||
pub fn add_root(&self, slot: Slot) -> AccountsAddRootTiming {
|
pub fn add_root(&self, slot: Slot) -> AccountsAddRootTiming {
|
||||||
let mut index_time = Measure::start("index_add_root");
|
let mut index_time = Measure::start("index_add_root");
|
||||||
self.accounts_index.add_root(slot, true);
|
self.accounts_index.add_root(slot);
|
||||||
index_time.stop();
|
index_time.stop();
|
||||||
let mut cache_time = Measure::start("cache_add_root");
|
let mut cache_time = Measure::start("cache_add_root");
|
||||||
self.accounts_cache.add_root(slot);
|
self.accounts_cache.add_root(slot);
|
||||||
|
@ -9212,7 +9212,7 @@ impl AccountsDb {
|
||||||
let uncleaned_roots = uncleaned_roots.into_inner().unwrap();
|
let uncleaned_roots = uncleaned_roots.into_inner().unwrap();
|
||||||
// Need to add these last, otherwise older updates will be cleaned
|
// Need to add these last, otherwise older updates will be cleaned
|
||||||
for root in &slots {
|
for root in &slots {
|
||||||
self.accounts_index.add_root(*root, true);
|
self.accounts_index.add_root(*root);
|
||||||
}
|
}
|
||||||
self.accounts_index
|
self.accounts_index
|
||||||
.add_uncleaned_roots(uncleaned_roots.into_iter());
|
.add_uncleaned_roots(uncleaned_roots.into_iter());
|
||||||
|
@ -14055,10 +14055,10 @@ pub mod tests {
|
||||||
&mut reclaims,
|
&mut reclaims,
|
||||||
UPSERT_POPULATE_RECLAIMS,
|
UPSERT_POPULATE_RECLAIMS,
|
||||||
);
|
);
|
||||||
accounts_index.add_root(0, false);
|
accounts_index.add_root(0);
|
||||||
accounts_index.add_root(1, false);
|
accounts_index.add_root(1);
|
||||||
accounts_index.add_root(2, false);
|
accounts_index.add_root(2);
|
||||||
accounts_index.add_root(3, false);
|
accounts_index.add_root(3);
|
||||||
let mut purges = HashMap::new();
|
let mut purges = HashMap::new();
|
||||||
let (key0_entry, _) = accounts_index.get_for_tests(&key0, None, None).unwrap();
|
let (key0_entry, _) = accounts_index.get_for_tests(&key0, None, None).unwrap();
|
||||||
purges.insert(
|
purges.insert(
|
||||||
|
@ -16514,7 +16514,7 @@ pub mod tests {
|
||||||
|
|
||||||
let extra = 3;
|
let extra = 3;
|
||||||
let active_root = 2;
|
let active_root = 2;
|
||||||
db.accounts_index.add_root(active_root, false);
|
db.accounts_index.add_root(active_root);
|
||||||
let result = db.calc_alive_ancient_historical_roots(extra);
|
let result = db.calc_alive_ancient_historical_roots(extra);
|
||||||
let expected_alive_roots = [active_root].into_iter().collect();
|
let expected_alive_roots = [active_root].into_iter().collect();
|
||||||
assert_eq!(result, expected_alive_roots, "extra: {extra}");
|
assert_eq!(result, expected_alive_roots, "extra: {extra}");
|
||||||
|
@ -17969,7 +17969,7 @@ pub mod tests {
|
||||||
.insert(slot0, BankHashInfo::default());
|
.insert(slot0, BankHashInfo::default());
|
||||||
db.storage.map.insert(slot0, Arc::default());
|
db.storage.map.insert(slot0, Arc::default());
|
||||||
assert!(!db.bank_hashes.read().unwrap().is_empty());
|
assert!(!db.bank_hashes.read().unwrap().is_empty());
|
||||||
db.accounts_index.add_root(slot0, false);
|
db.accounts_index.add_root(slot0);
|
||||||
assert!(db.accounts_index.is_uncleaned_root(slot0));
|
assert!(db.accounts_index.is_uncleaned_root(slot0));
|
||||||
assert!(db.accounts_index.is_alive_root(slot0));
|
assert!(db.accounts_index.is_alive_root(slot0));
|
||||||
db.handle_dropped_roots_for_ancient(dropped_roots);
|
db.handle_dropped_roots_for_ancient(dropped_roots);
|
||||||
|
|
|
@ -1817,7 +1817,7 @@ impl<T: IndexValue> AccountsIndex<T> {
|
||||||
.contains(&slot)
|
.contains(&slot)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_root(&self, slot: Slot, caching_enabled: bool) {
|
pub fn add_root(&self, slot: Slot) {
|
||||||
self.roots_added.fetch_add(1, Ordering::Relaxed);
|
self.roots_added.fetch_add(1, Ordering::Relaxed);
|
||||||
let mut w_roots_tracker = self.roots_tracker.write().unwrap();
|
let mut w_roots_tracker = self.roots_tracker.write().unwrap();
|
||||||
// `AccountsDb::flush_accounts_cache()` relies on roots being added in order
|
// `AccountsDb::flush_accounts_cache()` relies on roots being added in order
|
||||||
|
@ -1825,10 +1825,6 @@ impl<T: IndexValue> AccountsIndex<T> {
|
||||||
// 'slot' is a root, so it is both 'root' and 'original'
|
// 'slot' is a root, so it is both 'root' and 'original'
|
||||||
w_roots_tracker.alive_roots.insert(slot);
|
w_roots_tracker.alive_roots.insert(slot);
|
||||||
w_roots_tracker.historical_roots.insert(slot);
|
w_roots_tracker.historical_roots.insert(slot);
|
||||||
// we delay cleaning until flushing!
|
|
||||||
if !caching_enabled {
|
|
||||||
w_roots_tracker.uncleaned_roots.insert(slot);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_uncleaned_roots<I>(&self, roots: I)
|
pub fn add_uncleaned_roots<I>(&self, roots: I)
|
||||||
|
@ -2138,14 +2134,14 @@ pub mod tests {
|
||||||
assert_eq!(index.get_next_original_root(slot, ancestors), None);
|
assert_eq!(index.get_next_original_root(slot, ancestors), None);
|
||||||
}
|
}
|
||||||
// roots are now [1]. 0 and 1 both return 1
|
// roots are now [1]. 0 and 1 both return 1
|
||||||
index.add_root(1, true);
|
index.add_root(1);
|
||||||
for slot in 0..2 {
|
for slot in 0..2 {
|
||||||
assert_eq!(index.get_next_original_root(slot, ancestors), Some(1));
|
assert_eq!(index.get_next_original_root(slot, ancestors), Some(1));
|
||||||
}
|
}
|
||||||
assert_eq!(index.get_next_original_root(2, ancestors), None); // no roots after 1, so asking for root >= 2 is None
|
assert_eq!(index.get_next_original_root(2, ancestors), None); // no roots after 1, so asking for root >= 2 is None
|
||||||
|
|
||||||
// roots are now [1, 3]. 0 and 1 both return 1. 2 and 3 both return 3
|
// roots are now [1, 3]. 0 and 1 both return 1. 2 and 3 both return 3
|
||||||
index.add_root(3, true);
|
index.add_root(3);
|
||||||
for slot in 0..2 {
|
for slot in 0..2 {
|
||||||
assert_eq!(index.get_next_original_root(slot, ancestors), Some(1));
|
assert_eq!(index.get_next_original_root(slot, ancestors), Some(1));
|
||||||
}
|
}
|
||||||
|
@ -2192,7 +2188,7 @@ pub mod tests {
|
||||||
assert_eq!(index.get_next_original_root(slot, ancestors), None);
|
assert_eq!(index.get_next_original_root(slot, ancestors), None);
|
||||||
}
|
}
|
||||||
// roots are now [1]. 0 and 1 both return 1
|
// roots are now [1]. 0 and 1 both return 1
|
||||||
index.add_root(1, true);
|
index.add_root(1);
|
||||||
for slot in 0..2 {
|
for slot in 0..2 {
|
||||||
assert_eq!(index.get_next_original_root(slot, ancestors), Some(1));
|
assert_eq!(index.get_next_original_root(slot, ancestors), Some(1));
|
||||||
}
|
}
|
||||||
|
@ -2213,8 +2209,8 @@ pub mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_remove_old_historical_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);
|
||||||
index.add_root(2, true);
|
index.add_root(2);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
index
|
index
|
||||||
.roots_tracker
|
.roots_tracker
|
||||||
|
@ -2254,8 +2250,8 @@ pub mod tests {
|
||||||
|
|
||||||
// now use 'keep'
|
// now use 'keep'
|
||||||
let index = AccountsIndex::<bool>::default_for_tests();
|
let index = AccountsIndex::<bool>::default_for_tests();
|
||||||
index.add_root(1, true);
|
index.add_root(1);
|
||||||
index.add_root(2, true);
|
index.add_root(2);
|
||||||
let hash_set_1 = vec![1].into_iter().collect();
|
let hash_set_1 = vec![1].into_iter().collect();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
index
|
index
|
||||||
|
@ -2942,7 +2938,7 @@ pub mod tests {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
index.add_root(root_slot, false);
|
index.add_root(root_slot);
|
||||||
|
|
||||||
(index, pubkeys)
|
(index, pubkeys)
|
||||||
}
|
}
|
||||||
|
@ -3090,7 +3086,7 @@ pub mod tests {
|
||||||
fn test_is_alive_root() {
|
fn test_is_alive_root() {
|
||||||
let index = AccountsIndex::<bool>::default_for_tests();
|
let index = AccountsIndex::<bool>::default_for_tests();
|
||||||
assert!(!index.is_alive_root(0));
|
assert!(!index.is_alive_root(0));
|
||||||
index.add_root(0, false);
|
index.add_root(0);
|
||||||
assert!(index.is_alive_root(0));
|
assert!(index.is_alive_root(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3111,7 +3107,7 @@ pub mod tests {
|
||||||
);
|
);
|
||||||
assert!(gc.is_empty());
|
assert!(gc.is_empty());
|
||||||
|
|
||||||
index.add_root(0, false);
|
index.add_root(0);
|
||||||
let (list, idx) = index.get_for_tests(&key, None, None).unwrap();
|
let (list, idx) = index.get_for_tests(&key, None, None).unwrap();
|
||||||
assert_eq!(list.slot_list()[idx], (0, true));
|
assert_eq!(list.slot_list()[idx], (0, true));
|
||||||
}
|
}
|
||||||
|
@ -3119,8 +3115,8 @@ pub mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_clean_first() {
|
fn test_clean_first() {
|
||||||
let index = AccountsIndex::<bool>::default_for_tests();
|
let index = AccountsIndex::<bool>::default_for_tests();
|
||||||
index.add_root(0, false);
|
index.add_root(0);
|
||||||
index.add_root(1, false);
|
index.add_root(1);
|
||||||
index.clean_dead_slot(0, &mut AccountsIndexRootsStats::default());
|
index.clean_dead_slot(0, &mut AccountsIndexRootsStats::default());
|
||||||
assert!(index.is_alive_root(1));
|
assert!(index.is_alive_root(1));
|
||||||
assert!(!index.is_alive_root(0));
|
assert!(!index.is_alive_root(0));
|
||||||
|
@ -3130,8 +3126,8 @@ pub mod tests {
|
||||||
fn test_clean_last() {
|
fn test_clean_last() {
|
||||||
//this behavior might be undefined, clean up should only occur on older slots
|
//this behavior might be undefined, clean up should only occur on older slots
|
||||||
let index = AccountsIndex::<bool>::default_for_tests();
|
let index = AccountsIndex::<bool>::default_for_tests();
|
||||||
index.add_root(0, false);
|
index.add_root(0);
|
||||||
index.add_root(1, false);
|
index.add_root(1);
|
||||||
index.clean_dead_slot(1, &mut AccountsIndexRootsStats::default());
|
index.clean_dead_slot(1, &mut AccountsIndexRootsStats::default());
|
||||||
assert!(!index.is_alive_root(1));
|
assert!(!index.is_alive_root(1));
|
||||||
assert!(index.is_alive_root(0));
|
assert!(index.is_alive_root(0));
|
||||||
|
@ -3141,8 +3137,8 @@ pub mod tests {
|
||||||
fn test_clean_and_unclean_slot() {
|
fn test_clean_and_unclean_slot() {
|
||||||
let index = AccountsIndex::<bool>::default_for_tests();
|
let index = AccountsIndex::<bool>::default_for_tests();
|
||||||
assert_eq!(0, index.roots_tracker.read().unwrap().uncleaned_roots.len());
|
assert_eq!(0, index.roots_tracker.read().unwrap().uncleaned_roots.len());
|
||||||
index.add_root(0, false);
|
index.add_root(0);
|
||||||
index.add_root(1, false);
|
index.add_root(1);
|
||||||
assert_eq!(2, index.roots_tracker.read().unwrap().uncleaned_roots.len());
|
assert_eq!(2, index.roots_tracker.read().unwrap().uncleaned_roots.len());
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -3167,8 +3163,8 @@ pub mod tests {
|
||||||
.len()
|
.len()
|
||||||
);
|
);
|
||||||
|
|
||||||
index.add_root(2, false);
|
index.add_root(2);
|
||||||
index.add_root(3, false);
|
index.add_root(3);
|
||||||
assert_eq!(4, index.roots_tracker.read().unwrap().alive_roots.len());
|
assert_eq!(4, index.roots_tracker.read().unwrap().alive_roots.len());
|
||||||
assert_eq!(2, index.roots_tracker.read().unwrap().uncleaned_roots.len());
|
assert_eq!(2, index.roots_tracker.read().unwrap().uncleaned_roots.len());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -3327,9 +3323,9 @@ pub mod tests {
|
||||||
&mut gc,
|
&mut gc,
|
||||||
UPSERT_POPULATE_RECLAIMS,
|
UPSERT_POPULATE_RECLAIMS,
|
||||||
);
|
);
|
||||||
index.add_root(0, false);
|
index.add_root(0);
|
||||||
index.add_root(1, false);
|
index.add_root(1);
|
||||||
index.add_root(3, false);
|
index.add_root(3);
|
||||||
index.upsert(
|
index.upsert(
|
||||||
4,
|
4,
|
||||||
4,
|
4,
|
||||||
|
@ -3401,7 +3397,7 @@ pub mod tests {
|
||||||
|
|
||||||
let purges = index.purge_roots(&key);
|
let purges = index.purge_roots(&key);
|
||||||
assert_eq!(purges, (vec![], false));
|
assert_eq!(purges, (vec![], false));
|
||||||
index.add_root(1, false);
|
index.add_root(1);
|
||||||
|
|
||||||
let purges = index.purge_roots(&key);
|
let purges = index.purge_roots(&key);
|
||||||
assert_eq!(purges, (vec![(1, 10)], true));
|
assert_eq!(purges, (vec![(1, 10)], true));
|
||||||
|
@ -3429,7 +3425,7 @@ pub mod tests {
|
||||||
assert!(index.latest_slot(None, &slot_slice, None).is_none());
|
assert!(index.latest_slot(None, &slot_slice, None).is_none());
|
||||||
|
|
||||||
// Given a root, should return the root
|
// Given a root, should return the root
|
||||||
index.add_root(5, false);
|
index.add_root(5);
|
||||||
assert_eq!(index.latest_slot(None, &slot_slice, None).unwrap(), 1);
|
assert_eq!(index.latest_slot(None, &slot_slice, None).unwrap(), 1);
|
||||||
|
|
||||||
// Given a max_root == root, should still return the root
|
// Given a max_root == root, should still return the root
|
||||||
|
@ -3567,9 +3563,9 @@ pub mod tests {
|
||||||
|
|
||||||
// Add a later root, earlier slots should be reclaimed
|
// Add a later root, earlier slots should be reclaimed
|
||||||
slot_list = vec![(1, true), (2, true), (5, true), (9, true)];
|
slot_list = vec![(1, true), (2, true), (5, true), (9, true)];
|
||||||
index.add_root(1, false);
|
index.add_root(1);
|
||||||
// Note 2 is not a root
|
// Note 2 is not a root
|
||||||
index.add_root(5, false);
|
index.add_root(5);
|
||||||
reclaims = vec![];
|
reclaims = vec![];
|
||||||
index.purge_older_root_entries(&mut slot_list, &mut reclaims, None);
|
index.purge_older_root_entries(&mut slot_list, &mut reclaims, None);
|
||||||
assert_eq!(reclaims, vec![(1, true), (2, true)]);
|
assert_eq!(reclaims, vec![(1, true), (2, true)]);
|
||||||
|
@ -3577,7 +3573,7 @@ pub mod tests {
|
||||||
|
|
||||||
// Add a later root that is not in the list, should not affect the outcome
|
// Add a later root that is not in the list, should not affect the outcome
|
||||||
slot_list = vec![(1, true), (2, true), (5, true), (9, true)];
|
slot_list = vec![(1, true), (2, true), (5, true), (9, true)];
|
||||||
index.add_root(6, false);
|
index.add_root(6);
|
||||||
reclaims = vec![];
|
reclaims = vec![];
|
||||||
index.purge_older_root_entries(&mut slot_list, &mut reclaims, None);
|
index.purge_older_root_entries(&mut slot_list, &mut reclaims, None);
|
||||||
assert_eq!(reclaims, vec![(1, true), (2, true)]);
|
assert_eq!(reclaims, vec![(1, true), (2, true)]);
|
||||||
|
@ -3848,7 +3844,7 @@ pub mod tests {
|
||||||
// If we set a root at `later_slot`, and clean, then even though the account with secondary_key1
|
// If we set a root at `later_slot`, and clean, then even though the account with secondary_key1
|
||||||
// was outdated by the update in the later slot, the primary account key is still alive,
|
// was outdated by the update in the later slot, the primary account key is still alive,
|
||||||
// so both secondary keys will still be kept alive.
|
// so both secondary keys will still be kept alive.
|
||||||
index.add_root(later_slot, false);
|
index.add_root(later_slot);
|
||||||
index.slot_list_mut(&account_key, |slot_list| {
|
index.slot_list_mut(&account_key, |slot_list| {
|
||||||
index.purge_older_root_entries(slot_list, &mut vec![], None)
|
index.purge_older_root_entries(slot_list, &mut vec![], None)
|
||||||
});
|
});
|
||||||
|
@ -4011,7 +4007,7 @@ pub mod tests {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
index.add_root(slot2, true);
|
index.add_root(slot2);
|
||||||
|
|
||||||
{
|
{
|
||||||
let roots_tracker = &index.roots_tracker.read().unwrap();
|
let roots_tracker = &index.roots_tracker.read().unwrap();
|
||||||
|
@ -4124,7 +4120,7 @@ pub mod tests {
|
||||||
// re-add it
|
// re-add it
|
||||||
index.upsert_simple_test(&key, slot1, value);
|
index.upsert_simple_test(&key, slot1, value);
|
||||||
|
|
||||||
index.add_root(slot1, value);
|
index.add_root(slot1);
|
||||||
assert!(!index.clean_rooted_entries(&key, &mut gc, Some(slot2)));
|
assert!(!index.clean_rooted_entries(&key, &mut gc, Some(slot2)));
|
||||||
index.upsert_simple_test(&key, slot2, value);
|
index.upsert_simple_test(&key, slot2, value);
|
||||||
|
|
||||||
|
@ -4163,7 +4159,7 @@ pub mod tests {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
index.add_root(slot2, true);
|
index.add_root(slot2);
|
||||||
{
|
{
|
||||||
let roots_tracker = &index.roots_tracker.read().unwrap();
|
let roots_tracker = &index.roots_tracker.read().unwrap();
|
||||||
let slot_list = vec![(slot2, value)];
|
let slot_list = vec![(slot2, value)];
|
||||||
|
|
|
@ -10054,7 +10054,7 @@ pub(crate) mod tests {
|
||||||
.accounts
|
.accounts
|
||||||
.accounts_db
|
.accounts_db
|
||||||
.accounts_index
|
.accounts_index
|
||||||
.add_root(genesis_bank1.slot() + 1, false);
|
.add_root(genesis_bank1.slot() + 1);
|
||||||
bank1_without_zero
|
bank1_without_zero
|
||||||
.rc
|
.rc
|
||||||
.accounts
|
.accounts
|
||||||
|
|
Loading…
Reference in New Issue