Move Bank::get_incremental_snapshot_storages() into snapshot_utils (#19155)

Filtering out storages for incremental snapshots will be needed by the
background services for incremental snapshot support, but there is not a
Bank at that point.  Since the filtering doesn't apply only to Bank, and
more to snapshots, move the functionality into snapshot_utils.
This commit is contained in:
Brooks Prumo 2021-08-10 14:04:11 -05:00 committed by GitHub
parent ccfa82461b
commit faf99f4760
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 19 deletions

View File

@ -771,13 +771,21 @@ mod tests {
.into_iter()
.find(|elem| elem.slot == slot)
.ok_or_else(|| Error::new(ErrorKind::Other, "did not find snapshot with this path"))?;
let storages = {
let mut storages = bank.get_snapshot_storages();
snapshot_utils::filter_snapshot_storages_for_incremental_snapshot(
&mut storages,
incremental_snapshot_base_slot,
);
storages
};
snapshot_utils::package_process_and_archive_incremental_snapshot(
bank,
incremental_snapshot_base_slot,
&bank_snapshot_info,
&snapshot_config.snapshot_path,
&snapshot_config.snapshot_package_output_path,
bank.get_incremental_snapshot_storages(incremental_snapshot_base_slot),
storages,
snapshot_config.archive_format,
snapshot_config.snapshot_version,
None,

View File

@ -38,7 +38,7 @@ use crate::{
AccountAddressFilter, Accounts, TransactionAccounts, TransactionLoadResult,
TransactionLoaders,
},
accounts_db::{AccountShrinkThreshold, ErrorCounters, SnapshotStorage, SnapshotStorages},
accounts_db::{AccountShrinkThreshold, ErrorCounters, SnapshotStorages},
accounts_index::{
AccountSecondaryIndexes, IndexKey, ScanResult, BINS_FOR_BENCHMARKS, BINS_FOR_TESTING,
},
@ -4877,21 +4877,6 @@ impl Bank {
self.rc.get_snapshot_storages(self.slot())
}
/// Get the snapshot storages _higher than_ the `full_snapshot_slot`. This is used when making an
/// incremental snapshot.
pub fn get_incremental_snapshot_storages(&self, full_snapshot_slot: Slot) -> SnapshotStorages {
self.get_snapshot_storages()
.into_iter()
.map(|storage| {
storage
.into_iter()
.filter(|entry| entry.slot() > full_snapshot_slot)
.collect::<SnapshotStorage>()
})
.filter(|storage| !storage.is_empty())
.collect()
}
#[must_use]
fn verify_hash(&self) -> bool {
assert!(self.is_frozen());

View File

@ -1536,7 +1536,7 @@ pub fn snapshot_bank(
archive_format: &ArchiveFormat,
hash_for_testing: Option<Hash>,
) -> Result<()> {
let storages: Vec<_> = root_bank.get_snapshot_storages();
let storages = root_bank.get_snapshot_storages();
let mut add_snapshot_time = Measure::start("add-snapshot-ms");
add_bank_snapshot(snapshots_dir, root_bank, &storages, snapshot_version)?;
add_snapshot_time.stop();
@ -1630,7 +1630,11 @@ pub fn bank_to_incremental_snapshot_archive(
bank.rehash(); // Bank accounts may have been manually modified by the caller
let temp_dir = tempfile::tempdir_in(snapshots_dir)?;
let storages = bank.get_incremental_snapshot_storages(full_snapshot_slot);
let storages = {
let mut storages = bank.get_snapshot_storages();
filter_snapshot_storages_for_incremental_snapshot(&mut storages, full_snapshot_slot);
storages
};
let bank_snapshot_info = add_bank_snapshot(&temp_dir, bank, &storages, snapshot_version)?;
package_process_and_archive_incremental_snapshot(
@ -1795,6 +1799,19 @@ pub fn process_accounts_package_pre(
)
}
/// Filter snapshot storages and retain only the ones with slots _higher than_
/// `incremental_snapshot_base_slot`.
pub fn filter_snapshot_storages_for_incremental_snapshot(
snapshot_storages: &mut SnapshotStorages,
incremental_snapshot_base_slot: Slot,
) {
snapshot_storages.retain(|storage| {
storage
.first()
.map_or(false, |entry| entry.slot() > incremental_snapshot_base_slot)
});
}
#[cfg(test)]
mod tests {
use super::*;