Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.17: Cleans up snapshot errors (backport of #34831) #34835

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions runtime/src/snapshot_bank_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,9 @@ pub fn bank_fields_from_snapshot_archives(
incremental_snapshot_archives_dir: impl AsRef<Path>,
) -> snapshot_utils::Result<BankFieldsToDeserialize> {
let full_snapshot_archive_info =
get_highest_full_snapshot_archive_info(&full_snapshot_archives_dir)
.ok_or(SnapshotError::NoSnapshotArchives)?;
get_highest_full_snapshot_archive_info(&full_snapshot_archives_dir).ok_or_else(|| {
SnapshotError::NoSnapshotArchives(full_snapshot_archives_dir.as_ref().to_path_buf())
})?;

let incremental_snapshot_archive_info = get_highest_incremental_snapshot_archive_info(
&incremental_snapshot_archives_dir,
Expand Down Expand Up @@ -440,8 +441,9 @@ pub fn bank_from_latest_snapshot_archives(
Option<IncrementalSnapshotArchiveInfo>,
)> {
let full_snapshot_archive_info =
get_highest_full_snapshot_archive_info(&full_snapshot_archives_dir)
.ok_or(SnapshotError::NoSnapshotArchives)?;
get_highest_full_snapshot_archive_info(&full_snapshot_archives_dir).ok_or_else(|| {
SnapshotError::NoSnapshotArchives(full_snapshot_archives_dir.as_ref().to_path_buf())
})?;

let incremental_snapshot_archive_info = get_highest_incremental_snapshot_archive_info(
&incremental_snapshot_archives_dir,
Expand Down
70 changes: 39 additions & 31 deletions runtime/src/snapshot_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl BankSnapshotInfo {
SnapshotNewFromDirError::MissingVersionFile(version_path),
))?;
let snapshot_version = SnapshotVersion::from_str(version_str.as_str())
.or(Err(SnapshotNewFromDirError::InvalidVersion))?;
.or(Err(SnapshotNewFromDirError::InvalidVersion(version_str)))?;

let bank_snapshot_post_path = bank_snapshot_dir.join(get_snapshot_file_name(slot));
let bank_snapshot_pre_path =
Expand Down Expand Up @@ -289,7 +289,7 @@ pub(crate) struct StorageAndNextAppendVecId {
#[allow(clippy::large_enum_variant)]
pub enum SnapshotError {
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
Io(#[from] IoError),

#[error("AccountsFile error: {0}")]
AccountsFileError(#[from] AccountsFileError),
Expand All @@ -303,34 +303,38 @@ pub enum SnapshotError {
#[error("archive generation failure {0}")]
ArchiveGenerationFailure(ExitStatus),

#[error("storage path symlink is invalid")]
StoragePathSymlinkInvalid,
#[error("storage path symlink is invalid '{0}'")]
StoragePathSymlinkInvalid(PathBuf),

#[error("Unpack error: {0}")]
UnpackError(#[from] UnpackError),

#[error("source({1}) - I/O error: {0}")]
IoWithSource(std::io::Error, &'static str),
IoWithSource(IoError, &'static str),

<<<<<<< HEAD
#[error("source({1}) - I/O error: {0}, file: {2}")]
IoWithSourceAndFile(#[source] std::io::Error, &'static str, PathBuf),

#[error("could not get file name from path: {0}")]
=======
#[error("could not get file name from path '{0}'")]
>>>>>>> b53915f164 (Cleans up snapshot errors (#34831))
PathToFileNameError(PathBuf),

#[error("could not get str from file name: {0}")]
#[error("could not get str from file name '{0}'")]
FileNameToStrError(PathBuf),

#[error("could not parse snapshot archive's file name: {0}")]
#[error("could not parse snapshot archive's file name '{0}'")]
ParseSnapshotArchiveFileNameError(String),

#[error("snapshots are incompatible: full snapshot slot ({0}) and incremental snapshot base slot ({1}) do not match")]
MismatchedBaseSlot(Slot, Slot),

#[error("no snapshot archives to load from")]
NoSnapshotArchives,
#[error("no snapshot archives to load from '{0}'")]
NoSnapshotArchives(PathBuf),

#[error("snapshot has mismatch: deserialized bank: {:?}, snapshot archive info: {:?}", .0, .1)]
#[error("snapshot has mismatch: deserialized bank: {0:?}, snapshot archive info: {1:?}")]
MismatchedSlotHash((Slot, SnapshotHash), (Slot, SnapshotHash)),

#[error("snapshot slot deltas are invalid: {0}")]
Expand All @@ -339,16 +343,16 @@ pub enum SnapshotError {
#[error("bank_snapshot_info new_from_dir failed: {0}")]
NewFromDir(#[from] SnapshotNewFromDirError),

#[error("invalid snapshot dir path: {0}")]
#[error("invalid snapshot dir path '{0}'")]
InvalidSnapshotDirPath(PathBuf),

#[error("invalid AppendVec path: {0}")]
#[error("invalid AppendVec path '{0}'")]
InvalidAppendVecPath(PathBuf),

#[error("invalid account path: {0}")]
#[error("invalid account path '{0}'")]
InvalidAccountPath(PathBuf),

#[error("no valid snapshot dir found under {0}")]
#[error("no valid snapshot dir found under '{0}'")]
NoSnapshotSlotDir(PathBuf),

#[error("snapshot dir account paths mismatching")]
Expand All @@ -360,25 +364,29 @@ pub enum SnapshotError {

#[derive(Error, Debug)]
pub enum SnapshotNewFromDirError {
<<<<<<< HEAD
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),

#[error("invalid bank snapshot directory {0}")]
=======
#[error("invalid bank snapshot directory '{0}'")]
>>>>>>> b53915f164 (Cleans up snapshot errors (#34831))
InvalidBankSnapshotDir(PathBuf),

#[error("missing status cache file {0}")]
#[error("missing status cache file '{0}'")]
MissingStatusCacheFile(PathBuf),

#[error("missing version file {0}")]
#[error("missing version file '{0}'")]
MissingVersionFile(PathBuf),

#[error("invalid snapshot version")]
InvalidVersion,
#[error("invalid snapshot version '{0}'")]
InvalidVersion(String),

#[error("snapshot directory incomplete {0}")]
#[error("snapshot directory incomplete '{0}'")]
IncompleteDir(PathBuf),

#[error("missing snapshot file {0}")]
#[error("missing snapshot file '{0}'")]
MissingSnapshotFile(PathBuf),
}

Expand Down Expand Up @@ -412,11 +420,11 @@ pub enum VerifySlotDeltasError {
/// Errors that can happen in `add_bank_snapshot()`
#[derive(Error, Debug)]
pub enum AddBankSnapshotError {
#[error("bank snapshot dir already exists: {0}")]
#[error("bank snapshot dir already exists '{0}'")]
SnapshotDirAlreadyExists(PathBuf),

#[error("failed to create snapshot dir: {0}")]
CreateSnapshotDir(#[source] std::io::Error),
CreateSnapshotDir(#[source] IoError),

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

#[error("failed to write snapshot version file: {0}")]
WriteSnapshotVersionFile(#[source] std::io::Error),
WriteSnapshotVersionFile(#[source] IoError),

#[error("failed to mark snapshot as 'complete': {0}")]
CreateStateCompleteFile(#[source] std::io::Error),
CreateStateCompleteFile(#[source] IoError),
}

/// Errors that can happen in `hard_link_storages_to_snapshot()`
#[derive(Error, Debug)]
pub enum HardLinkStoragesToSnapshotError {
#[error("failed to create accounts hard links dir: {0}")]
CreateAccountsHardLinksDir(#[source] std::io::Error),
CreateAccountsHardLinksDir(#[source] IoError),

#[error("failed to flush storage: {0}")]
FlushStorage(#[source] AccountsFileError),
Expand All @@ -447,21 +455,21 @@ pub enum HardLinkStoragesToSnapshotError {
GetSnapshotHardLinksDir(#[from] GetSnapshotAccountsHardLinkDirError),

#[error("failed to hard link storage: {0}")]
HardLinkStorage(#[source] std::io::Error),
HardLinkStorage(#[source] IoError),
}

/// Errors that can happen in `get_snapshot_accounts_hardlink_dir()`
#[derive(Error, Debug)]
pub enum GetSnapshotAccountsHardLinkDirError {
#[error("invalid account storage path: {0}")]
#[error("invalid account storage path '{0}'")]
GetAccountPath(PathBuf),

#[error("failed to create the snapshot hard link dir: {0}")]
CreateSnapshotHardLinkDir(#[source] std::io::Error),
CreateSnapshotHardLinkDir(#[source] IoError),

#[error("failed to symlink snapshot hard link dir {link} to {original}: {source}")]
#[error("failed to symlink snapshot hard link dir '{link}' to '{original}': {source}")]
SymlinkSnapshotHardLinkDir {
source: std::io::Error,
source: IoError,
original: PathBuf,
link: PathBuf,
},
Expand Down Expand Up @@ -749,7 +757,7 @@ pub fn archive_snapshot_package(
symlink::symlink_file(storage_path, &output_path)
.map_err(|e| SnapshotError::IoWithSource(e, "create storage symlink"))?;
if !output_path.is_file() {
return Err(SnapshotError::StoragePathSymlinkInvalid);
return Err(SnapshotError::StoragePathSymlinkInvalid(output_path));
}
}

Expand Down
Loading