Uses fs_err instead of SnapshotError::IoWithSourceAndFile (#32267)
This commit is contained in:
parent
1574063143
commit
4547549a73
|
@ -438,12 +438,9 @@ pub fn create_and_canonicalize_directories(directories: &[PathBuf]) -> Result<Ve
|
||||||
directories
|
directories
|
||||||
.iter()
|
.iter()
|
||||||
.map(|path| {
|
.map(|path| {
|
||||||
std::fs::create_dir_all(path).map_err(|err| {
|
fs_err::create_dir_all(path)?;
|
||||||
SnapshotError::IoWithSourceAndFile(err, "create_dir_all", path.clone())
|
let path = fs_err::canonicalize(path)?;
|
||||||
})?;
|
Ok(path)
|
||||||
path.canonicalize().map_err(|err| {
|
|
||||||
SnapshotError::IoWithSourceAndFile(err, "canonicalize", path.clone())
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
@ -554,15 +551,8 @@ pub fn move_and_async_delete_path(path: impl AsRef<Path>) {
|
||||||
.name("solDeletePath".to_string())
|
.name("solDeletePath".to_string())
|
||||||
.spawn(move || {
|
.spawn(move || {
|
||||||
trace!("background deleting {}...", path_delete.display());
|
trace!("background deleting {}...", path_delete.display());
|
||||||
let (_, measure_delete) = measure!(std::fs::remove_dir_all(&path_delete)
|
let (_, measure_delete) =
|
||||||
.map_err(|err| {
|
measure!(fs_err::remove_dir_all(&path_delete).expect("background delete"));
|
||||||
SnapshotError::IoWithSourceAndFile(
|
|
||||||
err,
|
|
||||||
"background remove_dir_all",
|
|
||||||
path_delete.clone(),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.expect("background delete"));
|
|
||||||
trace!(
|
trace!(
|
||||||
"background deleting {}... Done, and{measure_delete}",
|
"background deleting {}... Done, and{measure_delete}",
|
||||||
path_delete.display()
|
path_delete.display()
|
||||||
|
@ -666,13 +656,11 @@ pub fn remove_tmp_snapshot_archives(snapshot_archives_dir: impl AsRef<Path>) {
|
||||||
.unwrap_or_else(|_| String::new());
|
.unwrap_or_else(|_| String::new());
|
||||||
if file_name.starts_with(TMP_SNAPSHOT_ARCHIVE_PREFIX) {
|
if file_name.starts_with(TMP_SNAPSHOT_ARCHIVE_PREFIX) {
|
||||||
if entry.path().is_file() {
|
if entry.path().is_file() {
|
||||||
fs::remove_file(entry.path())
|
fs_err::remove_file(entry.path())
|
||||||
} else {
|
} else {
|
||||||
fs::remove_dir_all(entry.path())
|
fs_err::remove_dir_all(entry.path())
|
||||||
}
|
}
|
||||||
.unwrap_or_else(|err| {
|
.unwrap_or_else(|err| warn!("Failed to remove temporary snapshot archive: {err}"));
|
||||||
warn!("Failed to remove {}: {}", entry.path().display(), err)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -683,11 +671,8 @@ pub fn write_snapshot_version_file(
|
||||||
version_file: impl AsRef<Path>,
|
version_file: impl AsRef<Path>,
|
||||||
version: SnapshotVersion,
|
version: SnapshotVersion,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let mut f = fs::File::create(version_file)
|
fs_err::write(version_file, version.as_str().as_bytes())
|
||||||
.map_err(|e| SnapshotError::IoWithSource(e, "create version file"))?;
|
.map_err(|err| SnapshotError::IoWithSource(err, "write snapshot version file"))
|
||||||
f.write_all(version.as_str().as_bytes())
|
|
||||||
.map_err(|e| SnapshotError::IoWithSource(e, "write version file"))?;
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Make a snapshot archive out of the snapshot package
|
/// Make a snapshot archive out of the snapshot package
|
||||||
|
@ -709,9 +694,8 @@ pub fn archive_snapshot_package(
|
||||||
.parent()
|
.parent()
|
||||||
.expect("Tar output path is invalid");
|
.expect("Tar output path is invalid");
|
||||||
|
|
||||||
fs::create_dir_all(tar_dir).map_err(|e| {
|
fs_err::create_dir_all(tar_dir)
|
||||||
SnapshotError::IoWithSourceAndFile(e, "create archive path", tar_dir.into())
|
.map_err(|err| SnapshotError::IoWithSource(err, "create archive path"))?;
|
||||||
})?;
|
|
||||||
|
|
||||||
// Create the staging directories
|
// Create the staging directories
|
||||||
let staging_dir_prefix = TMP_SNAPSHOT_ARCHIVE_PREFIX;
|
let staging_dir_prefix = TMP_SNAPSHOT_ARCHIVE_PREFIX;
|
||||||
|
@ -729,24 +713,14 @@ pub fn archive_snapshot_package(
|
||||||
let staging_version_file = staging_dir.path().join(SNAPSHOT_VERSION_FILENAME);
|
let staging_version_file = staging_dir.path().join(SNAPSHOT_VERSION_FILENAME);
|
||||||
|
|
||||||
// Create staging/accounts/
|
// Create staging/accounts/
|
||||||
fs::create_dir_all(&staging_accounts_dir).map_err(|e| {
|
fs_err::create_dir_all(&staging_accounts_dir)
|
||||||
SnapshotError::IoWithSourceAndFile(
|
.map_err(|err| SnapshotError::IoWithSource(err, "create staging accounts path"))?;
|
||||||
e,
|
|
||||||
"create staging accounts path",
|
|
||||||
staging_accounts_dir.clone(),
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let slot_str = snapshot_package.slot().to_string();
|
let slot_str = snapshot_package.slot().to_string();
|
||||||
let staging_snapshot_dir = staging_snapshots_dir.join(&slot_str);
|
let staging_snapshot_dir = staging_snapshots_dir.join(&slot_str);
|
||||||
// Creates staging snapshots/<slot>/
|
// Creates staging snapshots/<slot>/
|
||||||
fs::create_dir_all(&staging_snapshot_dir).map_err(|e| {
|
fs_err::create_dir_all(&staging_snapshot_dir)
|
||||||
SnapshotError::IoWithSourceAndFile(
|
.map_err(|err| SnapshotError::IoWithSource(err, "create staging snapshots path"))?;
|
||||||
e,
|
|
||||||
"create staging snapshots path",
|
|
||||||
staging_snapshots_dir.clone(),
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let src_snapshot_dir = &snapshot_package.bank_snapshot_dir;
|
let src_snapshot_dir = &snapshot_package.bank_snapshot_dir;
|
||||||
// To be a source for symlinking and archiving, the path need to be an aboslute path
|
// To be a source for symlinking and archiving, the path need to be an aboslute path
|
||||||
|
@ -844,11 +818,10 @@ pub fn archive_snapshot_package(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Atomically move the archive into position for other validators to find
|
// Atomically move the archive into position for other validators to find
|
||||||
let metadata = fs::metadata(&archive_path).map_err(|e| {
|
let metadata = fs_err::metadata(&archive_path)
|
||||||
SnapshotError::IoWithSourceAndFile(e, "archive path stat", archive_path.clone())
|
.map_err(|err| SnapshotError::IoWithSource(err, "archive path stat"))?;
|
||||||
})?;
|
fs_err::rename(&archive_path, snapshot_package.path())
|
||||||
fs::rename(&archive_path, snapshot_package.path())
|
.map_err(|err| SnapshotError::IoWithSource(err, "archive path rename"))?;
|
||||||
.map_err(|e| SnapshotError::IoWithSource(e, "archive path rename"))?;
|
|
||||||
|
|
||||||
purge_old_snapshot_archives(
|
purge_old_snapshot_archives(
|
||||||
full_snapshot_archives_dir,
|
full_snapshot_archives_dir,
|
||||||
|
@ -1178,10 +1151,9 @@ pub fn create_all_accounts_run_and_snapshot_dirs(
|
||||||
// create the run/ and snapshot/ sub directories for each account_path
|
// create the run/ and snapshot/ sub directories for each account_path
|
||||||
let (run_dir, snapshot_dir) =
|
let (run_dir, snapshot_dir) =
|
||||||
create_accounts_run_and_snapshot_dirs(account_path).map_err(|err| {
|
create_accounts_run_and_snapshot_dirs(account_path).map_err(|err| {
|
||||||
SnapshotError::IoWithSourceAndFile(
|
SnapshotError::IoWithSource(
|
||||||
err,
|
err,
|
||||||
"Unable to create account run and snapshot directories",
|
"Unable to create account run and snapshot directories",
|
||||||
account_path.to_path_buf(),
|
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
run_dirs.push(run_dir);
|
run_dirs.push(run_dir);
|
||||||
|
@ -1229,13 +1201,8 @@ fn get_snapshot_accounts_hardlink_dir(
|
||||||
appendvec_path.display(),
|
appendvec_path.display(),
|
||||||
snapshot_hardlink_dir.display()
|
snapshot_hardlink_dir.display()
|
||||||
);
|
);
|
||||||
fs::create_dir_all(&snapshot_hardlink_dir).map_err(|e| {
|
fs_err::create_dir_all(&snapshot_hardlink_dir)
|
||||||
SnapshotError::IoWithSourceAndFile(
|
.map_err(|err| SnapshotError::IoWithSource(err, "create hard-link dir"))?;
|
||||||
e,
|
|
||||||
"create hard-link dir",
|
|
||||||
snapshot_hardlink_dir.clone(),
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
let symlink_path = hardlinks_dir.as_ref().join(format!("account_path_{idx}"));
|
let symlink_path = hardlinks_dir.as_ref().join(format!("account_path_{idx}"));
|
||||||
symlink::symlink_dir(&snapshot_hardlink_dir, symlink_path).map_err(|e| {
|
symlink::symlink_dir(&snapshot_hardlink_dir, symlink_path).map_err(|e| {
|
||||||
SnapshotError::IoWithSourceAndFile(
|
SnapshotError::IoWithSourceAndFile(
|
||||||
|
@ -1276,15 +1243,8 @@ fn hard_link_storages_to_snapshot(
|
||||||
// Use the storage slot and id to compose a consistent file name for the hard-link file.
|
// Use the storage slot and id to compose a consistent file name for the hard-link file.
|
||||||
let hardlink_filename = AppendVec::file_name(storage.slot(), storage.append_vec_id());
|
let hardlink_filename = AppendVec::file_name(storage.slot(), storage.append_vec_id());
|
||||||
let hard_link_path = snapshot_hardlink_dir.join(hardlink_filename);
|
let hard_link_path = snapshot_hardlink_dir.join(hardlink_filename);
|
||||||
fs::hard_link(&storage_path, &hard_link_path).map_err(|e| {
|
fs_err::hard_link(&storage_path, &hard_link_path)
|
||||||
let err_msg = format!(
|
.map_err(|err| SnapshotError::IoWithSource(err, "hard-link append vec file"))?;
|
||||||
"hard-link appendvec file {} to {} failed. Error: {}",
|
|
||||||
storage_path.display(),
|
|
||||||
hard_link_path.display(),
|
|
||||||
e,
|
|
||||||
);
|
|
||||||
SnapshotError::Io(IoError::new(ErrorKind::Other, err_msg))
|
|
||||||
})?;
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue