From fe49d7ba34efde753c33ea2792253452f2df3bca Mon Sep 17 00:00:00 2001 From: Brooks Date: Mon, 10 Jun 2024 08:28:40 -0400 Subject: [PATCH] cli: Fixes snapshot paths (#1631) --- CHANGELOG.md | 1 + ledger-tool/src/main.rs | 1 + validator/src/cli.rs | 18 ++++++++++-- validator/src/main.rs | 63 +++++++++++++++++++++++++---------------- 4 files changed, 56 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89bcf65149db3e..102aa724f7e32d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ Release channels have their own copy of this changelog: * RPC's `simulateTransaction` now returns an extra `replacementBlockhash` field in the response when the `replaceRecentBlockhash` config param is `true` (#380) * SDK: `cargo test-sbf` accepts `--tools-version`, just like `build-sbf` (#1359) + * CLI: Can specify `--full-snapshot-archive-path` (#1631) ## [1.18.0] * Changes diff --git a/ledger-tool/src/main.rs b/ledger-tool/src/main.rs index 7a41758da291a0..9bbaaddc8d9e0a 100644 --- a/ledger-tool/src/main.rs +++ b/ledger-tool/src/main.rs @@ -808,6 +808,7 @@ fn main() { Arg::with_name("snapshots") .long("snapshots") .alias("snapshot-archive-path") + .alias("full-snapshot-archive-path") .value_name("DIR") .takes_value(true) .global(true) diff --git a/validator/src/cli.rs b/validator/src/cli.rs index 68841e34d4b319..978d650a2ef1de 100644 --- a/validator/src/cli.rs +++ b/validator/src/cli.rs @@ -332,7 +332,11 @@ pub fn app<'a>(version: &'a str, default_args: &'a DefaultArgs) -> App<'a, 'a> { .long("snapshots") .value_name("DIR") .takes_value(true) - .help("Use DIR as snapshot location [default: /snapshots]"), + .help( + "Use DIR as the base location for snapshots. \ + A subdirectory named \"snapshots\" will be created. \ + [default: --ledger value]", + ), ) .arg( Arg::with_name(use_snapshot_archives_at_startup::cli::NAME) @@ -343,6 +347,16 @@ pub fn app<'a>(version: &'a str, default_args: &'a DefaultArgs) -> App<'a, 'a> { .help(use_snapshot_archives_at_startup::cli::HELP) .long_help(use_snapshot_archives_at_startup::cli::LONG_HELP), ) + .arg( + Arg::with_name("full_snapshot_archive_path") + .long("full-snapshot-archive-path") + .value_name("DIR") + .takes_value(true) + .help( + "Use DIR as full snapshot archives location \ + [default: --snapshots value]", + ), + ) .arg( Arg::with_name("incremental_snapshot_archive_path") .long("incremental-snapshot-archive-path") @@ -350,7 +364,7 @@ pub fn app<'a>(version: &'a str, default_args: &'a DefaultArgs) -> App<'a, 'a> { .value_name("DIR") .takes_value(true) .help( - "Use DIR as separate location for incremental snapshot archives \ + "Use DIR as incremental snapshot archives location \ [default: --snapshots value]", ), ) diff --git a/validator/src/main.rs b/validator/src/main.rs index 2b6d2330651e31..7be329463a6b61 100644 --- a/validator/src/main.rs +++ b/validator/src/main.rs @@ -1589,36 +1589,49 @@ pub fn main() { let maximum_snapshot_download_abort = value_t_or_exit!(matches, "maximum_snapshot_download_abort", u64); - let full_snapshot_archives_dir = if matches.is_present("snapshots") { - PathBuf::from(matches.value_of("snapshots").unwrap()) + let snapshots_dir = if let Some(snapshots) = matches.value_of("snapshots") { + Path::new(snapshots) } else { - ledger_path.clone() + &ledger_path }; - let incremental_snapshot_archives_dir = - if matches.is_present("incremental_snapshot_archive_path") { - let incremental_snapshot_archives_dir = PathBuf::from( - matches - .value_of("incremental_snapshot_archive_path") - .unwrap(), - ); - fs::create_dir_all(&incremental_snapshot_archives_dir).unwrap_or_else(|err| { - eprintln!( - "Failed to create incremental snapshot archives directory {:?}: {}", - incremental_snapshot_archives_dir.display(), - err - ); - exit(1); - }); - incremental_snapshot_archives_dir - } else { - full_snapshot_archives_dir.clone() - }; - let bank_snapshots_dir = incremental_snapshot_archives_dir.join("snapshot"); + + let bank_snapshots_dir = snapshots_dir.join("snapshots"); fs::create_dir_all(&bank_snapshots_dir).unwrap_or_else(|err| { eprintln!( - "Failed to create snapshots directory {:?}: {}", + "Failed to create bank snapshots directory '{}': {err}", bank_snapshots_dir.display(), - err + ); + exit(1); + }); + + let full_snapshot_archives_dir = PathBuf::from( + if let Some(full_snapshot_archive_path) = matches.value_of("full_snapshot_archive_path") { + Path::new(full_snapshot_archive_path) + } else { + snapshots_dir + }, + ); + fs::create_dir_all(&full_snapshot_archives_dir).unwrap_or_else(|err| { + eprintln!( + "Failed to create full snapshot archives directory '{}': {err}", + full_snapshot_archives_dir.display(), + ); + exit(1); + }); + + let incremental_snapshot_archives_dir = PathBuf::from( + if let Some(incremental_snapshot_archive_path) = + matches.value_of("incremental_snapshot_archive_path") + { + Path::new(incremental_snapshot_archive_path) + } else { + snapshots_dir + }, + ); + fs::create_dir_all(&incremental_snapshot_archives_dir).unwrap_or_else(|err| { + eprintln!( + "Failed to create incremental snapshot archives directory '{}': {err}", + incremental_snapshot_archives_dir.display(), ); exit(1); });