Revert "Revert "Ledger-tool: only require ledger dir when necessary (backport #21575) (#21578)""

This reverts commit eae3166bdc.
This commit is contained in:
Tyera Eulberg
2021-12-16 13:57:24 -07:00
committed by Tyera Eulberg
parent 704d05f52d
commit 9fff4aa8b8
3 changed files with 1535 additions and 1481 deletions

View File

@ -1,23 +1,26 @@
/// The `bigtable` subcommand
use clap::{
value_t, value_t_or_exit, values_t_or_exit, App, AppSettings, Arg, ArgMatches, SubCommand,
};
use solana_clap_utils::{
input_parsers::pubkey_of,
input_validators::{is_slot, is_valid_pubkey},
};
use solana_cli_output::{
display::println_transaction, CliBlock, CliTransaction, CliTransactionConfirmation,
OutputFormat,
};
use solana_ledger::{blockstore::Blockstore, blockstore_db::AccessType};
use solana_sdk::{clock::Slot, pubkey::Pubkey, signature::Signature};
use solana_transaction_status::{ConfirmedBlock, EncodedTransaction, UiTransactionEncoding};
use std::{
path::Path,
process::exit,
result::Result,
sync::{atomic::AtomicBool, Arc},
use {
crate::ledger_path::canonicalize_ledger_path,
clap::{
value_t, value_t_or_exit, values_t_or_exit, App, AppSettings, Arg, ArgMatches, SubCommand,
},
solana_clap_utils::{
input_parsers::pubkey_of,
input_validators::{is_slot, is_valid_pubkey},
},
solana_cli_output::{
display::println_transaction, CliBlock, CliTransaction, CliTransactionConfirmation,
OutputFormat,
},
solana_ledger::{blockstore::Blockstore, blockstore_db::AccessType},
solana_sdk::{clock::Slot, pubkey::Pubkey, signature::Signature},
solana_transaction_status::{ConfirmedBlock, EncodedTransaction, UiTransactionEncoding},
std::{
path::Path,
process::exit,
result::Result,
sync::{atomic::AtomicBool, Arc},
},
};
async fn upload(
@ -426,8 +429,11 @@ pub fn bigtable_process_command(ledger_path: &Path, matches: &ArgMatches<'_>) {
let ending_slot = value_t!(arg_matches, "ending_slot", Slot).ok();
let allow_missing_metadata = arg_matches.is_present("allow_missing_metadata");
let force_reupload = arg_matches.is_present("force_reupload");
let blockstore =
crate::open_blockstore(ledger_path, AccessType::TryPrimaryThenSecondary, None);
let blockstore = crate::open_blockstore(
&canonicalize_ledger_path(ledger_path),
AccessType::TryPrimaryThenSecondary,
None,
);
runtime.block_on(upload(
blockstore,

View File

@ -0,0 +1,30 @@
use {
clap::{value_t, ArgMatches},
std::{
fs,
path::{Path, PathBuf},
process::exit,
},
};
pub fn parse_ledger_path(matches: &ArgMatches<'_>, name: &str) -> PathBuf {
PathBuf::from(value_t!(matches, name, String).unwrap_or_else(|_err| {
eprintln!(
"Error: Missing --ledger <DIR> argument.\n\n{}",
matches.usage()
);
exit(1);
}))
}
// Canonicalize ledger path to avoid issues with symlink creation
pub fn canonicalize_ledger_path(ledger_path: &Path) -> PathBuf {
fs::canonicalize(&ledger_path).unwrap_or_else(|err| {
eprintln!(
"Unable to access ledger path '{}': {}",
ledger_path.display(),
err
);
exit(1);
})
}

File diff suppressed because it is too large Load Diff