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

Separate snapshot location (bp #15840) #15956

Merged
merged 6 commits into from
Mar 17, 2021
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
6 changes: 3 additions & 3 deletions download-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,19 @@ pub fn download_genesis_if_missing(

pub fn download_snapshot(
rpc_addr: &SocketAddr,
ledger_path: &Path,
snapshot_output_dir: &Path,
desired_snapshot_hash: (Slot, Hash),
use_progress_bar: bool,
) -> Result<(), String> {
snapshot_utils::purge_old_snapshot_archives(ledger_path);
snapshot_utils::purge_old_snapshot_archives(snapshot_output_dir);

for compression in &[
ArchiveFormat::TarZstd,
ArchiveFormat::TarGzip,
ArchiveFormat::TarBzip2,
] {
let desired_snapshot_package = snapshot_utils::get_snapshot_archive_path(
ledger_path.to_path_buf(),
snapshot_output_dir.to_path_buf(),
&desired_snapshot_hash,
*compression,
);
Expand Down
30 changes: 22 additions & 8 deletions validator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ fn get_rpc_node(
blacklisted_rpc_nodes: &mut HashSet<Pubkey>,
snapshot_not_required: bool,
no_untrusted_rpc: bool,
ledger_path: &std::path::Path,
snapshot_output_dir: &Path,
) -> Option<(ContactInfo, Option<(Slot, Hash)>)> {
let mut blacklist_timeout = Instant::now();
let mut newer_cluster_snapshot_timeout = None;
Expand Down Expand Up @@ -420,7 +420,7 @@ fn get_rpc_node(
blacklist_timeout = Instant::now();

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));
let eligible_rpc_peers = if snapshot_not_required {
rpc_peers
Expand Down Expand Up @@ -758,6 +758,7 @@ fn rpc_bootstrap(
node: &Node,
identity_keypair: &Arc<Keypair>,
ledger_path: &Path,
snapshot_output_dir: &Path,
vote_account: &Pubkey,
authorized_voter_keypairs: &[Arc<Keypair>],
cluster_entrypoints: &[ContactInfo],
Expand Down Expand Up @@ -809,7 +810,7 @@ fn rpc_bootstrap(
&mut blacklisted_rpc_nodes,
bootstrap_config.no_snapshot_fetch,
bootstrap_config.no_untrusted_rpc,
ledger_path,
snapshot_output_dir,
);
if rpc_node_details.is_none() {
return;
Expand Down Expand Up @@ -865,7 +866,7 @@ fn rpc_bootstrap(
let mut use_local_snapshot = false;

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)
{
if highest_local_snapshot_slot
Expand Down Expand Up @@ -905,7 +906,7 @@ fn rpc_bootstrap(
gossip_exit_flag.store(true, Ordering::Relaxed);
let ret = download_snapshot(
&rpc_contact_info.rpc,
&ledger_path,
&snapshot_output_dir,
snapshot_hash,
use_progress_bar,
);
Expand Down Expand Up @@ -1203,6 +1204,13 @@ pub fn main() {
.multiple(true)
.help("Path to accounts shrink path which can hold a compacted account set."),
)
.arg(
Arg::with_name("snapshots")
.long("snapshots")
.value_name("DIR")
.takes_value(true)
.help("Use DIR as persistent snapshot [default: --ledger value]"),
)
.arg(
Arg::with_name("gossip_port")
.long("gossip-port")
Expand Down Expand Up @@ -2058,7 +2066,12 @@ pub fn main() {

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 snapshot_path = ledger_path.join("snapshot");
let snapshot_output_dir = if matches.is_present("snapshots") {
PathBuf::from(matches.value_of("snapshots").unwrap())
} else {
ledger_path.clone()
};
let snapshot_path = snapshot_output_dir.join("snapshot");
fs::create_dir_all(&snapshot_path).unwrap_or_else(|err| {
eprintln!(
"Failed to create snapshots directory {:?}: {}",
Expand Down Expand Up @@ -2094,7 +2107,7 @@ pub fn main() {
std::u64::MAX
},
snapshot_path,
snapshot_package_output_path: ledger_path.clone(),
snapshot_package_output_path: snapshot_output_dir.clone(),
archive_format,
snapshot_version,
});
Expand Down Expand Up @@ -2291,14 +2304,15 @@ pub fn main() {
enable_recycler_warming();
}
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");
if !cluster_entrypoints.is_empty() {
rpc_bootstrap(
&node,
&identity_keypair,
&ledger_path,
&snapshot_output_dir,
&vote_account,
&authorized_voter_keypairs,
&cluster_entrypoints,
Expand Down