Skip to content

Commit

Permalink
Snapshot archive uses version file from bank snapshot (#34832)
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo authored Jan 18, 2024
1 parent b53915f commit 8f9d915
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
14 changes: 8 additions & 6 deletions runtime/src/snapshot_bank_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ use {
get_storages_to_serialize, hard_link_storages_to_snapshot,
rebuild_storages_from_snapshot_dir, serialize_snapshot_data_file,
verify_and_unarchive_snapshots, verify_unpacked_snapshots_dir_and_version,
write_snapshot_version_file, AddBankSnapshotError, ArchiveFormat, BankSnapshotInfo,
BankSnapshotType, SnapshotError, SnapshotRootPaths, SnapshotVersion,
StorageAndNextAppendVecId, UnpackedSnapshotsDirAndVersion, VerifySlotDeltasError,
AddBankSnapshotError, ArchiveFormat, BankSnapshotInfo, BankSnapshotType, SnapshotError,
SnapshotRootPaths, SnapshotVersion, StorageAndNextAppendVecId,
UnpackedSnapshotsDirAndVersion, VerifySlotDeltasError,
},
status_cache,
},
Expand Down Expand Up @@ -135,9 +135,11 @@ pub fn add_bank_snapshot(
.map_err(|err| AddBankSnapshotError::SerializeStatusCache(Box::new(err)))?);

let version_path = bank_snapshot_dir.join(snapshot_utils::SNAPSHOT_VERSION_FILENAME);
let (_, measure_write_version_file) =
measure!(write_snapshot_version_file(version_path, snapshot_version)
.map_err(AddBankSnapshotError::WriteSnapshotVersionFile)?);
let (_, measure_write_version_file) = measure!(fs_err::write(
version_path,
snapshot_version.as_str().as_bytes()
)
.map_err(AddBankSnapshotError::WriteSnapshotVersionFile)?);

// Mark this directory complete so it can be used. Check this flag first before selecting for deserialization.
let state_complete_path =
Expand Down
20 changes: 7 additions & 13 deletions runtime/src/snapshot_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,14 +653,6 @@ pub fn remove_tmp_snapshot_archives(snapshot_archives_dir: impl AsRef<Path>) {
}
}

/// Write the snapshot version as a file into the bank snapshot directory
pub fn write_snapshot_version_file(
version_file: impl AsRef<Path>,
version: SnapshotVersion,
) -> std::io::Result<()> {
fs_err::write(version_file, version.as_str().as_bytes())
}

/// Make a snapshot archive out of the snapshot package
pub fn archive_snapshot_package(
snapshot_package: &SnapshotPackage,
Expand Down Expand Up @@ -696,7 +688,6 @@ pub fn archive_snapshot_package(

let staging_accounts_dir = staging_dir.path().join("accounts");
let staging_snapshots_dir = staging_dir.path().join("snapshots");
let staging_version_file = staging_dir.path().join(SNAPSHOT_VERSION_FILENAME);

// Create staging/accounts/
fs_err::create_dir_all(&staging_accounts_dir)
Expand Down Expand Up @@ -725,6 +716,12 @@ pub fn archive_snapshot_package(
symlink::symlink_file(src_status_cache, staging_status_cache)
.map_err(|e| SnapshotError::IoWithSource(e, "create status cache symlink"))?;

// The bank snapshot has the version file, so symlink it to the correct staging path
let staging_version_file = staging_dir.path().join(SNAPSHOT_VERSION_FILENAME);
let src_version_file = src_snapshot_dir.join(SNAPSHOT_VERSION_FILENAME);
symlink::symlink_file(src_version_file, staging_version_file)
.map_err(|e| SnapshotError::IoWithSource(e, "create version file symlink"))?;

// Add the AppendVecs into the compressible list
for storage in snapshot_package.snapshot_storages.iter() {
storage.flush()?;
Expand All @@ -745,9 +742,6 @@ pub fn archive_snapshot_package(
}
}

write_snapshot_version_file(staging_version_file, snapshot_package.snapshot_version)
.map_err(|err| SnapshotError::IoWithSource(err, "write snapshot version file"))?;

// Tar the staging directory into the archive at `archive_path`
let archive_path = tar_dir.join(format!(
"{}{}.{}",
Expand Down Expand Up @@ -2550,7 +2544,7 @@ mod tests {
fs_err::File::create(status_cache_file).unwrap();

let version_path = snapshot_dir.join(SNAPSHOT_VERSION_FILENAME);
write_snapshot_version_file(version_path, SnapshotVersion::default()).unwrap();
fs_err::write(version_path, SnapshotVersion::default().as_str().as_bytes()).unwrap();

// Mark this directory complete so it can be used. Check this flag first before selecting for deserialization.
let state_complete_path = snapshot_dir.join(SNAPSHOT_STATE_COMPLETE_FILENAME);
Expand Down

0 comments on commit 8f9d915

Please sign in to comment.