Skip to content

Commit

Permalink
Replaces fs-err for some snapshot errors (#34837)
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo authored Jan 19, 2024
1 parent 17de7a3 commit 6835e10
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
20 changes: 11 additions & 9 deletions runtime/src/snapshot_bank_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use {
status_cache,
},
bincode::{config::Options, serialize_into},
fs_err,
log::*,
solana_accounts_db::{
accounts_db::{
Expand All @@ -49,6 +48,7 @@ use {
},
std::{
collections::HashSet,
fs,
io::{BufWriter, Write},
num::NonZeroUsize,
path::{Path, PathBuf},
Expand Down Expand Up @@ -85,8 +85,9 @@ pub fn add_bank_snapshot(
bank_snapshot_dir,
));
}
fs_err::create_dir_all(&bank_snapshot_dir)
.map_err(AddBankSnapshotError::CreateSnapshotDir)?;
fs::create_dir_all(&bank_snapshot_dir).map_err(|err| {
AddBankSnapshotError::CreateSnapshotDir(err, bank_snapshot_dir.clone())
})?;

// the bank snapshot is stored as bank_snapshots_dir/slot/slot.BANK_SNAPSHOT_PRE_FILENAME_EXTENSION
let bank_snapshot_path = bank_snapshot_dir
Expand Down Expand Up @@ -135,18 +136,19 @@ 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!(fs_err::write(
version_path,
snapshot_version.as_str().as_bytes()
let (_, measure_write_version_file) = measure!(fs::write(
&version_path,
snapshot_version.as_str().as_bytes(),
)
.map_err(AddBankSnapshotError::WriteSnapshotVersionFile)?);
.map_err(|err| AddBankSnapshotError::WriteSnapshotVersionFile(err, version_path))?);

// Mark this directory complete so it can be used. Check this flag first before selecting for deserialization.
let state_complete_path =
bank_snapshot_dir.join(snapshot_utils::SNAPSHOT_STATE_COMPLETE_FILENAME);
let (_, measure_write_state_complete_file) =
measure!(fs_err::File::create(state_complete_path)
.map_err(AddBankSnapshotError::CreateStateCompleteFile)?);
measure!(fs::File::create(&state_complete_path).map_err(|err| {
AddBankSnapshotError::CreateStateCompleteFile(err, state_complete_path)
})?);

measure_everything.stop();

Expand Down
24 changes: 14 additions & 10 deletions runtime/src/snapshot_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,8 @@ pub enum AddBankSnapshotError {
#[error("bank snapshot dir already exists '{0}'")]
SnapshotDirAlreadyExists(PathBuf),

#[error("failed to create snapshot dir: {0}")]
CreateSnapshotDir(#[source] IoError),
#[error("failed to create snapshot dir '{1}': {0}")]
CreateSnapshotDir(#[source] IoError, PathBuf),

#[error("failed to hard link storages: {0}")]
HardLinkStorages(#[source] HardLinkStoragesToSnapshotError),
Expand All @@ -419,11 +419,11 @@ pub enum AddBankSnapshotError {
#[error("failed to serialize status cache: {0}")]
SerializeStatusCache(#[source] Box<SnapshotError>),

#[error("failed to write snapshot version file: {0}")]
WriteSnapshotVersionFile(#[source] IoError),
#[error("failed to write snapshot version file '{1}': {0}")]
WriteSnapshotVersionFile(#[source] IoError, PathBuf),

#[error("failed to mark snapshot as 'complete': {0}")]
CreateStateCompleteFile(#[source] IoError),
#[error("failed to mark snapshot as 'complete': failed to create file '{1}': {0}")]
CreateStateCompleteFile(#[source] IoError, PathBuf),
}

/// Errors that can happen in `archive_snapshot_package()`
Expand Down Expand Up @@ -515,8 +515,8 @@ pub enum GetSnapshotAccountsHardLinkDirError {
#[error("invalid account storage path '{0}'")]
GetAccountPath(PathBuf),

#[error("failed to create the snapshot hard link dir: {0}")]
CreateSnapshotHardLinkDir(#[source] IoError),
#[error("failed to create the snapshot hard link dir '{1}': {0}")]
CreateSnapshotHardLinkDir(#[source] IoError, PathBuf),

#[error("failed to symlink snapshot hard link dir '{link}' to '{original}': {source}")]
SymlinkSnapshotHardLinkDir {
Expand Down Expand Up @@ -1220,8 +1220,12 @@ fn get_snapshot_accounts_hardlink_dir(
appendvec_path.display(),
snapshot_hardlink_dir.display()
);
fs_err::create_dir_all(&snapshot_hardlink_dir)
.map_err(GetSnapshotAccountsHardLinkDirError::CreateSnapshotHardLinkDir)?;
fs::create_dir_all(&snapshot_hardlink_dir).map_err(|err| {
GetSnapshotAccountsHardLinkDirError::CreateSnapshotHardLinkDir(
err,
snapshot_hardlink_dir.clone(),
)
})?;
let symlink_path = hardlinks_dir.as_ref().join(format!("account_path_{idx}"));
symlink::symlink_dir(&snapshot_hardlink_dir, &symlink_path).map_err(|err| {
GetSnapshotAccountsHardLinkDirError::SymlinkSnapshotHardLinkDir {
Expand Down

0 comments on commit 6835e10

Please sign in to comment.