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

(Ledger-Tool) Add command --purge-older-slots #26905

Closed
wants to merge 1 commit into from
Closed
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
38 changes: 38 additions & 0 deletions ledger-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,19 @@ fn main() {
.help("Target db"),
)
)
.subcommand(
SubCommand::with_name("purge-older-slots")
.about("Purge the slots that is older than or equal to the specified slot")
.arg(
Arg::with_name("ending_slot")
.long("ending-slot")
.value_name("SLOT")
.takes_value(true)
.required(true)
.help("The latest slot to be purged. Anything that is older than \
this slot will be purged.")
)
)
.subcommand(
SubCommand::with_name("slot")
.about("Print the contents of one or more slots")
Expand Down Expand Up @@ -2192,6 +2205,31 @@ fn main() {
}
}
}
("purge-older-slots", Some(arg_matches)) => {
let ending_slot = value_t_or_exit!(arg_matches, "ending_slot", Slot);
let blockstore = open_blockstore(
&ledger_path,
AccessType::Primary,
wal_recovery_mode,
&shred_storage_type,
force_update_to_open,
);
match blockstore.run_purge(
0, // from_slot
ending_slot,
PurgeType::CompactionFilter,
) {
Comment on lines +2217 to +2221
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing purge command can accomplish the same behavior; I believe the following are equivalent:

solana-ledger-tool purge --start_slot 0 --end_slot SLOT ...
solana-ledger-tool purge-older-slots --ending_slot SLOT ...

As such, I don't think this warrants a new subcommand unless there is some subtlety that I'm overlooking

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't notice we already have the purge command. Then I will just improve the comment saying if the starting slot is 0, then all files whose slot range is older than the ending_slot will be deleted immediately.

Ok(columns_purged) => {
if !columns_purged {
eprintln!(
"Internal error. The purge process on some \
columns might not be successful."
);
}
}
Err(_) => eprintln!("Internal error. Failed to submit the purge request.",),
}
}
("genesis", Some(arg_matches)) => {
let genesis_config = open_genesis_config_by(&ledger_path, arg_matches);
let print_accouunts = arg_matches.is_present("accounts");
Expand Down
11 changes: 5 additions & 6 deletions ledger/src/blockstore/blockstore_purge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,11 @@ impl Blockstore {
}
}

pub(crate) fn run_purge(
&self,
from_slot: Slot,
to_slot: Slot,
purge_type: PurgeType,
) -> Result<bool> {
/// Purge any slots within the specified slot range for all slot-based columns.
///
/// Note that `from_slot` is 0, any sst-file with a slot-range completely older
/// than `to_slot` will be deleted immediately.
pub fn run_purge(&self, from_slot: Slot, to_slot: Slot, purge_type: PurgeType) -> Result<bool> {
self.run_purge_with_stats(from_slot, to_slot, purge_type, &mut PurgeStats::default())
}

Expand Down