From 55020d07da9f3a73f717a91736731f54ef3c2673 Mon Sep 17 00:00:00 2001 From: Steven Czabaniuk Date: Fri, 23 Dec 2022 01:59:47 -0500 Subject: [PATCH] Adjust ledger-tool bigtable upload starting-slot default value Currently, if starting-slot is unspecified, a value of 0 will be chosen. In the common case where someone is operating on a range much more recent, this will result in a ton of wasted operations. Instead, choose a smarter default value for starting-slot based on what we detect is currently in the blockstore. --- ledger-tool/src/bigtable.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ledger-tool/src/bigtable.rs b/ledger-tool/src/bigtable.rs index fae7fda6d260a7..f31a36b9d6e24d 100644 --- a/ledger-tool/src/bigtable.rs +++ b/ledger-tool/src/bigtable.rs @@ -38,7 +38,7 @@ use { async fn upload( blockstore: Blockstore, - mut starting_slot: Slot, + starting_slot: Option, ending_slot: Option, force_reupload: bool, config: solana_storage_bigtable::LedgerStorageConfig, @@ -53,6 +53,14 @@ async fn upload( }; let blockstore = Arc::new(blockstore); + let mut starting_slot = match starting_slot { + Some(slot) => slot, + None => blockstore.get_first_available_block()?, + }; + // It is possible that the slot returned below could get purged by + // LedgerCleanupService before upload_confirmed_blocks() receives the + // value. This is ok because upload_confirmed_blocks() doesn't need + // the exact slot to be in ledger, the slot is only used as a bound. let ending_slot = ending_slot.unwrap_or_else(|| blockstore.last_root()); while starting_slot <= ending_slot { @@ -640,7 +648,7 @@ pub fn bigtable_process_command( let future = match (subcommand, sub_matches) { ("upload", Some(arg_matches)) => { - let starting_slot = value_t!(arg_matches, "starting_slot", Slot).unwrap_or(0); + let starting_slot = value_t!(arg_matches, "starting_slot", Slot).ok(); let ending_slot = value_t!(arg_matches, "ending_slot", Slot).ok(); let force_reupload = arg_matches.is_present("force_reupload"); let blockstore = crate::open_blockstore(