Skip to content

Commit

Permalink
Add slot deltas into the bank snapshot directory
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangzhu70 committed Dec 24, 2022
1 parent 5a687fa commit 46703b8
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 50 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 @@ -326,7 +326,6 @@ mod tests {
archive_format,
},
block_height: slot,
slot_deltas: vec![],
snapshot_links: link_snapshots_dir,
snapshot_storages: vec![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
@@ -1,7 +1,6 @@
#![allow(clippy::integer_arithmetic)]

use {
bincode::serialize_into,
crossbeam_channel::unbounded,
fs_extra::dir::CopyOptions,
itertools::Itertools,
Expand All @@ -19,7 +18,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 @@ -261,13 +260,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 @@ -366,8 +363,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 @@ -411,19 +415,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 @@ -554,20 +559,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 @@ -358,14 +358,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
14 changes: 7 additions & 7 deletions runtime/src/snapshot_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use {
accounts::Accounts,
accounts_db::SnapshotStorages,
accounts_hash::AccountsHash,
bank::{Bank, BankSlotDelta},
bank::Bank,
epoch_accounts_hash::EpochAccountsHash,
rent_collector::RentCollector,
snapshot_archive_info::{SnapshotArchiveInfo, SnapshotArchiveInfoGetter},
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: SnapshotStorages,
Expand Down Expand Up @@ -98,10 +97,15 @@ impl AccountsPackage {
&bank_snapshot_info.snapshot_path,
snapshot_hardlink_dir.join(file_name),
)?;
let status_cache_file_name =
snapshot_utils::path_to_file_name_str(&bank_snapshot_info.status_cache_path)?;
fs::hard_link(
&bank_snapshot_info.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 +178,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 +218,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 +239,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: SnapshotStorages,
pub snapshot_version: SnapshotVersion,
Expand Down Expand Up @@ -293,7 +294,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
50 changes: 30 additions & 20 deletions runtime/src/snapshot_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ pub struct BankSnapshotInfo {
pub snapshot_path: PathBuf,
/// Type of the snapshot
pub snapshot_type: BankSnapshotType,
/// Path to the status cache (transaction history)
pub status_cache_path: PathBuf,
}

impl PartialOrd for BankSnapshotInfo {
Expand Down Expand Up @@ -313,15 +315,6 @@ pub fn archive_snapshot_package(
snapshot_package.slot()
);

serialize_status_cache(
snapshot_package.slot(),
&snapshot_package.slot_deltas,
&snapshot_package
.snapshot_links
.path()
.join(SNAPSHOT_STATUS_CACHE_FILENAME),
)?;

let mut timer = Measure::start("snapshot_package-package_snapshots");
let tar_dir = snapshot_package
.path()
Expand Down Expand Up @@ -520,6 +513,8 @@ pub fn get_bank_snapshots(bank_snapshots_dir: impl AsRef<Path>) -> Vec<BankSnaps
slot,
snapshot_path: bank_snapshot_pre_path,
snapshot_type: BankSnapshotType::Pre,
status_cache_path: bank_snapshot_outer_dir
.join(SNAPSHOT_STATUS_CACHE_FILENAME),
});
}

Expand All @@ -528,6 +523,8 @@ pub fn get_bank_snapshots(bank_snapshots_dir: impl AsRef<Path>) -> Vec<BankSnaps
slot,
snapshot_path: bank_snapshot_post_path,
snapshot_type: BankSnapshotType::Post,
status_cache_path: bank_snapshot_outer_dir
.join(SNAPSHOT_STATUS_CACHE_FILENAME),
});
}
}),
Expand Down Expand Up @@ -757,15 +754,16 @@ pub fn add_bank_snapshot(
bank: &Bank,
snapshot_storages: &[SnapshotStorage],
snapshot_version: SnapshotVersion,
slot_deltas: Vec<BankSlotDelta>,
) -> Result<BankSnapshotInfo> {
let mut add_snapshot_time = Measure::start("add-snapshot-ms");
let slot = bank.slot();
// bank_snapshots_dir/slot
let bank_snapshots_dir = get_bank_snapshots_dir(bank_snapshots_dir, slot);
fs::create_dir_all(&bank_snapshots_dir)?;
let bank_snapshot_dir = get_bank_snapshots_dir(bank_snapshots_dir, slot);
fs::create_dir_all(&bank_snapshot_dir)?;

// the bank snapshot is stored as bank_snapshots_dir/slot/slot.BANK_SNAPSHOT_PRE_FILENAME_EXTENSION
let mut bank_snapshot_path = bank_snapshots_dir.join(get_snapshot_file_name(slot));
let mut bank_snapshot_path = bank_snapshot_dir.join(get_snapshot_file_name(slot));
bank_snapshot_path.set_extension(BANK_SNAPSHOT_PRE_FILENAME_EXTENSION);

info!(
Expand All @@ -787,6 +785,9 @@ pub fn add_bank_snapshot(
bank_serialize.stop();
add_snapshot_time.stop();

let status_cache_path = bank_snapshot_dir.join(SNAPSHOT_STATUS_CACHE_FILENAME);
serialize_status_cache(slot, &slot_deltas, &status_cache_path)?;

// Monitor sizes because they're capped to MAX_SNAPSHOT_DATA_FILE_SIZE
datapoint_info!(
"snapshot-bank-file",
Expand All @@ -808,6 +809,7 @@ pub fn add_bank_snapshot(
slot,
snapshot_path: bank_snapshot_path,
snapshot_type: BankSnapshotType::Pre,
status_cache_path,
})
}

Expand Down Expand Up @@ -2119,8 +2121,14 @@ pub fn bank_to_full_snapshot_archive(

let temp_dir = tempfile::tempdir_in(bank_snapshots_dir)?;
let snapshot_storages = bank.get_snapshot_storages(None);
let bank_snapshot_info =
add_bank_snapshot(&temp_dir, bank, &snapshot_storages, snapshot_version)?;
let slot_deltas = bank.status_cache.read().unwrap().root_slot_deltas();
let bank_snapshot_info = add_bank_snapshot(
&temp_dir,
bank,
&snapshot_storages,
snapshot_version,
slot_deltas,
)?;

package_and_archive_full_snapshot(
bank,
Expand Down Expand Up @@ -2166,8 +2174,14 @@ pub fn bank_to_incremental_snapshot_archive(

let temp_dir = tempfile::tempdir_in(bank_snapshots_dir)?;
let snapshot_storages = bank.get_snapshot_storages(Some(full_snapshot_slot));
let bank_snapshot_info =
add_bank_snapshot(&temp_dir, bank, &snapshot_storages, snapshot_version)?;
let slot_deltas = bank.status_cache.read().unwrap().root_slot_deltas();
let bank_snapshot_info = add_bank_snapshot(
&temp_dir,
bank,
&snapshot_storages,
snapshot_version,
slot_deltas,
)?;

package_and_archive_incremental_snapshot(
bank,
Expand Down Expand Up @@ -2198,13 +2212,11 @@ pub fn package_and_archive_full_snapshot(
maximum_full_snapshot_archives_to_retain: usize,
maximum_incremental_snapshot_archives_to_retain: usize,
) -> Result<FullSnapshotArchiveInfo> {
let slot_deltas = bank.status_cache.read().unwrap().root_slot_deltas();
let accounts_package = AccountsPackage::new_for_snapshot(
AccountsPackageType::Snapshot(SnapshotType::FullSnapshot),
bank,
bank_snapshot_info,
bank_snapshots_dir,
slot_deltas,
&full_snapshot_archives_dir,
&incremental_snapshot_archives_dir,
snapshot_storages,
Expand Down Expand Up @@ -2250,15 +2262,13 @@ pub fn package_and_archive_incremental_snapshot(
maximum_full_snapshot_archives_to_retain: usize,
maximum_incremental_snapshot_archives_to_retain: usize,
) -> Result<IncrementalSnapshotArchiveInfo> {
let slot_deltas = bank.status_cache.read().unwrap().root_slot_deltas();
let accounts_package = AccountsPackage::new_for_snapshot(
AccountsPackageType::Snapshot(SnapshotType::IncrementalSnapshot(
incremental_snapshot_base_slot,
)),
bank,
bank_snapshot_info,
bank_snapshots_dir,
slot_deltas,
&full_snapshot_archives_dir,
&incremental_snapshot_archives_dir,
snapshot_storages,
Expand Down

0 comments on commit 46703b8

Please sign in to comment.