refactor reconstruct_accountsdb_from_fields (#17987)

This commit is contained in:
Jeff Washington (jwash) 2021-06-21 10:47:58 -05:00 committed by GitHub
parent e7a7d0d55f
commit ae82e4e25b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 11 deletions

View File

@ -35,7 +35,7 @@ use {
std::{ std::{
collections::{HashMap, HashSet}, collections::{HashMap, HashSet},
io::{self, BufReader, BufWriter, Read, Write}, io::{self, BufReader, BufWriter, Read, Write},
path::PathBuf, path::{Path, PathBuf},
result::Result, result::Result,
sync::{atomic::Ordering, Arc, RwLock}, sync::{atomic::Ordering, Arc, RwLock},
}, },
@ -287,6 +287,24 @@ where
Ok(bank) Ok(bank)
} }
fn reconstruct_single_storage<E>(
slot: &Slot,
append_vec_path: &Path,
storage_entry: &E,
new_slot_storage: &mut HashMap<AppendVecId, Arc<AccountStorageEntry>>,
) -> Result<(), Error>
where
E: SerializableStorage,
{
let (accounts, num_accounts) =
AppendVec::new_from_file(append_vec_path, storage_entry.current_len())?;
let u_storage_entry =
AccountStorageEntry::new_existing(*slot, storage_entry.id(), accounts, num_accounts);
new_slot_storage.insert(storage_entry.id(), Arc::new(u_storage_entry));
Ok(())
}
fn reconstruct_accountsdb_from_fields<E>( fn reconstruct_accountsdb_from_fields<E>(
accounts_db_fields: AccountsDbFields<E>, accounts_db_fields: AccountsDbFields<E>,
account_paths: &[PathBuf], account_paths: &[PathBuf],
@ -333,16 +351,12 @@ where
) )
})?; })?;
let (accounts, num_accounts) = reconstruct_single_storage(
AppendVec::new_from_file(append_vec_path, storage_entry.current_len())?; &slot,
let u_storage_entry = AccountStorageEntry::new_existing( append_vec_path,
*slot, storage_entry,
storage_entry.id(), &mut new_slot_storage,
accounts, )?;
num_accounts,
);
new_slot_storage.insert(storage_entry.id(), Arc::new(u_storage_entry));
} }
Ok((*slot, new_slot_storage)) Ok((*slot, new_slot_storage))
}) })