Do not delete ALL other snapshots before downloading a new snapshot
This commit is contained in:
parent
8082a2454c
commit
93ae177503
|
@ -168,23 +168,8 @@ pub fn download_snapshot(
|
|||
desired_snapshot_hash: (Slot, Hash),
|
||||
use_progress_bar: bool,
|
||||
) -> Result<(), String> {
|
||||
// Remove all snapshot not matching the desired hash
|
||||
let snapshot_packages = snapshot_utils::get_snapshot_archives(ledger_path);
|
||||
let mut found_package = false;
|
||||
for (snapshot_package, (snapshot_slot, snapshot_hash, _compression)) in snapshot_packages.iter()
|
||||
{
|
||||
if (*snapshot_slot, *snapshot_hash) != desired_snapshot_hash {
|
||||
info!("Removing old snapshot: {:?}", snapshot_package);
|
||||
fs::remove_file(snapshot_package)
|
||||
.unwrap_or_else(|err| info!("Failed to remove old snapshot: {:}", err));
|
||||
} else {
|
||||
found_package = true;
|
||||
}
|
||||
}
|
||||
snapshot_utils::purge_old_snapshot_archives(ledger_path);
|
||||
|
||||
if found_package {
|
||||
Ok(())
|
||||
} else {
|
||||
for compression in &[
|
||||
CompressionType::Zstd,
|
||||
CompressionType::Gzip,
|
||||
|
@ -196,6 +181,10 @@ pub fn download_snapshot(
|
|||
compression,
|
||||
);
|
||||
|
||||
if desired_snapshot_package.is_file() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if download_file(
|
||||
&format!(
|
||||
"http://{}/{}",
|
||||
|
@ -216,4 +205,3 @@ pub fn download_snapshot(
|
|||
}
|
||||
Err("Snapshot couldn't be downloaded".to_string())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -363,14 +363,7 @@ pub fn archive_snapshot_package(snapshot_package: &AccountsPackage) -> Result<()
|
|||
let metadata = fs::metadata(&archive_path)?;
|
||||
fs::rename(&archive_path, &snapshot_package.tar_output_file)?;
|
||||
|
||||
// Keep around at most three snapshot archives
|
||||
let mut archives = get_snapshot_archives(snapshot_package.tar_output_file.parent().unwrap());
|
||||
// Keep the oldest snapshot so we can always play the ledger from it.
|
||||
archives.pop();
|
||||
for old_archive in archives.into_iter().skip(2) {
|
||||
fs::remove_file(old_archive.0)
|
||||
.unwrap_or_else(|err| info!("Failed to remove old snapshot: {:}", err));
|
||||
}
|
||||
purge_old_snapshot_archives(snapshot_package.tar_output_file.parent().unwrap());
|
||||
|
||||
timer.stop();
|
||||
info!(
|
||||
|
@ -746,6 +739,16 @@ pub fn get_highest_snapshot_archive_path<P: AsRef<Path>>(
|
|||
archives.into_iter().next()
|
||||
}
|
||||
|
||||
pub fn purge_old_snapshot_archives<P: AsRef<Path>>(snapshot_output_dir: P) {
|
||||
let mut archives = get_snapshot_archives(snapshot_output_dir);
|
||||
// Keep the oldest snapshot so we can always play the ledger from it.
|
||||
archives.pop();
|
||||
for old_archive in archives.into_iter().skip(2) {
|
||||
fs::remove_file(old_archive.0)
|
||||
.unwrap_or_else(|err| info!("Failed to remove old snapshot: {:}", err));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn untar_snapshot_in<P: AsRef<Path>, Q: AsRef<Path>>(
|
||||
snapshot_tar: P,
|
||||
unpack_dir: Q,
|
||||
|
|
Loading…
Reference in New Issue