Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Replaces fs-err in clean_orphaned_account_snapshot_dirs() #34902

Merged
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
2 changes: 1 addition & 1 deletion core/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ impl Validator {
&config.snapshot_config.bank_snapshots_dir,
&config.account_snapshot_paths,
)
.map_err(|err| format!("Failed to clean orphaned account snapshot directories: {err:?}"))?;
.map_err(|err| format!("failed to clean orphaned account snapshot directories: {err}"))?;
timer.stop();
info!("Cleaning orphaned account snapshot directories done. {timer}");

Expand Down
3 changes: 1 addition & 2 deletions ledger-tool/src/ledger_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ use {
snapshot_hash::StartingSnapshotHashes,
snapshot_utils::{
self, clean_orphaned_account_snapshot_dirs, move_and_async_delete_path_contents,
SnapshotError,
},
},
solana_sdk::{
Expand Down Expand Up @@ -67,7 +66,7 @@ const PROCESS_SLOTS_HELP_STRING: &str =
#[derive(Error, Debug)]
pub(crate) enum LoadAndProcessLedgerError {
#[error("failed to clean orphaned account snapshot directories: {0}")]
CleanOrphanedAccountSnapshotDirectories(#[source] SnapshotError),
CleanOrphanedAccountSnapshotDirectories(#[source] std::io::Error),

#[error("failed to create all run and snapshot directories: {0}")]
CreateAllAccountsRunAndSnapshotDirectories(#[source] std::io::Error),
Expand Down
29 changes: 23 additions & 6 deletions runtime/src/snapshot_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use {
cmp::Ordering,
collections::{HashMap, HashSet},
fmt, fs,
io::{BufReader, BufWriter, Error as IoError, Read, Seek, Write},
io::{BufReader, BufWriter, Error as IoError, Read, Result as IoResult, Seek, Write},
num::NonZeroUsize,
path::{Path, PathBuf},
process::ExitStatus,
Expand Down Expand Up @@ -610,28 +610,45 @@ pub fn move_and_async_delete_path(path: impl AsRef<Path>) {
pub fn clean_orphaned_account_snapshot_dirs(
bank_snapshots_dir: impl AsRef<Path>,
account_snapshot_paths: &[PathBuf],
) -> Result<()> {
) -> IoResult<()> {
// Create the HashSet of the account snapshot hardlink directories referenced by the snapshot dirs.
// This is used to clean up any hardlinks that are no longer referenced by the snapshot dirs.
let mut account_snapshot_dirs_referenced = HashSet::new();
let snapshots = get_bank_snapshots(bank_snapshots_dir);
for snapshot in snapshots {
let account_hardlinks_dir = snapshot.snapshot_dir.join(SNAPSHOT_ACCOUNTS_HARDLINKS);
// loop through entries in the snapshot_hardlink_dir, read the symlinks, add the target to the HashSet
for entry in fs_err::read_dir(&account_hardlinks_dir)? {
let read_dir = fs::read_dir(&account_hardlinks_dir).map_err(|err| {
IoError::other(format!(
"failed to read account hardlinks dir '{}': {err}",
account_hardlinks_dir.display(),
))
})?;
for entry in read_dir {
let path = entry?.path();
let target = fs_err::read_link(&path)?;
let target = fs::read_link(&path).map_err(|err| {
IoError::other(format!(
"failed to read symlink '{}': {err}",
path.display(),
))
})?;
account_snapshot_dirs_referenced.insert(target);
}
}

// loop through the account snapshot hardlink directories, if the directory is not in the account_snapshot_dirs_referenced set, delete it
for account_snapshot_path in account_snapshot_paths {
for entry in fs_err::read_dir(account_snapshot_path)? {
let read_dir = fs::read_dir(account_snapshot_path).map_err(|err| {
IoError::other(format!(
"failed to read account snapshot dir '{}': {err}",
account_snapshot_path.display(),
))
})?;
for entry in read_dir {
let path = entry?.path();
if !account_snapshot_dirs_referenced.contains(&path) {
info!(
"Removing orphaned account snapshot hardlink directory: {}",
"Removing orphaned account snapshot hardlink directory '{}'...",
path.display()
);
move_and_async_delete_path(&path);
Expand Down