Skip to content

Commit

Permalink
Add slot deltas into the bank snapshot directory (#29409)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangzhu70 authored Feb 2, 2023
1 parent c549129 commit f107b8b
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 89 deletions.
1 change: 0 additions & 1 deletion core/src/snapshot_packager_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ mod tests {
archive_format,
},
block_height: slot,
slot_deltas: vec![],
snapshot_links: link_snapshots_dir,
snapshot_storages: storage_entries,
snapshot_version: SnapshotVersion::default(),
Expand Down
33 changes: 12 additions & 21 deletions core/tests/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use {
crate::snapshot_utils::create_tmp_accounts_dir_for_tests,
bincode::serialize_into,
crossbeam_channel::unbounded,
fs_extra::dir::CopyOptions,
itertools::Itertools,
Expand All @@ -22,7 +21,7 @@ use {
accounts_db::{self, ACCOUNTS_DB_CONFIG_FOR_TESTING},
accounts_hash::AccountsHash,
accounts_index::AccountSecondaryIndexes,
bank::{Bank, BankSlotDelta},
bank::Bank,
bank_forks::BankForks,
epoch_accounts_hash::EpochAccountsHash,
genesis_utils::{create_genesis_config_with_leader, GenesisConfigInfo},
Expand Down Expand Up @@ -266,13 +265,11 @@ fn run_bank_forks_snapshot_n<F>(
let bank_snapshots_dir = &snapshot_config.bank_snapshots_dir;
let last_bank_snapshot_info = snapshot_utils::get_highest_bank_snapshot_pre(bank_snapshots_dir)
.expect("no bank snapshots found in path");
let slot_deltas = last_bank.status_cache.read().unwrap().root_slot_deltas();
let accounts_package = AccountsPackage::new_for_snapshot(
AccountsPackageType::Snapshot(SnapshotType::FullSnapshot),
&last_bank,
&last_bank_snapshot_info,
bank_snapshots_dir,
slot_deltas,
&snapshot_config.full_snapshot_archives_dir,
&snapshot_config.incremental_snapshot_archives_dir,
last_bank.get_snapshot_storages(None),
Expand Down Expand Up @@ -371,8 +368,15 @@ fn test_concurrent_snapshot_packaging(
// Take snapshot of zeroth bank
let bank0 = bank_forks.get(0).unwrap();
let storages = bank0.get_snapshot_storages(None);
snapshot_utils::add_bank_snapshot(bank_snapshots_dir, &bank0, &storages, snapshot_version)
.unwrap();
let slot_deltas = bank0.status_cache.read().unwrap().root_slot_deltas();
snapshot_utils::add_bank_snapshot(
bank_snapshots_dir,
&bank0,
&storages,
snapshot_version,
slot_deltas,
)
.unwrap();

// Set up snapshotting channels
let (real_accounts_package_sender, real_accounts_package_receiver) =
Expand Down Expand Up @@ -416,19 +420,20 @@ fn test_concurrent_snapshot_packaging(
};

let snapshot_storages = bank.get_snapshot_storages(None);
let slot_deltas = bank.status_cache.read().unwrap().root_slot_deltas();
let bank_snapshot_info = snapshot_utils::add_bank_snapshot(
bank_snapshots_dir,
&bank,
&snapshot_storages,
snapshot_config.snapshot_version,
slot_deltas,
)
.unwrap();
let accounts_package = AccountsPackage::new_for_snapshot(
AccountsPackageType::Snapshot(SnapshotType::FullSnapshot),
&bank,
&bank_snapshot_info,
bank_snapshots_dir,
vec![],
full_snapshot_archives_dir,
incremental_snapshot_archives_dir,
snapshot_storages,
Expand Down Expand Up @@ -561,20 +566,6 @@ fn test_concurrent_snapshot_packaging(

// Check the archive we cached the state for earlier was generated correctly

// before we compare, stick an empty status_cache in this dir so that the package comparison works
// This is needed since the status_cache is added by the packager and is not collected from
// the source dir for snapshots
snapshot_utils::serialize_snapshot_data_file(
&saved_snapshots_dir
.path()
.join(snapshot_utils::SNAPSHOT_STATUS_CACHE_FILENAME),
|stream| {
serialize_into(stream, &[] as &[BankSlotDelta])?;
Ok(())
},
)
.unwrap();

// files were saved off before we reserialized the bank in the hacked up accounts_hash_verifier stand-in.
solana_runtime::serde_snapshot::reserialize_bank_with_new_accounts_hash(
saved_snapshots_dir.path(),
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/accounts_background_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,14 +357,14 @@ impl SnapshotRequestHandler {
&snapshot_root_bank,
&snapshot_storages,
self.snapshot_config.snapshot_version,
status_cache_slot_deltas,
)
.expect("snapshot bank");
AccountsPackage::new_for_snapshot(
accounts_package_type,
&snapshot_root_bank,
&bank_snapshot_info,
&self.snapshot_config.bank_snapshots_dir,
status_cache_slot_deltas,
&self.snapshot_config.full_snapshot_archives_dir,
&self.snapshot_config.incremental_snapshot_archives_dir,
snapshot_storages,
Expand Down
23 changes: 11 additions & 12 deletions runtime/src/snapshot_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use {
accounts::Accounts,
accounts_db::AccountStorageEntry,
accounts_hash::AccountsHash,
bank::{Bank, BankSlotDelta},
bank::Bank,
epoch_accounts_hash::EpochAccountsHash,
rent_collector::RentCollector,
snapshot_archive_info::{SnapshotArchiveInfo, SnapshotArchiveInfoGetter},
snapshot_hash::SnapshotHash,
snapshot_utils::{
self, ArchiveFormat, BankSnapshotInfo, Result, SnapshotVersion,
TMP_BANK_SNAPSHOT_PREFIX,
SNAPSHOT_STATUS_CACHE_FILENAME, TMP_BANK_SNAPSHOT_PREFIX,
},
},
log::*,
Expand Down Expand Up @@ -59,7 +59,6 @@ impl AccountsPackage {
bank: &Bank,
bank_snapshot_info: &BankSnapshotInfo,
bank_snapshots_dir: impl AsRef<Path>,
slot_deltas: Vec<BankSlotDelta>,
full_snapshot_archives_dir: impl AsRef<Path>,
incremental_snapshot_archives_dir: impl AsRef<Path>,
snapshot_storages: Vec<Arc<AccountStorageEntry>>,
Expand Down Expand Up @@ -92,16 +91,20 @@ impl AccountsPackage {
.path()
.join(bank_snapshot_info.slot.to_string());
fs::create_dir_all(&snapshot_hardlink_dir)?;
let file_name =
snapshot_utils::path_to_file_name_str(&bank_snapshot_info.snapshot_path)?;
let snapshot_path = bank_snapshot_info.snapshot_path();
let file_name = snapshot_utils::path_to_file_name_str(&snapshot_path)?;
fs::hard_link(&snapshot_path, snapshot_hardlink_dir.join(file_name))?;
let status_cache_path = bank_snapshot_info
.snapshot_dir
.join(SNAPSHOT_STATUS_CACHE_FILENAME);
let status_cache_file_name = snapshot_utils::path_to_file_name_str(&status_cache_path)?;
fs::hard_link(
&bank_snapshot_info.snapshot_path,
snapshot_hardlink_dir.join(file_name),
&status_cache_path,
snapshot_links.path().join(status_cache_file_name),
)?;
}

let snapshot_info = SupplementalSnapshotInfo {
slot_deltas,
snapshot_links,
archive_format,
snapshot_version,
Expand Down Expand Up @@ -174,7 +177,6 @@ impl AccountsPackage {
epoch_schedule: EpochSchedule::default(),
rent_collector: RentCollector::default(),
snapshot_info: Some(SupplementalSnapshotInfo {
slot_deltas: Vec::default(),
snapshot_links: TempDir::new().unwrap(),
archive_format: ArchiveFormat::Tar,
snapshot_version: SnapshotVersion::default(),
Expand Down Expand Up @@ -215,7 +217,6 @@ impl std::fmt::Debug for AccountsPackage {

/// Supplemental information needed for snapshots
pub struct SupplementalSnapshotInfo {
pub slot_deltas: Vec<BankSlotDelta>,
pub snapshot_links: TempDir,
pub archive_format: ArchiveFormat,
pub snapshot_version: SnapshotVersion,
Expand All @@ -237,7 +238,6 @@ pub enum AccountsPackageType {
pub struct SnapshotPackage {
pub snapshot_archive_info: SnapshotArchiveInfo,
pub block_height: Slot,
pub slot_deltas: Vec<BankSlotDelta>,
pub snapshot_links: TempDir,
pub snapshot_storages: Vec<Arc<AccountStorageEntry>>,
pub snapshot_version: SnapshotVersion,
Expand Down Expand Up @@ -286,7 +286,6 @@ impl SnapshotPackage {
archive_format: snapshot_info.archive_format,
},
block_height: accounts_package.block_height,
slot_deltas: snapshot_info.slot_deltas,
snapshot_links: snapshot_info.snapshot_links,
snapshot_storages,
snapshot_version: snapshot_info.snapshot_version,
Expand Down
Loading

0 comments on commit f107b8b

Please sign in to comment.