move hash calculation out of acct bg svc (#23689)

* move hash calculation out of acct bg svc

* pr feedback
This commit is contained in:
Jeff Washington (jwash)
2022-04-08 10:42:03 -05:00
committed by GitHub
parent cb1507126f
commit 210f6a6fab
6 changed files with 82 additions and 66 deletions

View File

@@ -4,6 +4,7 @@
use {
crate::{
accounts_hash::CalcAccountsHashConfig,
bank::{Bank, BankSlotDelta, DropCallback},
bank_forks::BankForks,
snapshot_config::SnapshotConfig,
@@ -109,7 +110,7 @@ impl SnapshotRequestHandler {
let previous_hash = if test_hash_calculation {
// We have to use the index version here.
// We cannot calculate the non-index way because cache has not been flushed and stores don't match reality.
// We cannot calculate the non-index way because cache has not been flushed and stores don't match reality. This comment is out of date and can be re-evaluated.
snapshot_root_bank.update_accounts_hash_with_index_option(true, false, false)
} else {
Hash::default()
@@ -144,20 +145,27 @@ impl SnapshotRequestHandler {
}
flush_accounts_cache_time.stop();
let use_index_hash_calculation = false;
let mut hash_time = Measure::start("hash_time");
let this_hash = snapshot_root_bank.update_accounts_hash_with_index_option(
use_index_hash_calculation,
test_hash_calculation,
false,
);
let hash_for_testing = if test_hash_calculation {
let use_index_hash_calculation = false;
let check_hash = false;
let (this_hash, _cap) = snapshot_root_bank.accounts().accounts_db.calculate_accounts_hash_helper(
use_index_hash_calculation,
snapshot_root_bank.slot(),
&CalcAccountsHashConfig {
use_bg_thread_pool: true,
check_hash,
ancestors: None,
use_write_cache: false,
epoch_schedule: snapshot_root_bank.epoch_schedule(),
rent_collector: &snapshot_root_bank.rent_collector(),
},
).unwrap();
assert_eq!(previous_hash, this_hash);
Some(snapshot_root_bank.get_accounts_hash())
Some(this_hash)
} else {
None
};
hash_time.stop();
let mut clean_time = Measure::start("clean_time");
// Don't clean the slot we're snapshotting because it may have zero-lamport
@@ -234,7 +242,6 @@ impl SnapshotRequestHandler {
datapoint_info!(
"handle_snapshot_requests-timing",
("hash_time", hash_time.as_us(), i64),
(
"flush_accounts_cache_time",
flush_accounts_cache_time.as_us(),

View File

@@ -5505,7 +5505,7 @@ impl AccountsDb {
}
}
fn calculate_accounts_hash_helper(
pub(crate) fn calculate_accounts_hash_helper(
&self,
use_index: bool,
slot: Slot,

View File

@@ -37,7 +37,6 @@ pub struct AccountsPackage {
pub slot_deltas: Vec<BankSlotDelta>,
pub snapshot_links: TempDir,
pub snapshot_storages: SnapshotStorages,
pub accounts_hash: Hash, // temporarily here while we still have to calculate hash before serializing bank
pub archive_format: ArchiveFormat,
pub snapshot_version: SnapshotVersion,
pub snapshot_archives_dir: PathBuf,
@@ -104,7 +103,6 @@ impl AccountsPackage {
slot_deltas,
snapshot_links,
snapshot_storages,
accounts_hash: bank.get_accounts_hash(),
archive_format,
snapshot_version,
snapshot_archives_dir: snapshot_archives_dir.as_ref().to_path_buf(),
@@ -129,8 +127,8 @@ pub struct SnapshotPackage {
pub snapshot_type: SnapshotType,
}
impl From<AccountsPackage> for SnapshotPackage {
fn from(accounts_package: AccountsPackage) -> Self {
impl SnapshotPackage {
pub fn new(accounts_package: AccountsPackage, accounts_hash: Hash) -> Self {
assert!(
accounts_package.snapshot_type.is_some(),
"Cannot make a SnapshotPackage from an AccountsPackage when SnapshotType is None!"
@@ -141,7 +139,7 @@ impl From<AccountsPackage> for SnapshotPackage {
SnapshotType::FullSnapshot => snapshot_utils::build_full_snapshot_archive_path(
accounts_package.snapshot_archives_dir,
accounts_package.slot,
&accounts_package.accounts_hash,
&accounts_hash,
accounts_package.archive_format,
),
SnapshotType::IncrementalSnapshot(incremental_snapshot_base_slot) => {
@@ -161,7 +159,7 @@ impl From<AccountsPackage> for SnapshotPackage {
accounts_package.snapshot_archives_dir,
incremental_snapshot_base_slot,
accounts_package.slot,
&accounts_package.accounts_hash,
&accounts_hash,
accounts_package.archive_format,
)
}
@@ -171,7 +169,7 @@ impl From<AccountsPackage> for SnapshotPackage {
snapshot_archive_info: SnapshotArchiveInfo {
path: snapshot_archive_path,
slot: accounts_package.slot,
hash: accounts_package.accounts_hash,
hash: accounts_hash,
archive_format: accounts_package.archive_format,
},
block_height: accounts_package.block_height,

View File

@@ -1924,7 +1924,7 @@ pub fn package_and_archive_full_snapshot(
&bank.get_accounts_hash(),
);
let snapshot_package = SnapshotPackage::from(accounts_package);
let snapshot_package = SnapshotPackage::new(accounts_package, bank.get_accounts_hash());
archive_snapshot_package(
&snapshot_package,
maximum_full_snapshot_archives_to_retain,
@@ -1971,7 +1971,7 @@ pub fn package_and_archive_incremental_snapshot(
&bank.get_accounts_hash(),
);
let snapshot_package = SnapshotPackage::from(accounts_package);
let snapshot_package = SnapshotPackage::new(accounts_package, bank.get_accounts_hash());
archive_snapshot_package(
&snapshot_package,
maximum_full_snapshot_archives_to_retain,
@@ -3443,7 +3443,6 @@ mod tests {
slot_deltas: Vec::default(),
snapshot_links: TempDir::new().unwrap(),
snapshot_storages: SnapshotStorages::default(),
accounts_hash: Hash::default(),
archive_format: ArchiveFormat::Tar,
snapshot_version: SnapshotVersion::default(),
snapshot_archives_dir: PathBuf::default(),