Add base_slot to get_snapshot_storages() (#19348)

This commit is contained in:
Brooks Prumo 2021-08-20 16:23:43 -05:00 committed by GitHub
parent 05e7d1027b
commit 234461f779
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 73 additions and 37 deletions

View File

@ -282,7 +282,7 @@ mod tests {
snapshot_path, snapshot_path,
last_bank.src.slot_deltas(&last_bank.src.roots()), last_bank.src.slot_deltas(&last_bank.src.roots()),
&snapshot_config.snapshot_package_output_path, &snapshot_config.snapshot_package_output_path,
last_bank.get_snapshot_storages(), last_bank.get_snapshot_storages(None),
ArchiveFormat::TarBzip2, ArchiveFormat::TarBzip2,
snapshot_version, snapshot_version,
None, None,
@ -364,7 +364,7 @@ mod tests {
// Take snapshot of zeroth bank // Take snapshot of zeroth bank
let bank0 = bank_forks.get(0).unwrap(); let bank0 = bank_forks.get(0).unwrap();
let storages = bank0.get_snapshot_storages(); let storages = bank0.get_snapshot_storages(None);
snapshot_utils::add_bank_snapshot(snapshot_path, bank0, &storages, snapshot_version) snapshot_utils::add_bank_snapshot(snapshot_path, bank0, &storages, snapshot_version)
.unwrap(); .unwrap();
@ -424,7 +424,7 @@ mod tests {
if slot == saved_slot as u64 { if slot == saved_slot as u64 {
// Find the relevant snapshot storages // Find the relevant snapshot storages
let snapshot_storage_files: HashSet<_> = bank_forks[slot] let snapshot_storage_files: HashSet<_> = bank_forks[slot]
.get_snapshot_storages() .get_snapshot_storages(None)
.into_iter() .into_iter()
.flatten() .flatten()
.map(|s| s.get_path()) .map(|s| s.get_path())
@ -763,7 +763,7 @@ mod tests {
&bank_snapshot_info, &bank_snapshot_info,
&snapshot_config.snapshot_path, &snapshot_config.snapshot_path,
&snapshot_config.snapshot_package_output_path, &snapshot_config.snapshot_package_output_path,
bank.get_snapshot_storages(), bank.get_snapshot_storages(None),
snapshot_config.archive_format, snapshot_config.archive_format,
snapshot_config.snapshot_version, snapshot_config.snapshot_version,
None, None,
@ -788,7 +788,7 @@ mod tests {
.find(|elem| elem.slot == slot) .find(|elem| elem.slot == slot)
.ok_or_else(|| Error::new(ErrorKind::Other, "did not find snapshot with this path"))?; .ok_or_else(|| Error::new(ErrorKind::Other, "did not find snapshot with this path"))?;
let storages = { let storages = {
let mut storages = bank.get_snapshot_storages(); let mut storages = bank.get_snapshot_storages(Some(incremental_snapshot_base_slot));
snapshot_utils::filter_snapshot_storages_for_incremental_snapshot( snapshot_utils::filter_snapshot_storages_for_incremental_snapshot(
&mut storages, &mut storages,
incremental_snapshot_base_slot, incremental_snapshot_base_slot,

View File

@ -4834,7 +4834,7 @@ impl AccountsDb {
}; };
let mut collect_time = Measure::start("collect"); let mut collect_time = Measure::start("collect");
let (combined_maps, slots) = self.get_snapshot_storages(slot, Some(ancestors)); let (combined_maps, slots) = self.get_snapshot_storages(slot, None, Some(ancestors));
collect_time.stop(); collect_time.stop();
let mut sort_time = Measure::start("sort_storages"); let mut sort_time = Measure::start("sort_storages");
@ -5884,6 +5884,7 @@ impl AccountsDb {
pub fn get_snapshot_storages( pub fn get_snapshot_storages(
&self, &self,
snapshot_slot: Slot, snapshot_slot: Slot,
snapshot_base_slot: Option<Slot>,
ancestors: Option<&Ancestors>, ancestors: Option<&Ancestors>,
) -> (SnapshotStorages, Vec<Slot>) { ) -> (SnapshotStorages, Vec<Slot>) {
let mut m = Measure::start("get slots"); let mut m = Measure::start("get slots");
@ -5905,6 +5906,8 @@ impl AccountsDb {
.iter() .iter()
.filter_map(|slot| { .filter_map(|slot| {
if *slot <= snapshot_slot if *slot <= snapshot_slot
&& snapshot_base_slot
.map_or(true, |snapshot_base_slot| *slot > snapshot_base_slot)
&& (self.accounts_index.is_root(*slot) && (self.accounts_index.is_root(*slot)
|| ancestors || ancestors
.map(|ancestors| ancestors.contains_key(slot)) .map(|ancestors| ancestors.contains_key(slot))
@ -6635,7 +6638,7 @@ pub mod tests {
accounts.store_uncached(slot, &to_store[..]); accounts.store_uncached(slot, &to_store[..]);
accounts.add_root(slot); accounts.add_root(slot);
let (storages, slots) = accounts.get_snapshot_storages(slot, None); let (storages, slots) = accounts.get_snapshot_storages(slot, None, None);
assert_eq!(storages.len(), slots.len()); assert_eq!(storages.len(), slots.len());
storages storages
.iter() .iter()
@ -9203,7 +9206,7 @@ pub mod tests {
#[test] #[test]
fn test_get_snapshot_storages_empty() { fn test_get_snapshot_storages_empty() {
let db = AccountsDb::new(Vec::new(), &ClusterType::Development); let db = AccountsDb::new(Vec::new(), &ClusterType::Development);
assert!(db.get_snapshot_storages(0, None).0.is_empty()); assert!(db.get_snapshot_storages(0, None, None).0.is_empty());
} }
#[test] #[test]
@ -9218,10 +9221,13 @@ pub mod tests {
db.add_root(base_slot); db.add_root(base_slot);
db.store_uncached(base_slot, &[(&key, &account)]); db.store_uncached(base_slot, &[(&key, &account)]);
assert!(db.get_snapshot_storages(before_slot, None).0.is_empty()); assert!(db
.get_snapshot_storages(before_slot, None, None)
.0
.is_empty());
assert_eq!(1, db.get_snapshot_storages(base_slot, None).0.len()); assert_eq!(1, db.get_snapshot_storages(base_slot, None, None).0.len());
assert_eq!(1, db.get_snapshot_storages(after_slot, None).0.len()); assert_eq!(1, db.get_snapshot_storages(after_slot, None, None).0.len());
} }
#[test] #[test]
@ -9241,10 +9247,13 @@ pub mod tests {
.unwrap() .unwrap()
.clear(); .clear();
db.add_root(base_slot); db.add_root(base_slot);
assert!(db.get_snapshot_storages(after_slot, None).0.is_empty()); assert!(db
.get_snapshot_storages(after_slot, None, None)
.0
.is_empty());
db.store_uncached(base_slot, &[(&key, &account)]); db.store_uncached(base_slot, &[(&key, &account)]);
assert_eq!(1, db.get_snapshot_storages(after_slot, None).0.len()); assert_eq!(1, db.get_snapshot_storages(after_slot, None, None).0.len());
} }
#[test] #[test]
@ -9257,10 +9266,13 @@ pub mod tests {
let after_slot = base_slot + 1; let after_slot = base_slot + 1;
db.store_uncached(base_slot, &[(&key, &account)]); db.store_uncached(base_slot, &[(&key, &account)]);
assert!(db.get_snapshot_storages(after_slot, None).0.is_empty()); assert!(db
.get_snapshot_storages(after_slot, None, None)
.0
.is_empty());
db.add_root(base_slot); db.add_root(base_slot);
assert_eq!(1, db.get_snapshot_storages(after_slot, None).0.len()); assert_eq!(1, db.get_snapshot_storages(after_slot, None, None).0.len());
} }
#[test] #[test]
@ -9274,7 +9286,7 @@ pub mod tests {
db.store_uncached(base_slot, &[(&key, &account)]); db.store_uncached(base_slot, &[(&key, &account)]);
db.add_root(base_slot); db.add_root(base_slot);
assert_eq!(1, db.get_snapshot_storages(after_slot, None).0.len()); assert_eq!(1, db.get_snapshot_storages(after_slot, None, None).0.len());
db.storage db.storage
.get_slot_stores(0) .get_slot_stores(0)
@ -9285,7 +9297,32 @@ pub mod tests {
.next() .next()
.unwrap() .unwrap()
.remove_account(0, true); .remove_account(0, true);
assert!(db.get_snapshot_storages(after_slot, None).0.is_empty()); assert!(db
.get_snapshot_storages(after_slot, None, None)
.0
.is_empty());
}
#[test]
fn test_get_snapshot_storages_with_base_slot() {
let db = AccountsDb::new(Vec::new(), &ClusterType::Development);
let key = Pubkey::default();
let account = AccountSharedData::new(1, 0, &key);
let slot = 10;
db.store_uncached(slot, &[(&key, &account)]);
db.add_root(slot);
assert_eq!(
0,
db.get_snapshot_storages(slot + 1, Some(slot), None).0.len()
);
assert_eq!(
1,
db.get_snapshot_storages(slot + 1, Some(slot - 1), None)
.0
.len()
);
} }
#[test] #[test]
@ -9449,7 +9486,7 @@ pub mod tests {
accounts.store_uncached(current_slot, &[(&pubkey2, &zero_lamport_account)]); accounts.store_uncached(current_slot, &[(&pubkey2, &zero_lamport_account)]);
accounts.store_uncached(current_slot, &[(&pubkey3, &zero_lamport_account)]); accounts.store_uncached(current_slot, &[(&pubkey3, &zero_lamport_account)]);
let snapshot_stores = accounts.get_snapshot_storages(current_slot, None).0; let snapshot_stores = accounts.get_snapshot_storages(current_slot, None, None).0;
let total_accounts: usize = snapshot_stores let total_accounts: usize = snapshot_stores
.iter() .iter()
.flatten() .flatten()

View File

@ -483,13 +483,6 @@ impl BankRc {
bank_id_generator: Arc::new(AtomicU64::new(0)), bank_id_generator: Arc::new(AtomicU64::new(0)),
} }
} }
pub fn get_snapshot_storages(&self, slot: Slot) -> SnapshotStorages {
self.accounts
.accounts_db
.get_snapshot_storages(slot, None)
.0
}
} }
#[derive(Default, Debug, AbiExample)] #[derive(Default, Debug, AbiExample)]
@ -4904,8 +4897,12 @@ impl Bank {
) )
} }
pub fn get_snapshot_storages(&self) -> SnapshotStorages { pub fn get_snapshot_storages(&self, base_slot: Option<Slot>) -> SnapshotStorages {
self.rc.get_snapshot_storages(self.slot()) self.rc
.accounts
.accounts_db
.get_snapshot_storages(self.slot(), base_slot, None)
.0
} }
#[must_use] #[must_use]

View File

@ -28,7 +28,9 @@ fn copy_append_vecs<P: AsRef<Path>>(
accounts_db: &AccountsDb, accounts_db: &AccountsDb,
output_dir: P, output_dir: P,
) -> std::io::Result<UnpackedAppendVecMap> { ) -> std::io::Result<UnpackedAppendVecMap> {
let storage_entries = accounts_db.get_snapshot_storages(Slot::max_value(), None).0; let storage_entries = accounts_db
.get_snapshot_storages(Slot::max_value(), None, None)
.0;
let mut unpacked_append_vec_map = UnpackedAppendVecMap::new(); let mut unpacked_append_vec_map = UnpackedAppendVecMap::new();
for storage in storage_entries.iter().flatten() { for storage in storage_entries.iter().flatten() {
let storage_path = storage.get_path(); let storage_path = storage.get_path();
@ -151,7 +153,7 @@ fn test_accounts_serialize_style(serde_style: SerdeStyle) {
&mut writer, &mut writer,
&*accounts.accounts_db, &*accounts.accounts_db,
0, 0,
&accounts.accounts_db.get_snapshot_storages(0, None).0, &accounts.accounts_db.get_snapshot_storages(0, None, None).0,
) )
.unwrap(); .unwrap();
@ -203,7 +205,7 @@ fn test_bank_serialize_style(serde_style: SerdeStyle) {
bank2.squash(); bank2.squash();
bank2.force_flush_accounts_cache(); bank2.force_flush_accounts_cache();
let snapshot_storages = bank2.get_snapshot_storages(); let snapshot_storages = bank2.get_snapshot_storages(None);
let mut buf = vec![]; let mut buf = vec![];
let mut writer = Cursor::new(&mut buf); let mut writer = Cursor::new(&mut buf);
crate::serde_snapshot::bank_to_stream( crate::serde_snapshot::bank_to_stream(
@ -259,7 +261,7 @@ pub(crate) fn reconstruct_accounts_db_via_serialization(
slot: Slot, slot: Slot,
) -> AccountsDb { ) -> AccountsDb {
let mut writer = Cursor::new(vec![]); let mut writer = Cursor::new(vec![]);
let snapshot_storages = accounts.get_snapshot_storages(slot, None).0; let snapshot_storages = accounts.get_snapshot_storages(slot, None, None).0;
accountsdb_to_stream( accountsdb_to_stream(
SerdeStyle::Newer, SerdeStyle::Newer,
&mut writer, &mut writer,
@ -321,7 +323,7 @@ mod test_bank_serialize {
.rc .rc
.accounts .accounts
.accounts_db .accounts_db
.get_snapshot_storages(0, None) .get_snapshot_storages(0, None, None)
.0; .0;
// ensure there is a single snapshot storage example for ABI digesting // ensure there is a single snapshot storage example for ABI digesting
assert_eq!(snapshot_storages.len(), 1); assert_eq!(snapshot_storages.len(), 1);

View File

@ -1541,7 +1541,7 @@ pub fn snapshot_bank(
archive_format: &ArchiveFormat, archive_format: &ArchiveFormat,
hash_for_testing: Option<Hash>, hash_for_testing: Option<Hash>,
) -> Result<()> { ) -> Result<()> {
let storages = root_bank.get_snapshot_storages(); let storages = root_bank.get_snapshot_storages(None);
let mut add_snapshot_time = Measure::start("add-snapshot-ms"); let mut add_snapshot_time = Measure::start("add-snapshot-ms");
add_bank_snapshot(snapshots_dir, root_bank, &storages, snapshot_version)?; add_bank_snapshot(snapshots_dir, root_bank, &storages, snapshot_version)?;
add_snapshot_time.stop(); add_snapshot_time.stop();
@ -1592,7 +1592,7 @@ pub fn bank_to_full_snapshot_archive(
bank.rehash(); // Bank accounts may have been manually modified by the caller bank.rehash(); // Bank accounts may have been manually modified by the caller
let temp_dir = tempfile::tempdir_in(snapshots_dir)?; let temp_dir = tempfile::tempdir_in(snapshots_dir)?;
let storages = bank.get_snapshot_storages(); let storages = bank.get_snapshot_storages(None);
let bank_snapshot_info = add_bank_snapshot(&temp_dir, bank, &storages, snapshot_version)?; let bank_snapshot_info = add_bank_snapshot(&temp_dir, bank, &storages, snapshot_version)?;
package_process_and_archive_full_snapshot( package_process_and_archive_full_snapshot(
@ -1636,7 +1636,7 @@ pub fn bank_to_incremental_snapshot_archive(
let temp_dir = tempfile::tempdir_in(snapshots_dir)?; let temp_dir = tempfile::tempdir_in(snapshots_dir)?;
let storages = { let storages = {
let mut storages = bank.get_snapshot_storages(); let mut storages = bank.get_snapshot_storages(Some(full_snapshot_slot));
filter_snapshot_storages_for_incremental_snapshot(&mut storages, full_snapshot_slot); filter_snapshot_storages_for_incremental_snapshot(&mut storages, full_snapshot_slot);
storages storages
}; };

View File

@ -1386,9 +1386,9 @@ mod tests {
bank.squash(); bank.squash();
bank.force_flush_accounts_cache(); bank.force_flush_accounts_cache();
// do clean and assert that it actually did its job // do clean and assert that it actually did its job
assert_eq!(3, bank.get_snapshot_storages().len()); assert_eq!(3, bank.get_snapshot_storages(None).len());
bank.clean_accounts(false, false, None); bank.clean_accounts(false, false, None);
assert_eq!(2, bank.get_snapshot_storages().len()); assert_eq!(2, bank.get_snapshot_storages(None).len());
}); });
} }