Unpack snapshot AppendVecs directly into account paths

This commit is contained in:
Michael Vines
2021-03-10 09:49:10 -08:00
parent c078e01fa9
commit 1061d021c9
8 changed files with 210 additions and 167 deletions

View File

@@ -7,6 +7,7 @@ use {
bank::{Bank, BankFieldsToDeserialize, BankRc, Builtins},
blockhash_queue::BlockhashQueue,
epoch_stakes::EpochStakes,
hardened_unpack::UnpackedAppendVecMap,
message_processor::MessageProcessor,
rent_collector::RentCollector,
serde_snapshot::future::SerializableStorage,
@@ -14,9 +15,7 @@ use {
},
bincode,
bincode::{config::Options, Error},
fs_extra::dir::CopyOptions,
log::{info, warn},
rand::{thread_rng, Rng},
log::*,
serde::{de::DeserializeOwned, Deserialize, Serialize},
solana_sdk::{
clock::{Epoch, Slot, UnixTimestamp},
@@ -31,8 +30,8 @@ use {
},
std::{
collections::{HashMap, HashSet},
io::{BufReader, BufWriter, Read, Write},
path::{Path, PathBuf},
io::{self, BufReader, BufWriter, Read, Write},
path::PathBuf,
result::Result,
sync::{atomic::Ordering, Arc, RwLock},
time::Instant,
@@ -119,11 +118,11 @@ where
}
#[allow(clippy::too_many_arguments)]
pub(crate) fn bank_from_stream<R, P>(
pub(crate) fn bank_from_stream<R>(
serde_style: SerdeStyle,
stream: &mut BufReader<R>,
append_vecs_path: P,
account_paths: &[PathBuf],
unpacked_append_vec_map: UnpackedAppendVecMap,
genesis_config: &GenesisConfig,
frozen_account_pubkeys: &[Pubkey],
debug_keys: Option<Arc<HashSet<Pubkey>>>,
@@ -133,7 +132,6 @@ pub(crate) fn bank_from_stream<R, P>(
) -> std::result::Result<Bank, Error>
where
R: Read,
P: AsRef<Path>,
{
macro_rules! INTO {
($x:ident) => {{
@@ -145,7 +143,7 @@ where
genesis_config,
frozen_account_pubkeys,
account_paths,
append_vecs_path,
unpacked_append_vec_map,
debug_keys,
additional_builtins,
account_indexes,
@@ -228,13 +226,13 @@ impl<'a, C: TypeContext<'a>> Serialize for SerializableAccountsDb<'a, C> {
impl<'a, C> IgnoreAsHelper for SerializableAccountsDb<'a, C> {}
#[allow(clippy::too_many_arguments)]
fn reconstruct_bank_from_fields<E, P>(
fn reconstruct_bank_from_fields<E>(
bank_fields: BankFieldsToDeserialize,
accounts_db_fields: AccountsDbFields<E>,
genesis_config: &GenesisConfig,
frozen_account_pubkeys: &[Pubkey],
account_paths: &[PathBuf],
append_vecs_path: P,
unpacked_append_vec_map: UnpackedAppendVecMap,
debug_keys: Option<Arc<HashSet<Pubkey>>>,
additional_builtins: Option<&Builtins>,
account_indexes: HashSet<AccountIndex>,
@@ -242,12 +240,11 @@ fn reconstruct_bank_from_fields<E, P>(
) -> Result<Bank, Error>
where
E: SerializableStorage,
P: AsRef<Path>,
{
let mut accounts_db = reconstruct_accountsdb_from_fields(
accounts_db_fields,
account_paths,
append_vecs_path,
unpacked_append_vec_map,
&genesis_config.cluster_type,
account_indexes,
caching_enabled,
@@ -266,17 +263,16 @@ where
Ok(bank)
}
fn reconstruct_accountsdb_from_fields<E, P>(
fn reconstruct_accountsdb_from_fields<E>(
accounts_db_fields: AccountsDbFields<E>,
account_paths: &[PathBuf],
stream_append_vecs_path: P,
unpacked_append_vec_map: UnpackedAppendVecMap,
cluster_type: &ClusterType,
account_indexes: HashSet<AccountIndex>,
caching_enabled: bool,
) -> Result<AccountsDb, Error>
where
E: SerializableStorage,
P: AsRef<Path>,
{
let mut accounts_db = AccountsDb::new_with_config(
account_paths.to_vec(),
@@ -308,29 +304,17 @@ where
let mut new_slot_storage = HashMap::new();
for storage_entry in slot_storage.drain(..) {
let path_index = thread_rng().gen_range(0, accounts_db.paths.len());
let local_dir = &accounts_db.paths[path_index];
let file_name = AppendVec::file_name(slot, storage_entry.id());
// Move the corresponding AppendVec from the snapshot into the directory pointed
// at by `local_dir`
let append_vec_relative_path = AppendVec::file_name(slot, storage_entry.id());
let append_vec_abs_path = stream_append_vecs_path
.as_ref()
.join(&append_vec_relative_path);
let target = local_dir.join(append_vec_abs_path.file_name().unwrap());
std::fs::rename(append_vec_abs_path.clone(), target).or_else(|_| {
let mut copy_options = CopyOptions::new();
copy_options.overwrite = true;
fs_extra::move_items(&[&append_vec_abs_path], &local_dir, &copy_options)
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))
.and(Ok(()))
let append_vec_path = unpacked_append_vec_map.get(&file_name).ok_or_else(|| {
io::Error::new(
io::ErrorKind::NotFound,
format!("{} not found in unpacked append vecs", file_name),
)
})?;
// Notify the AppendVec of the new file location
let local_path = local_dir.join(append_vec_relative_path);
let (accounts, num_accounts) =
AppendVec::new_from_file(&local_path, storage_entry.current_len())?;
AppendVec::new_from_file(append_vec_path, storage_entry.current_len())?;
let u_storage_entry = AccountStorageEntry::new_existing(
slot,
storage_entry.id(),