Skip to content

Commit

Permalink
Plumb maximum_incremental_snapshot_archives_to_retain (solana-labs#…
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo authored and dankelleher committed Nov 24, 2021
1 parent e9cc040 commit 9e606be
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 32 deletions.
2 changes: 2 additions & 0 deletions core/src/snapshot_packager_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ impl SnapshotPackagerService {
snapshot_utils::archive_snapshot_package(
&snapshot_package,
snapshot_config.maximum_full_snapshot_archives_to_retain,
snapshot_config.maximum_incremental_snapshot_archives_to_retain,
)
.expect("failed to archive snapshot package");

Expand Down Expand Up @@ -190,6 +191,7 @@ mod tests {
snapshot_utils::archive_snapshot_package(
&snapshot_package,
snapshot_utils::DEFAULT_MAX_FULL_SNAPSHOT_ARCHIVES_TO_RETAIN,
snapshot_utils::DEFAULT_MAX_INCREMENTAL_SNAPSHOT_ARCHIVES_TO_RETAIN,
)
.unwrap();

Expand Down
1 change: 1 addition & 0 deletions core/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,7 @@ fn new_banks_from_ledger(
&snapshot_config.snapshot_archives_dir,
snapshot_config.archive_format,
snapshot_config.maximum_full_snapshot_archives_to_retain,
snapshot_config.maximum_incremental_snapshot_archives_to_retain,
)
.unwrap_or_else(|err| {
error!("Unable to create snapshot: {}", err);
Expand Down
9 changes: 6 additions & 3 deletions core/tests/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ mod tests {
let snapshot_package = SnapshotPackage::from(accounts_package);
snapshot_utils::archive_snapshot_package(
&snapshot_package,
DEFAULT_MAX_FULL_SNAPSHOT_ARCHIVES_TO_RETAIN,
snapshot_config.maximum_full_snapshot_archives_to_retain,
snapshot_config.maximum_incremental_snapshot_archives_to_retain,
)
.unwrap();

Expand Down Expand Up @@ -387,7 +388,7 @@ mod tests {
let saved_slot = 4;
let mut saved_archive_path = None;

for forks in 0..snapshot_utils::MAX_BANK_SNAPSHOTS + 2 {
for forks in 0..snapshot_utils::MAX_BANK_SNAPSHOTS_TO_RETAIN + 2 {
let bank = Bank::new_from_parent(
&bank_forks[forks as u64],
&Pubkey::default(),
Expand Down Expand Up @@ -483,7 +484,7 @@ mod tests {
assert!(bank_snapshots
.into_iter()
.map(|path| path.slot)
.eq(3..=snapshot_utils::MAX_BANK_SNAPSHOTS as u64 + 2));
.eq(3..=snapshot_utils::MAX_BANK_SNAPSHOTS_TO_RETAIN as u64 + 2));

// Create a SnapshotPackagerService to create tarballs from all the pending
// SnapshotPackage's on the channel. By the time this service starts, we have already
Expand Down Expand Up @@ -776,6 +777,7 @@ mod tests {
snapshot_config.archive_format,
snapshot_config.snapshot_version,
snapshot_config.maximum_full_snapshot_archives_to_retain,
snapshot_config.maximum_incremental_snapshot_archives_to_retain,
)?;

Ok(())
Expand Down Expand Up @@ -812,6 +814,7 @@ mod tests {
snapshot_config.archive_format,
snapshot_config.snapshot_version,
snapshot_config.maximum_full_snapshot_archives_to_retain,
snapshot_config.maximum_incremental_snapshot_archives_to_retain,
)?;

Ok(())
Expand Down
7 changes: 4 additions & 3 deletions download-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,14 @@ pub fn download_snapshot<'a, 'b>(
snapshot_archives_dir: &Path,
desired_snapshot_hash: (Slot, Hash),
use_progress_bar: bool,
maximum_snapshots_to_retain: usize,
maximum_full_snapshot_archives_to_retain: usize,
maximum_incremental_snapshot_archives_to_retain: usize,
progress_notify_callback: &'a mut DownloadProgressCallbackOption<'b>,
) -> Result<(), String> {
snapshot_utils::purge_old_snapshot_archives(
snapshot_archives_dir,
maximum_snapshots_to_retain,
snapshot_utils::DEFAULT_MAX_INCREMENTAL_SNAPSHOT_ARCHIVES_TO_RETAIN,
maximum_full_snapshot_archives_to_retain,
maximum_incremental_snapshot_archives_to_retain,
);

for compression in &[
Expand Down
7 changes: 5 additions & 2 deletions ledger-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2018,8 +2018,10 @@ fn main() {
})
});

let maximum_snapshots_to_retain =
let maximum_full_snapshot_archives_to_retain =
value_t_or_exit!(arg_matches, "maximum_snapshots_to_retain", usize);
let maximum_incremental_snapshot_archives_to_retain =
snapshot_utils::DEFAULT_MAX_INCREMENTAL_SNAPSHOT_ARCHIVES_TO_RETAIN;
let genesis_config = open_genesis_config_by(&ledger_path, arg_matches);
let blockstore = open_blockstore(
&ledger_path,
Expand Down Expand Up @@ -2235,7 +2237,8 @@ fn main() {
Some(snapshot_version),
output_directory,
ArchiveFormat::TarZstd,
maximum_snapshots_to_retain,
maximum_full_snapshot_archives_to_retain,
maximum_incremental_snapshot_archives_to_retain,
)
.unwrap_or_else(|err| {
eprintln!("Unable to create snapshot: {}", err);
Expand Down
1 change: 1 addition & 0 deletions local-cluster/tests/local_cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1708,6 +1708,7 @@ fn test_snapshot_download() {
archive_snapshot_hash,
false,
snapshot_utils::DEFAULT_MAX_FULL_SNAPSHOT_ARCHIVES_TO_RETAIN,
snapshot_utils::DEFAULT_MAX_INCREMENTAL_SNAPSHOT_ARCHIVES_TO_RETAIN,
&mut None,
)
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions replica-node/src/replica_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ fn initialize_from_snapshot(
replica_config.snapshot_info,
false,
snapshot_config.maximum_full_snapshot_archives_to_retain,
snapshot_config.maximum_incremental_snapshot_archives_to_retain,
&mut None,
)
.unwrap();
Expand Down
64 changes: 44 additions & 20 deletions runtime/src/snapshot_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ use {

pub const SNAPSHOT_STATUS_CACHE_FILE_NAME: &str = "status_cache";

pub const MAX_BANK_SNAPSHOTS: usize = 8; // Save some snapshots but not too many
const MAX_SNAPSHOT_DATA_FILE_SIZE: u64 = 32 * 1024 * 1024 * 1024; // 32 GiB
const VERSION_STRING_V1_2_0: &str = "1.2.0";
const DEFAULT_SNAPSHOT_VERSION: SnapshotVersion = SnapshotVersion::V1_2_0;
pub(crate) const TMP_BANK_SNAPSHOT_PREFIX: &str = "tmp-bank-snapshot-";
pub const TMP_SNAPSHOT_ARCHIVE_PREFIX: &str = "tmp-snapshot-archive-";
pub const MAX_BANK_SNAPSHOTS_TO_RETAIN: usize = 8; // Save some bank snapshots but not too many
pub const DEFAULT_MAX_FULL_SNAPSHOT_ARCHIVES_TO_RETAIN: usize = 2;
pub const DEFAULT_MAX_INCREMENTAL_SNAPSHOT_ARCHIVES_TO_RETAIN: usize = 4;
pub const FULL_SNAPSHOT_ARCHIVE_FILENAME_REGEX: &str = r"^snapshot-(?P<slot>[[:digit:]]+)-(?P<hash>[[:alnum:]]+)\.(?P<ext>tar|tar\.bz2|tar\.zst|tar\.gz)$";
Expand Down Expand Up @@ -242,7 +242,8 @@ pub fn remove_tmp_snapshot_archives(snapshot_archives_dir: impl AsRef<Path>) {
/// Make a snapshot archive out of the snapshot package
pub fn archive_snapshot_package(
snapshot_package: &SnapshotPackage,
maximum_snapshot_archives_to_retain: usize,
maximum_full_snapshot_archives_to_retain: usize,
maximum_incremental_snapshot_archives_to_retain: usize,
) -> Result<()> {
info!(
"Generating snapshot archive for slot {}",
Expand Down Expand Up @@ -374,8 +375,8 @@ pub fn archive_snapshot_package(

purge_old_snapshot_archives(
tar_dir,
maximum_snapshot_archives_to_retain,
DEFAULT_MAX_INCREMENTAL_SNAPSHOT_ARCHIVES_TO_RETAIN,
maximum_full_snapshot_archives_to_retain,
maximum_incremental_snapshot_archives_to_retain,
);

timer.stop();
Expand Down Expand Up @@ -1552,12 +1553,12 @@ where
bank_snapshot_infos
.into_iter()
.rev()
.skip(MAX_BANK_SNAPSHOTS)
.skip(MAX_BANK_SNAPSHOTS_TO_RETAIN)
.for_each(|bank_snapshot_info| {
let r = remove_bank_snapshot(bank_snapshot_info.slot, &bank_snapshots_dir);
if r.is_err() {
warn!(
"Couldn't remove snapshot at: {}",
"Couldn't remove bank snapshot at: {}",
bank_snapshot_info.snapshot_path.display()
);
}
Expand Down Expand Up @@ -1630,7 +1631,8 @@ pub fn bank_to_full_snapshot_archive(
snapshot_version: Option<SnapshotVersion>,
snapshot_archives_dir: impl AsRef<Path>,
archive_format: ArchiveFormat,
maximum_snapshots_to_retain: usize,
maximum_full_snapshot_archives_to_retain: usize,
maximum_incremental_snapshot_archives_to_retain: usize,
) -> Result<FullSnapshotArchiveInfo> {
let snapshot_version = snapshot_version.unwrap_or_default();

Expand All @@ -1654,7 +1656,8 @@ pub fn bank_to_full_snapshot_archive(
snapshot_storages,
archive_format,
snapshot_version,
maximum_snapshots_to_retain,
maximum_full_snapshot_archives_to_retain,
maximum_incremental_snapshot_archives_to_retain,
)
}

Expand All @@ -1671,7 +1674,8 @@ pub fn bank_to_incremental_snapshot_archive(
snapshot_version: Option<SnapshotVersion>,
snapshot_archives_dir: impl AsRef<Path>,
archive_format: ArchiveFormat,
maximum_snapshots_to_retain: usize,
maximum_full_snapshot_archives_to_retain: usize,
maximum_incremental_snapshot_archives_to_retain: usize,
) -> Result<IncrementalSnapshotArchiveInfo> {
let snapshot_version = snapshot_version.unwrap_or_default();

Expand All @@ -1697,7 +1701,8 @@ pub fn bank_to_incremental_snapshot_archive(
snapshot_storages,
archive_format,
snapshot_version,
maximum_snapshots_to_retain,
maximum_full_snapshot_archives_to_retain,
maximum_incremental_snapshot_archives_to_retain,
)
}

Expand All @@ -1710,7 +1715,8 @@ pub fn package_and_archive_full_snapshot(
snapshot_storages: SnapshotStorages,
archive_format: ArchiveFormat,
snapshot_version: SnapshotVersion,
maximum_snapshots_to_retain: usize,
maximum_full_snapshot_archives_to_retain: usize,
maximum_incremental_snapshot_archives_to_retain: usize,
) -> Result<FullSnapshotArchiveInfo> {
let accounts_package = AccountsPackage::new(
bank,
Expand All @@ -1726,7 +1732,11 @@ pub fn package_and_archive_full_snapshot(
)?;

let snapshot_package = SnapshotPackage::from(accounts_package);
archive_snapshot_package(&snapshot_package, maximum_snapshots_to_retain)?;
archive_snapshot_package(
&snapshot_package,
maximum_full_snapshot_archives_to_retain,
maximum_incremental_snapshot_archives_to_retain,
)?;

Ok(FullSnapshotArchiveInfo::new(
snapshot_package.snapshot_archive_info,
Expand All @@ -1744,7 +1754,8 @@ pub fn package_and_archive_incremental_snapshot(
snapshot_storages: SnapshotStorages,
archive_format: ArchiveFormat,
snapshot_version: SnapshotVersion,
maximum_snapshots_to_retain: usize,
maximum_full_snapshot_archives_to_retain: usize,
maximum_incremental_snapshot_archives_to_retain: usize,
) -> Result<IncrementalSnapshotArchiveInfo> {
let accounts_package = AccountsPackage::new(
bank,
Expand All @@ -1762,7 +1773,11 @@ pub fn package_and_archive_incremental_snapshot(
)?;

let snapshot_package = SnapshotPackage::from(accounts_package);
archive_snapshot_package(&snapshot_package, maximum_snapshots_to_retain)?;
archive_snapshot_package(
&snapshot_package,
maximum_full_snapshot_archives_to_retain,
maximum_incremental_snapshot_archives_to_retain,
)?;

Ok(IncrementalSnapshotArchiveInfo::new(
incremental_snapshot_base_slot,
Expand Down Expand Up @@ -2544,7 +2559,8 @@ mod tests {
None,
snapshot_archives_dir.path(),
snapshot_archive_format,
1,
DEFAULT_MAX_FULL_SNAPSHOT_ARCHIVES_TO_RETAIN,
DEFAULT_MAX_INCREMENTAL_SNAPSHOT_ARCHIVES_TO_RETAIN,
)
.unwrap();

Expand Down Expand Up @@ -2634,7 +2650,8 @@ mod tests {
None,
snapshot_archives_dir.path(),
snapshot_archive_format,
std::usize::MAX,
DEFAULT_MAX_FULL_SNAPSHOT_ARCHIVES_TO_RETAIN,
DEFAULT_MAX_INCREMENTAL_SNAPSHOT_ARCHIVES_TO_RETAIN,
)
.unwrap();

Expand Down Expand Up @@ -2710,7 +2727,8 @@ mod tests {
None,
snapshot_archives_dir.path(),
snapshot_archive_format,
std::usize::MAX,
DEFAULT_MAX_FULL_SNAPSHOT_ARCHIVES_TO_RETAIN,
DEFAULT_MAX_INCREMENTAL_SNAPSHOT_ARCHIVES_TO_RETAIN,
)
.unwrap();

Expand Down Expand Up @@ -2742,7 +2760,8 @@ mod tests {
None,
snapshot_archives_dir.path(),
snapshot_archive_format,
std::usize::MAX,
DEFAULT_MAX_FULL_SNAPSHOT_ARCHIVES_TO_RETAIN,
DEFAULT_MAX_INCREMENTAL_SNAPSHOT_ARCHIVES_TO_RETAIN,
)
.unwrap();

Expand Down Expand Up @@ -2808,7 +2827,8 @@ mod tests {
None,
&snapshot_archives_dir,
snapshot_archive_format,
std::usize::MAX,
DEFAULT_MAX_FULL_SNAPSHOT_ARCHIVES_TO_RETAIN,
DEFAULT_MAX_INCREMENTAL_SNAPSHOT_ARCHIVES_TO_RETAIN,
)
.unwrap();

Expand Down Expand Up @@ -2840,7 +2860,8 @@ mod tests {
None,
&snapshot_archives_dir,
snapshot_archive_format,
std::usize::MAX,
DEFAULT_MAX_FULL_SNAPSHOT_ARCHIVES_TO_RETAIN,
DEFAULT_MAX_INCREMENTAL_SNAPSHOT_ARCHIVES_TO_RETAIN,
)
.unwrap();

Expand Down Expand Up @@ -2939,6 +2960,7 @@ mod tests {
snapshot_archives_dir.path(),
snapshot_archive_format,
DEFAULT_MAX_FULL_SNAPSHOT_ARCHIVES_TO_RETAIN,
DEFAULT_MAX_INCREMENTAL_SNAPSHOT_ARCHIVES_TO_RETAIN,
)
.unwrap();

Expand Down Expand Up @@ -2980,6 +3002,7 @@ mod tests {
snapshot_archives_dir.path(),
snapshot_archive_format,
DEFAULT_MAX_FULL_SNAPSHOT_ARCHIVES_TO_RETAIN,
DEFAULT_MAX_INCREMENTAL_SNAPSHOT_ARCHIVES_TO_RETAIN,
)
.unwrap();
let (deserialized_bank, _) = bank_from_snapshot_archives(
Expand Down Expand Up @@ -3040,6 +3063,7 @@ mod tests {
snapshot_archives_dir.path(),
snapshot_archive_format,
DEFAULT_MAX_FULL_SNAPSHOT_ARCHIVES_TO_RETAIN,
DEFAULT_MAX_INCREMENTAL_SNAPSHOT_ARCHIVES_TO_RETAIN,
)
.unwrap();

Expand Down
9 changes: 5 additions & 4 deletions validator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -925,19 +925,20 @@ fn rpc_bootstrap(
gossip.take().unwrap();
cluster_info.save_contact_info();
gossip_exit_flag.store(true, Ordering::Relaxed);
let maximum_snapshots_to_retain = if let Some(snapshot_config) =
let (maximum_full_snapshot_archives_to_retain, maximum_incremental_snapshot_archives_to_retain) = if let Some(snapshot_config) =
validator_config.snapshot_config.as_ref()
{
snapshot_config.maximum_full_snapshot_archives_to_retain
(snapshot_config.maximum_full_snapshot_archives_to_retain, snapshot_config.maximum_incremental_snapshot_archives_to_retain)
} else {
DEFAULT_MAX_FULL_SNAPSHOT_ARCHIVES_TO_RETAIN
(DEFAULT_MAX_FULL_SNAPSHOT_ARCHIVES_TO_RETAIN, DEFAULT_MAX_INCREMENTAL_SNAPSHOT_ARCHIVES_TO_RETAIN)
};
let ret = download_snapshot(
&rpc_contact_info.rpc,
snapshot_archives_dir,
snapshot_hash,
use_progress_bar,
maximum_snapshots_to_retain,
maximum_full_snapshot_archives_to_retain,
maximum_incremental_snapshot_archives_to_retain,
&mut Some(Box::new(|download_progress: &DownloadProgressRecord| {
debug!("Download progress: {:?}", download_progress);

Expand Down

0 comments on commit 9e606be

Please sign in to comment.