Removes get_io_error() (#34863)
This commit is contained in:
parent
5e4332ee35
commit
c264307f10
|
@ -31,7 +31,7 @@ use {
|
|||
cmp::Ordering,
|
||||
collections::{HashMap, HashSet},
|
||||
fmt, fs,
|
||||
io::{BufReader, BufWriter, Error as IoError, ErrorKind, Read, Seek, Write},
|
||||
io::{BufReader, BufWriter, Error as IoError, Read, Seek, Write},
|
||||
num::NonZeroUsize,
|
||||
path::{Path, PathBuf},
|
||||
process::ExitStatus,
|
||||
|
@ -1067,9 +1067,10 @@ where
|
|||
let consumed_size = data_file_stream.stream_position()?;
|
||||
if consumed_size > maximum_file_size {
|
||||
let error_message = format!(
|
||||
"too large snapshot data file to serialize: {data_file_path:?} has {consumed_size} bytes"
|
||||
"too large snapshot data file to serialize: '{}' has {consumed_size} bytes",
|
||||
data_file_path.display(),
|
||||
);
|
||||
return Err(get_io_error(&error_message));
|
||||
return Err(IoError::other(error_message).into());
|
||||
}
|
||||
Ok(consumed_size)
|
||||
}
|
||||
|
@ -1133,12 +1134,12 @@ fn create_snapshot_data_file_stream(
|
|||
|
||||
if snapshot_file_size > maximum_file_size {
|
||||
let error_message = format!(
|
||||
"too large snapshot data file to deserialize: {} has {} bytes (max size is {} bytes)",
|
||||
"too large snapshot data file to deserialize: '{}' has {} bytes (max size is {} bytes)",
|
||||
snapshot_root_file_path.as_ref().display(),
|
||||
snapshot_file_size,
|
||||
maximum_file_size,
|
||||
);
|
||||
return Err(get_io_error(&error_message));
|
||||
return Err(IoError::other(error_message).into());
|
||||
}
|
||||
|
||||
let snapshot_data_file = fs_err::File::open(snapshot_root_file_path.as_ref())?;
|
||||
|
@ -1158,12 +1159,12 @@ fn check_deserialize_file_consumed(
|
|||
|
||||
if consumed_size != file_size {
|
||||
let error_message = format!(
|
||||
"invalid snapshot data file: {} has {} bytes, however consumed {} bytes to deserialize",
|
||||
"invalid snapshot data file: '{}' has {} bytes, however consumed {} bytes to deserialize",
|
||||
file_path.as_ref().display(),
|
||||
file_size,
|
||||
consumed_size,
|
||||
);
|
||||
return Err(get_io_error(&error_message));
|
||||
return Err(IoError::other(error_message).into());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -1601,12 +1602,12 @@ fn snapshot_version_from_file(path: impl AsRef<Path>) -> Result<String> {
|
|||
let file_size = fs_err::metadata(&path)?.len();
|
||||
if file_size > MAX_SNAPSHOT_VERSION_FILE_SIZE {
|
||||
let error_message = format!(
|
||||
"snapshot version file too large: {} has {} bytes (max size is {} bytes)",
|
||||
"snapshot version file too large: '{}' has {} bytes (max size is {} bytes)",
|
||||
path.as_ref().display(),
|
||||
file_size,
|
||||
MAX_SNAPSHOT_VERSION_FILE_SIZE,
|
||||
);
|
||||
return Err(get_io_error(&error_message));
|
||||
return Err(IoError::other(error_message).into());
|
||||
}
|
||||
|
||||
// Read snapshot_version from file.
|
||||
|
@ -2024,11 +2025,20 @@ pub fn verify_unpacked_snapshots_dir_and_version(
|
|||
let mut bank_snapshots =
|
||||
get_bank_snapshots_post(&unpacked_snapshots_dir_and_version.unpacked_snapshots_dir);
|
||||
if bank_snapshots.len() > 1 {
|
||||
return Err(get_io_error("invalid snapshot format"));
|
||||
return Err(IoError::other(format!(
|
||||
"invalid snapshot format: only one snapshot allowed, but found {}",
|
||||
bank_snapshots.len(),
|
||||
))
|
||||
.into());
|
||||
}
|
||||
let root_paths = bank_snapshots
|
||||
.pop()
|
||||
.ok_or_else(|| get_io_error("No snapshots found in snapshots directory"))?;
|
||||
let root_paths = bank_snapshots.pop().ok_or_else(|| {
|
||||
IoError::other(format!(
|
||||
"no snapshots found in snapshots directory '{}'",
|
||||
unpacked_snapshots_dir_and_version
|
||||
.unpacked_snapshots_dir
|
||||
.display(),
|
||||
))
|
||||
})?;
|
||||
Ok((snapshot_version, root_paths))
|
||||
}
|
||||
|
||||
|
@ -2044,11 +2054,6 @@ pub fn get_bank_snapshot_dir(bank_snapshots_dir: impl AsRef<Path>, slot: Slot) -
|
|||
.join(get_snapshot_file_name(slot))
|
||||
}
|
||||
|
||||
fn get_io_error(error: &str) -> SnapshotError {
|
||||
warn!("Snapshot Error: {:?}", error);
|
||||
SnapshotError::Io(IoError::new(ErrorKind::Other, error))
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
/// allow tests to specify what happened to the serialized format
|
||||
pub enum VerifyBank {
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
//! Provides interfaces for rebuilding snapshot storages
|
||||
|
||||
use {
|
||||
super::{
|
||||
get_io_error, snapshot_version_from_file, SnapshotError, SnapshotFrom, SnapshotVersion,
|
||||
},
|
||||
super::{snapshot_version_from_file, SnapshotError, SnapshotFrom, SnapshotVersion},
|
||||
crate::serde_snapshot::{
|
||||
self, reconstruct_single_storage, remap_and_reconstruct_single_storage,
|
||||
snapshot_storage_lengths_from_fields, SerdeStyle, SerializedAppendVecId,
|
||||
|
@ -25,7 +23,7 @@ use {
|
|||
std::{
|
||||
collections::HashMap,
|
||||
fs::File,
|
||||
io::BufReader,
|
||||
io::{BufReader, Error as IoError},
|
||||
path::{Path, PathBuf},
|
||||
sync::{
|
||||
atomic::{AtomicUsize, Ordering},
|
||||
|
@ -84,9 +82,9 @@ impl SnapshotStorageRebuilder {
|
|||
let (snapshot_version_path, snapshot_file_path, append_vec_files) =
|
||||
Self::get_version_and_snapshot_files(&file_receiver);
|
||||
let snapshot_version_str = snapshot_version_from_file(snapshot_version_path)?;
|
||||
let snapshot_version = snapshot_version_str.parse().map_err(|_| {
|
||||
get_io_error(&format!(
|
||||
"unsupported snapshot version: {snapshot_version_str}",
|
||||
let snapshot_version = snapshot_version_str.parse().map_err(|err| {
|
||||
IoError::other(format!(
|
||||
"unsupported snapshot version '{snapshot_version_str}': {err}",
|
||||
))
|
||||
})?;
|
||||
let snapshot_storage_lengths =
|
||||
|
|
Loading…
Reference in New Issue