Adapt local-cluster/

This commit is contained in:
Michael Vines
2020-02-26 19:04:18 -07:00
parent fcabc6f799
commit 0d4cb252c4
6 changed files with 102 additions and 87 deletions

View File

@@ -10,7 +10,7 @@ use solana_sdk::{clock::Slot, timing};
use std::{
collections::{HashMap, HashSet},
ops::Index,
path::{Path, PathBuf},
path::PathBuf,
sync::Arc,
time::Instant,
};
@@ -192,10 +192,6 @@ impl BankForks {
root,
&root_bank.src.roots(),
snapshot_package_sender.as_ref().unwrap(),
snapshot_utils::get_snapshot_archive_path(
&config.snapshot_package_output_path,
&(root_bank.slot(), root_bank.hash()),
),
);
if r.is_err() {
warn!("Error generating snapshot for bank: {}, err: {:?}", root, r);
@@ -239,12 +235,11 @@ impl BankForks {
}
}
pub fn generate_snapshot<P: AsRef<Path>>(
pub fn generate_snapshot(
&self,
root: Slot,
slots_to_snapshot: &[Slot],
snapshot_package_sender: &SnapshotPackageSender,
tar_output_file: P,
) -> Result<()> {
let config = self.snapshot_config.as_ref().unwrap();
@@ -270,9 +265,9 @@ impl BankForks {
let package = snapshot_utils::package_snapshot(
&bank,
latest_slot_snapshot_paths,
tar_output_file,
&config.snapshot_path,
slots_to_snapshot,
&config.snapshot_package_output_path,
storages,
)?;

View File

@@ -10,7 +10,7 @@ use crate::{
};
use log::*;
use solana_sdk::{clock::Slot, genesis_config::GenesisConfig, hash::Hash};
use std::{fs, path::PathBuf, result, sync::Arc};
use std::{fs, path::PathBuf, process, result, sync::Arc};
pub type LoadResult = result::Result<
(
@@ -55,39 +55,45 @@ pub fn load(
match snapshot_utils::get_highest_snapshot_archive_path(
&snapshot_config.snapshot_package_output_path,
) {
Some(tar) => {
if tar.exists() {
info!("Loading snapshot package: {:?}", tar);
// Fail hard here if snapshot fails to load, don't silently continue
Some((archive_filename, archive_snapshot_hash)) => {
info!("Loading snapshot package: {:?}", archive_filename);
// Fail hard here if snapshot fails to load, don't silently continue
if account_paths.is_empty() {
panic!("Account paths not present when booting from snapshot")
}
let deserialized_bank = snapshot_utils::bank_from_archive(
&account_paths,
&snapshot_config.snapshot_path,
&tar,
)
.expect("Load from snapshot failed");
let snapshot_hash = (
deserialized_bank.slot(),
deserialized_bank.get_accounts_hash(),
);
return to_loadresult(
blockstore_processor::process_blockstore_from_root(
genesis_config,
blockstore,
Arc::new(deserialized_bank),
&process_options,
&VerifyRecyclers::default(),
),
Some(snapshot_hash),
);
} else {
info!("Snapshot package does not exist: {:?}", tar);
if account_paths.is_empty() {
error!("Account paths not present when booting from snapshot");
process::exit(1);
}
let deserialized_bank = snapshot_utils::bank_from_archive(
&account_paths,
&snapshot_config.snapshot_path,
&archive_filename,
)
.expect("Load from snapshot failed");
let deserialized_snapshot_hash = (
deserialized_bank.slot(),
deserialized_bank.get_accounts_hash(),
);
if deserialized_snapshot_hash != archive_snapshot_hash {
error!(
"Snapshot has mismatch:\narchive: {:?}\ndeserialized: {:?}",
archive_snapshot_hash, deserialized_snapshot_hash
);
process::exit(1);
}
return to_loadresult(
blockstore_processor::process_blockstore_from_root(
genesis_config,
blockstore,
Arc::new(deserialized_bank),
&process_options,
&VerifyRecyclers::default(),
),
Some(deserialized_snapshot_hash),
);
}
None => info!("No snapshot package available"),
}

View File

@@ -82,9 +82,9 @@ impl SlotSnapshotPaths {
pub fn package_snapshot<P: AsRef<Path>, Q: AsRef<Path>>(
bank: &Bank,
snapshot_files: &SlotSnapshotPaths,
snapshot_package_output_file: P,
snapshot_path: Q,
slots_to_snapshot: &[Slot],
snapshot_package_output_path: P,
snapshot_storages: SnapshotStorages,
) -> Result<SnapshotPackage> {
// Hard link all the snapshots we need for this package
@@ -101,12 +101,17 @@ pub fn package_snapshot<P: AsRef<Path>, Q: AsRef<Path>>(
// any temporary state created for the SnapshotPackage (like the snapshot_hard_links_dir)
snapshot_files.copy_snapshot_directory(snapshot_hard_links_dir.path())?;
let snapshot_package_output_file = get_snapshot_archive_path(
&snapshot_package_output_path,
&(bank.slot(), bank.get_accounts_hash()),
);
let package = SnapshotPackage::new(
bank.slot(),
bank.src.slot_deltas(slots_to_snapshot),
snapshot_hard_links_dir,
snapshot_storages,
snapshot_package_output_file.as_ref().to_path_buf(),
snapshot_package_output_file,
bank.get_accounts_hash(),
);
@@ -555,9 +560,9 @@ fn get_snapshot_archives<P: AsRef<Path>>(snapshot_output_dir: P) -> Vec<(PathBuf
pub fn get_highest_snapshot_archive_path<P: AsRef<Path>>(
snapshot_output_dir: P,
) -> Option<PathBuf> {
) -> Option<(PathBuf, (Slot, Hash))> {
let archives = get_snapshot_archives(snapshot_output_dir);
archives.into_iter().next().map(|archive| archive.0)
archives.into_iter().next()
}
pub fn untar_snapshot_in<P: AsRef<Path>, Q: AsRef<Path>>(