Add option for separate snapshot location

(cherry picked from commit 6126878f509c69e23480a5ec22b3271e2b16e072)
This commit is contained in:
DimAn 2021-03-13 21:48:26 +00:00 committed by Michael Vines
parent 58b980f9cd
commit 0209d334bd
3 changed files with 30 additions and 14 deletions

View File

@ -178,11 +178,11 @@ pub fn download_genesis_if_missing(
pub fn download_snapshot( pub fn download_snapshot(
rpc_addr: &SocketAddr, rpc_addr: &SocketAddr,
ledger_path: &Path, snapshot_output_dir: &Path,
desired_snapshot_hash: (Slot, Hash), desired_snapshot_hash: (Slot, Hash),
use_progress_bar: bool, use_progress_bar: bool,
) -> Result<(), String> { ) -> Result<(), String> {
snapshot_utils::purge_old_snapshot_archives(ledger_path); snapshot_utils::purge_old_snapshot_archives(snapshot_output_dir);
for compression in &[ for compression in &[
ArchiveFormat::TarZstd, ArchiveFormat::TarZstd,
@ -190,7 +190,7 @@ pub fn download_snapshot(
ArchiveFormat::TarBzip2, ArchiveFormat::TarBzip2,
] { ] {
let desired_snapshot_package = snapshot_utils::get_snapshot_archive_path( let desired_snapshot_package = snapshot_utils::get_snapshot_archive_path(
ledger_path.to_path_buf(), snapshot_output_dir.to_path_buf(),
&desired_snapshot_hash, &desired_snapshot_hash,
*compression, *compression,
); );

View File

@ -44,6 +44,7 @@ const MAX_SNAPSHOT_DATA_FILE_SIZE: u64 = 32 * 1024 * 1024 * 1024; // 32 GiB
const VERSION_STRING_V1_2_0: &str = "1.2.0"; const VERSION_STRING_V1_2_0: &str = "1.2.0";
const DEFAULT_SNAPSHOT_VERSION: SnapshotVersion = SnapshotVersion::V1_2_0; const DEFAULT_SNAPSHOT_VERSION: SnapshotVersion = SnapshotVersion::V1_2_0;
const TMP_SNAPSHOT_PREFIX: &str = "tmp-snapshot-"; const TMP_SNAPSHOT_PREFIX: &str = "tmp-snapshot-";
const TMP_SNAPSHOT_EXTENSION: &str = ".tmp"; // when downloading
#[derive(Copy, Clone, Eq, PartialEq, Debug)] #[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum SnapshotVersion { pub enum SnapshotVersion {
@ -206,11 +207,12 @@ fn get_archive_ext(archive_format: ArchiveFormat) -> &'static str {
pub fn remove_tmp_snapshot_archives(snapshot_path: &Path) { pub fn remove_tmp_snapshot_archives(snapshot_path: &Path) {
if let Ok(entries) = fs::read_dir(&snapshot_path) { if let Ok(entries) = fs::read_dir(&snapshot_path) {
for entry in entries.filter_map(|entry| entry.ok()) { for entry in entries.filter_map(|entry| entry.ok()) {
if entry let filename = entry
.file_name() .file_name()
.into_string() .into_string()
.unwrap_or_else(|_| String::new()) .unwrap_or_else(|_| String::new());
.starts_with(TMP_SNAPSHOT_PREFIX) if filename.starts_with(TMP_SNAPSHOT_PREFIX)
| filename.ends_with(TMP_SNAPSHOT_EXTENSION)
{ {
if entry.path().is_file() { if entry.path().is_file() {
fs::remove_file(entry.path()) fs::remove_file(entry.path())

View File

@ -341,7 +341,7 @@ fn get_rpc_node(
blacklisted_rpc_nodes: &mut HashSet<Pubkey>, blacklisted_rpc_nodes: &mut HashSet<Pubkey>,
snapshot_not_required: bool, snapshot_not_required: bool,
no_untrusted_rpc: bool, no_untrusted_rpc: bool,
ledger_path: &std::path::Path, snapshot_output_dir: &Path,
) -> Option<(ContactInfo, Option<(Slot, Hash)>)> { ) -> Option<(ContactInfo, Option<(Slot, Hash)>)> {
let mut blacklist_timeout = Instant::now(); let mut blacklist_timeout = Instant::now();
let mut newer_cluster_snapshot_timeout = None; let mut newer_cluster_snapshot_timeout = None;
@ -420,7 +420,7 @@ fn get_rpc_node(
blacklist_timeout = Instant::now(); blacklist_timeout = Instant::now();
let mut highest_snapshot_hash: Option<(Slot, Hash)> = let mut highest_snapshot_hash: Option<(Slot, Hash)> =
get_highest_snapshot_archive_path(ledger_path) get_highest_snapshot_archive_path(snapshot_output_dir)
.map(|(_path, (slot, hash, _compression))| (slot, hash)); .map(|(_path, (slot, hash, _compression))| (slot, hash));
let eligible_rpc_peers = if snapshot_not_required { let eligible_rpc_peers = if snapshot_not_required {
rpc_peers rpc_peers
@ -758,6 +758,7 @@ fn rpc_bootstrap(
node: &Node, node: &Node,
identity_keypair: &Arc<Keypair>, identity_keypair: &Arc<Keypair>,
ledger_path: &Path, ledger_path: &Path,
snapshot_output_dir: &Path,
vote_account: &Pubkey, vote_account: &Pubkey,
authorized_voter_keypairs: &[Arc<Keypair>], authorized_voter_keypairs: &[Arc<Keypair>],
cluster_entrypoints: &[ContactInfo], cluster_entrypoints: &[ContactInfo],
@ -809,7 +810,7 @@ fn rpc_bootstrap(
&mut blacklisted_rpc_nodes, &mut blacklisted_rpc_nodes,
bootstrap_config.no_snapshot_fetch, bootstrap_config.no_snapshot_fetch,
bootstrap_config.no_untrusted_rpc, bootstrap_config.no_untrusted_rpc,
ledger_path, snapshot_output_dir,
); );
if rpc_node_details.is_none() { if rpc_node_details.is_none() {
return; return;
@ -865,7 +866,7 @@ fn rpc_bootstrap(
let mut use_local_snapshot = false; let mut use_local_snapshot = false;
if let Some(highest_local_snapshot_slot) = if let Some(highest_local_snapshot_slot) =
get_highest_snapshot_archive_path(ledger_path) get_highest_snapshot_archive_path(snapshot_output_dir)
.map(|(_path, (slot, _hash, _compression))| slot) .map(|(_path, (slot, _hash, _compression))| slot)
{ {
if highest_local_snapshot_slot if highest_local_snapshot_slot
@ -905,7 +906,7 @@ fn rpc_bootstrap(
gossip_exit_flag.store(true, Ordering::Relaxed); gossip_exit_flag.store(true, Ordering::Relaxed);
let ret = download_snapshot( let ret = download_snapshot(
&rpc_contact_info.rpc, &rpc_contact_info.rpc,
&ledger_path, &snapshot_output_dir,
snapshot_hash, snapshot_hash,
use_progress_bar, use_progress_bar,
); );
@ -1203,6 +1204,13 @@ pub fn main() {
.multiple(true) .multiple(true)
.help("Path to accounts shrink path which can hold a compacted account set."), .help("Path to accounts shrink path which can hold a compacted account set."),
) )
.arg(
Arg::with_name("snapshots_path")
.long("snapshots")
.value_name("PATHS")
.takes_value(true)
.help("Snapshots location"),
)
.arg( .arg(
Arg::with_name("gossip_port") Arg::with_name("gossip_port")
.long("gossip-port") .long("gossip-port")
@ -2058,7 +2066,12 @@ pub fn main() {
let snapshot_interval_slots = value_t_or_exit!(matches, "snapshot_interval_slots", u64); let snapshot_interval_slots = value_t_or_exit!(matches, "snapshot_interval_slots", u64);
let maximum_local_snapshot_age = value_t_or_exit!(matches, "maximum_local_snapshot_age", u64); let maximum_local_snapshot_age = value_t_or_exit!(matches, "maximum_local_snapshot_age", u64);
let snapshot_path = ledger_path.join("snapshot"); let snapshot_output_dir = if matches.is_present("snapshots_path") {
PathBuf::from(matches.value_of("snapshots_path").unwrap())
} else {
ledger_path.clone()
};
let snapshot_path = snapshot_output_dir.join("snapshot");
fs::create_dir_all(&snapshot_path).unwrap_or_else(|err| { fs::create_dir_all(&snapshot_path).unwrap_or_else(|err| {
eprintln!( eprintln!(
"Failed to create snapshots directory {:?}: {}", "Failed to create snapshots directory {:?}: {}",
@ -2094,7 +2107,7 @@ pub fn main() {
std::u64::MAX std::u64::MAX
}, },
snapshot_path, snapshot_path,
snapshot_package_output_path: ledger_path.clone(), snapshot_package_output_path: snapshot_output_dir.clone(),
archive_format, archive_format,
snapshot_version, snapshot_version,
}); });
@ -2291,7 +2304,7 @@ pub fn main() {
enable_recycler_warming(); enable_recycler_warming();
} }
solana_ledger::entry::init_poh(); solana_ledger::entry::init_poh();
solana_runtime::snapshot_utils::remove_tmp_snapshot_archives(&ledger_path); solana_runtime::snapshot_utils::remove_tmp_snapshot_archives(&snapshot_output_dir);
let should_check_duplicate_instance = !matches.is_present("no_duplicate_instance_check"); let should_check_duplicate_instance = !matches.is_present("no_duplicate_instance_check");
if !cluster_entrypoints.is_empty() { if !cluster_entrypoints.is_empty() {
@ -2299,6 +2312,7 @@ pub fn main() {
&node, &node,
&identity_keypair, &identity_keypair,
&ledger_path, &ledger_path,
&snapshot_output_dir,
&vote_account, &vote_account,
&authorized_voter_keypairs, &authorized_voter_keypairs,
&cluster_entrypoints, &cluster_entrypoints,