move uncleaned roots code to test mod (#33029)

This commit is contained in:
Jeff Washington (jwash) 2023-08-28 14:01:27 -07:00 committed by GitHub
parent ce71461bad
commit 97d6e6f738
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 30 deletions

View File

@ -1950,31 +1950,6 @@ impl<T: IndexValue, U: DiskIndexValue + From<T> + Into<T>> AccountsIndex<T, U> {
w_roots_tracker.previous_uncleaned_roots = cleaned_roots;
}
#[cfg(test)]
pub fn clear_uncleaned_roots(&self, max_clean_root: Option<Slot>) -> HashSet<Slot> {
let mut cleaned_roots = HashSet::new();
let mut w_roots_tracker = self.roots_tracker.write().unwrap();
w_roots_tracker.uncleaned_roots.retain(|root| {
let is_cleaned = max_clean_root
.map(|max_clean_root| *root <= max_clean_root)
.unwrap_or(true);
if is_cleaned {
cleaned_roots.insert(*root);
}
// Only keep the slots that have yet to be cleaned
!is_cleaned
});
cleaned_roots
}
pub fn is_uncleaned_root(&self, slot: Slot) -> bool {
self.roots_tracker
.read()
.unwrap()
.uncleaned_roots
.contains(&slot)
}
pub fn num_alive_roots(&self) -> usize {
self.roots_tracker.read().unwrap().alive_roots.len()
}
@ -1984,11 +1959,6 @@ impl<T: IndexValue, U: DiskIndexValue + From<T> + Into<T>> AccountsIndex<T, U> {
tracker.alive_roots.get_all()
}
#[cfg(test)]
pub fn clear_roots(&self) {
self.roots_tracker.write().unwrap().alive_roots.clear()
}
pub fn clone_uncleaned_roots(&self) -> HashSet<Slot> {
self.roots_tracker.read().unwrap().uncleaned_roots.clone()
}
@ -3902,6 +3872,34 @@ pub mod tests {
);
assert!(gc.is_empty());
}
pub fn clear_uncleaned_roots(&self, max_clean_root: Option<Slot>) -> HashSet<Slot> {
let mut cleaned_roots = HashSet::new();
let mut w_roots_tracker = self.roots_tracker.write().unwrap();
w_roots_tracker.uncleaned_roots.retain(|root| {
let is_cleaned = max_clean_root
.map(|max_clean_root| *root <= max_clean_root)
.unwrap_or(true);
if is_cleaned {
cleaned_roots.insert(*root);
}
// Only keep the slots that have yet to be cleaned
!is_cleaned
});
cleaned_roots
}
pub(crate) fn is_uncleaned_root(&self, slot: Slot) -> bool {
self.roots_tracker
.read()
.unwrap()
.uncleaned_roots
.contains(&slot)
}
pub fn clear_roots(&self) {
self.roots_tracker.write().unwrap().alive_roots.clear()
}
}
#[test]