Moves create_and_canonicalize_directories() into accounts-db utils (#34882)
This commit is contained in:
parent
9263cc6c82
commit
8ff511e8fa
|
@ -85,6 +85,20 @@ pub fn delete_contents_of_path(path: impl AsRef<Path>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates directories if they do not exist, and canonicalizes the paths.
|
||||||
|
pub fn create_and_canonicalize_directories(
|
||||||
|
directories: impl IntoIterator<Item = impl AsRef<Path>>,
|
||||||
|
) -> std::io::Result<Vec<PathBuf>> {
|
||||||
|
directories
|
||||||
|
.into_iter()
|
||||||
|
.map(|path| {
|
||||||
|
fs::create_dir_all(&path)?;
|
||||||
|
let path = fs::canonicalize(&path)?;
|
||||||
|
Ok(path)
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use {super::*, tempfile::TempDir};
|
use {super::*, tempfile::TempDir};
|
||||||
|
|
|
@ -5,13 +5,14 @@ use {
|
||||||
accounts_db::{AccountsDb, AccountsDbConfig},
|
accounts_db::{AccountsDb, AccountsDbConfig},
|
||||||
accounts_index::{AccountsIndexConfig, IndexLimitMb},
|
accounts_index::{AccountsIndexConfig, IndexLimitMb},
|
||||||
partitioned_rewards::TestPartitionedEpochRewards,
|
partitioned_rewards::TestPartitionedEpochRewards,
|
||||||
|
utils::create_and_canonicalize_directories,
|
||||||
},
|
},
|
||||||
solana_clap_utils::input_parsers::pubkeys_of,
|
solana_clap_utils::input_parsers::pubkeys_of,
|
||||||
solana_ledger::{
|
solana_ledger::{
|
||||||
blockstore_processor::ProcessOptions,
|
blockstore_processor::ProcessOptions,
|
||||||
use_snapshot_archives_at_startup::{self, UseSnapshotArchivesAtStartup},
|
use_snapshot_archives_at_startup::{self, UseSnapshotArchivesAtStartup},
|
||||||
},
|
},
|
||||||
solana_runtime::{runtime_config::RuntimeConfig, snapshot_utils},
|
solana_runtime::runtime_config::RuntimeConfig,
|
||||||
solana_sdk::clock::Slot,
|
solana_sdk::clock::Slot,
|
||||||
std::{
|
std::{
|
||||||
collections::HashSet,
|
collections::HashSet,
|
||||||
|
@ -116,14 +117,16 @@ pub fn get_accounts_db_config(
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
ledger_tool_ledger_path.join(AccountsDb::DEFAULT_ACCOUNTS_HASH_CACHE_DIR)
|
ledger_tool_ledger_path.join(AccountsDb::DEFAULT_ACCOUNTS_HASH_CACHE_DIR)
|
||||||
});
|
});
|
||||||
let accounts_hash_cache_path =
|
let accounts_hash_cache_path = create_and_canonicalize_directories([&accounts_hash_cache_path])
|
||||||
snapshot_utils::create_and_canonicalize_directories(&[accounts_hash_cache_path])
|
.unwrap_or_else(|err| {
|
||||||
.unwrap_or_else(|err| {
|
eprintln!(
|
||||||
eprintln!("Unable to access accounts hash cache path: {err}");
|
"Unable to access accounts hash cache path '{}': {err}",
|
||||||
std::process::exit(1);
|
accounts_hash_cache_path.display(),
|
||||||
})
|
);
|
||||||
.pop()
|
std::process::exit(1);
|
||||||
.unwrap();
|
})
|
||||||
|
.pop()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
AccountsDbConfig {
|
AccountsDbConfig {
|
||||||
index: Some(accounts_index_config),
|
index: Some(accounts_index_config),
|
||||||
|
|
|
@ -530,18 +530,6 @@ pub enum GetSnapshotAccountsHardLinkDirError {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates directories if they do not exist, and canonicalizes the paths.
|
|
||||||
pub fn create_and_canonicalize_directories(directories: &[PathBuf]) -> Result<Vec<PathBuf>> {
|
|
||||||
directories
|
|
||||||
.iter()
|
|
||||||
.map(|path| {
|
|
||||||
fs_err::create_dir_all(path)?;
|
|
||||||
let path = fs_err::canonicalize(path)?;
|
|
||||||
Ok(path)
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Moves and asynchronously deletes the contents of a directory to avoid blocking on it.
|
/// Moves and asynchronously deletes the contents of a directory to avoid blocking on it.
|
||||||
/// The directory is re-created after the move, and should now be empty.
|
/// The directory is re-created after the move, and should now be empty.
|
||||||
pub fn move_and_async_delete_path_contents(path: impl AsRef<Path>) {
|
pub fn move_and_async_delete_path_contents(path: impl AsRef<Path>) {
|
||||||
|
|
|
@ -14,7 +14,7 @@ use {
|
||||||
AccountsIndexConfig, IndexLimitMb,
|
AccountsIndexConfig, IndexLimitMb,
|
||||||
},
|
},
|
||||||
partitioned_rewards::TestPartitionedEpochRewards,
|
partitioned_rewards::TestPartitionedEpochRewards,
|
||||||
utils::create_all_accounts_run_and_snapshot_dirs,
|
utils::{create_all_accounts_run_and_snapshot_dirs, create_and_canonicalize_directories},
|
||||||
},
|
},
|
||||||
solana_clap_utils::input_parsers::{keypair_of, keypairs_of, pubkey_of, value_of},
|
solana_clap_utils::input_parsers::{keypair_of, keypairs_of, pubkey_of, value_of},
|
||||||
solana_core::{
|
solana_core::{
|
||||||
|
@ -48,9 +48,7 @@ use {
|
||||||
runtime_config::RuntimeConfig,
|
runtime_config::RuntimeConfig,
|
||||||
snapshot_bank_utils::DISABLED_SNAPSHOT_ARCHIVE_INTERVAL,
|
snapshot_bank_utils::DISABLED_SNAPSHOT_ARCHIVE_INTERVAL,
|
||||||
snapshot_config::{SnapshotConfig, SnapshotUsage},
|
snapshot_config::{SnapshotConfig, SnapshotUsage},
|
||||||
snapshot_utils::{
|
snapshot_utils::{self, ArchiveFormat, SnapshotVersion},
|
||||||
self, create_and_canonicalize_directories, ArchiveFormat, SnapshotVersion,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
clock::{Slot, DEFAULT_S_PER_SLOT},
|
clock::{Slot, DEFAULT_S_PER_SLOT},
|
||||||
|
@ -991,9 +989,12 @@ pub fn main() {
|
||||||
.map(BlockstoreRecoveryMode::from);
|
.map(BlockstoreRecoveryMode::from);
|
||||||
|
|
||||||
// Canonicalize ledger path to avoid issues with symlink creation
|
// Canonicalize ledger path to avoid issues with symlink creation
|
||||||
let ledger_path = create_and_canonicalize_directories(&[ledger_path])
|
let ledger_path = create_and_canonicalize_directories([&ledger_path])
|
||||||
.unwrap_or_else(|err| {
|
.unwrap_or_else(|err| {
|
||||||
eprintln!("Unable to access ledger path: {err}");
|
eprintln!(
|
||||||
|
"Unable to access ledger path '{}': {err}",
|
||||||
|
ledger_path.display(),
|
||||||
|
);
|
||||||
exit(1);
|
exit(1);
|
||||||
})
|
})
|
||||||
.pop()
|
.pop()
|
||||||
|
@ -1003,9 +1004,12 @@ pub fn main() {
|
||||||
.value_of("accounts_hash_cache_path")
|
.value_of("accounts_hash_cache_path")
|
||||||
.map(Into::into)
|
.map(Into::into)
|
||||||
.unwrap_or_else(|| ledger_path.join(AccountsDb::DEFAULT_ACCOUNTS_HASH_CACHE_DIR));
|
.unwrap_or_else(|| ledger_path.join(AccountsDb::DEFAULT_ACCOUNTS_HASH_CACHE_DIR));
|
||||||
let accounts_hash_cache_path = create_and_canonicalize_directories(&[accounts_hash_cache_path])
|
let accounts_hash_cache_path = create_and_canonicalize_directories([&accounts_hash_cache_path])
|
||||||
.unwrap_or_else(|err| {
|
.unwrap_or_else(|err| {
|
||||||
eprintln!("Unable to access accounts hash cache path: {err}");
|
eprintln!(
|
||||||
|
"Unable to access accounts hash cache path '{}': {err}",
|
||||||
|
accounts_hash_cache_path.display(),
|
||||||
|
);
|
||||||
exit(1);
|
exit(1);
|
||||||
})
|
})
|
||||||
.pop()
|
.pop()
|
||||||
|
@ -1443,11 +1447,10 @@ pub fn main() {
|
||||||
} else {
|
} else {
|
||||||
vec![ledger_path.join("accounts")]
|
vec![ledger_path.join("accounts")]
|
||||||
};
|
};
|
||||||
let account_paths = snapshot_utils::create_and_canonicalize_directories(&account_paths)
|
let account_paths = create_and_canonicalize_directories(account_paths).unwrap_or_else(|err| {
|
||||||
.unwrap_or_else(|err| {
|
eprintln!("Unable to access account path: {err}");
|
||||||
eprintln!("Unable to access account path: {err}");
|
exit(1);
|
||||||
exit(1);
|
});
|
||||||
});
|
|
||||||
|
|
||||||
let account_shrink_paths: Option<Vec<PathBuf>> =
|
let account_shrink_paths: Option<Vec<PathBuf>> =
|
||||||
values_t!(matches, "account_shrink_path", String)
|
values_t!(matches, "account_shrink_path", String)
|
||||||
|
|
Loading…
Reference in New Issue