rework assert_no_shrink_in_progress to get assert stack easily (#31251)

This commit is contained in:
Jeff Washington (jwash) 2023-04-19 13:36:24 -05:00 committed by GitHub
parent 812d899c7f
commit 9124d1f35d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 16 deletions

View File

@ -67,15 +67,15 @@ impl AccountStorage {
.or_else(lookup_in_map)
}
/// assert if shrink in progress is active
pub(crate) fn assert_no_shrink_in_progress(&self) {
assert!(self.shrink_in_progress_map.is_empty());
/// returns true if shrink in progress is NOT active
pub(crate) fn no_shrink_in_progress(&self) -> bool {
self.shrink_in_progress_map.is_empty()
}
/// return the append vec for 'slot' if it exists
/// This is only ever called when shrink is not possibly running and there is a max of 1 append vec per slot.
pub(crate) fn get_slot_storage_entry(&self, slot: Slot) -> Option<Arc<AccountStorageEntry>> {
self.assert_no_shrink_in_progress();
assert!(self.no_shrink_in_progress());
self.get_slot_storage_entry_shrinking_in_progress_ok(slot)
}
@ -88,21 +88,21 @@ impl AccountStorage {
}
pub(crate) fn all_slots(&self) -> Vec<Slot> {
self.assert_no_shrink_in_progress();
assert!(self.no_shrink_in_progress());
self.map.iter().map(|iter_item| *iter_item.key()).collect()
}
/// returns true if there is no entry for 'slot'
#[cfg(test)]
pub(crate) fn is_empty_entry(&self, slot: Slot) -> bool {
self.assert_no_shrink_in_progress();
assert!(self.no_shrink_in_progress());
self.map.get(&slot).is_none()
}
/// initialize the storage map to 'all_storages'
pub(crate) fn initialize(&mut self, all_storages: AccountStorageMap) {
assert!(self.map.is_empty());
self.assert_no_shrink_in_progress();
assert!(self.no_shrink_in_progress());
self.map.extend(all_storages.into_iter())
}
@ -119,12 +119,12 @@ impl AccountStorage {
/// iterate through all (slot, append-vec)
pub(crate) fn iter(&self) -> AccountStorageIter<'_> {
self.assert_no_shrink_in_progress();
assert!(self.no_shrink_in_progress());
AccountStorageIter::new(self)
}
pub(crate) fn insert(&self, slot: Slot, store: Arc<AccountStorageEntry>) {
self.assert_no_shrink_in_progress();
assert!(self.no_shrink_in_progress());
assert!(self
.map
.insert(
@ -352,7 +352,7 @@ pub(crate) mod tests {
}
#[test]
#[should_panic(expected = "self.shrink_in_progress_map.is_empty()")]
#[should_panic(expected = "assertion failed: self.no_shrink_in_progress()")]
fn test_get_slot_storage_entry_fail() {
let storage = AccountStorage::default();
storage
@ -362,7 +362,7 @@ pub(crate) mod tests {
}
#[test]
#[should_panic(expected = "self.shrink_in_progress_map.is_empty()")]
#[should_panic(expected = "assertion failed: self.no_shrink_in_progress()")]
fn test_all_slots_fail() {
let storage = AccountStorage::default();
storage
@ -372,7 +372,7 @@ pub(crate) mod tests {
}
#[test]
#[should_panic(expected = "self.shrink_in_progress_map.is_empty()")]
#[should_panic(expected = "assertion failed: self.no_shrink_in_progress()")]
fn test_initialize_fail() {
let mut storage = AccountStorage::default();
storage
@ -382,7 +382,9 @@ pub(crate) mod tests {
}
#[test]
#[should_panic(expected = "self.shrink_in_progress_map.is_empty()")]
#[should_panic(
expected = "assertion failed: shrink_can_be_active || self.shrink_in_progress_map.is_empty()"
)]
fn test_remove_fail() {
let storage = AccountStorage::default();
storage
@ -392,7 +394,7 @@ pub(crate) mod tests {
}
#[test]
#[should_panic(expected = "self.shrink_in_progress_map.is_empty()")]
#[should_panic(expected = "assertion failed: self.no_shrink_in_progress()")]
fn test_iter_fail() {
let storage = AccountStorage::default();
storage
@ -402,7 +404,7 @@ pub(crate) mod tests {
}
#[test]
#[should_panic(expected = "self.shrink_in_progress_map.is_empty()")]
#[should_panic(expected = "assertion failed: self.no_shrink_in_progress()")]
fn test_insert_fail() {
let storage = AccountStorage::default();
let sample = storage.get_test_storage();

View File

@ -8091,7 +8091,7 @@ impl AccountsDb {
where
I: Iterator<Item = &'a (Slot, AccountInfo)>,
{
self.storage.assert_no_shrink_in_progress();
assert!(self.storage.no_shrink_in_progress());
let mut dead_slots = HashSet::new();
let mut new_shrink_candidates: ShrinkCandidates = HashMap::new();