add --limit_load_slot_count_from_snapshot to ledger-tool (#17417)

This commit is contained in:
Jeff Washington (jwash)
2021-05-26 10:36:12 -05:00
committed by GitHub
parent bb72ab7f1b
commit 6b9d8d41a3
8 changed files with 32 additions and 2 deletions

View File

@ -5123,12 +5123,15 @@ impl AccountsDb {
}
#[allow(clippy::needless_collect)]
pub fn generate_index(&self) {
pub fn generate_index(&self, limit_load_slot_count_from_snapshot: Option<usize>) {
type AccountsMap<'a> =
HashMap<Pubkey, (StoredMetaWriteVersion, AppendVecId, StoredAccountMeta<'a>)>;
let mut slots = self.storage.all_slots();
#[allow(clippy::stable_sort_primitive)]
slots.sort();
if let Some(limit) = limit_load_slot_count_from_snapshot {
slots.truncate(limit); // get rid of the newer slots and keep just the older
}
let total_processed_slots_across_all_threads = AtomicU64::new(0);
let outer_slots_len = slots.len();
let chunk_size = (outer_slots_len / 7) + 1; // approximately 400k slots in a snapshot

View File

@ -135,6 +135,7 @@ pub(crate) fn bank_from_stream<R>(
additional_builtins: Option<&Builtins>,
account_indexes: AccountSecondaryIndexes,
caching_enabled: bool,
limit_load_slot_count_from_snapshot: Option<usize>,
) -> std::result::Result<Bank, Error>
where
R: Read,
@ -154,6 +155,7 @@ where
additional_builtins,
account_indexes,
caching_enabled,
limit_load_slot_count_from_snapshot,
)?;
Ok(bank)
}};
@ -243,6 +245,7 @@ fn reconstruct_bank_from_fields<E>(
additional_builtins: Option<&Builtins>,
account_indexes: AccountSecondaryIndexes,
caching_enabled: bool,
limit_load_slot_count_from_snapshot: Option<usize>,
) -> Result<Bank, Error>
where
E: SerializableStorage,
@ -254,6 +257,7 @@ where
&genesis_config.cluster_type,
account_indexes,
caching_enabled,
limit_load_slot_count_from_snapshot,
)?;
accounts_db.freeze_accounts(
&Ancestors::from(&bank_fields.ancestors),
@ -279,6 +283,7 @@ fn reconstruct_accountsdb_from_fields<E>(
cluster_type: &ClusterType,
account_indexes: AccountSecondaryIndexes,
caching_enabled: bool,
limit_load_slot_count_from_snapshot: Option<usize>,
) -> Result<AccountsDb, Error>
where
E: SerializableStorage,
@ -371,6 +376,6 @@ where
accounts_db
.write_version
.fetch_add(version, Ordering::Relaxed);
accounts_db.generate_index();
accounts_db.generate_index(limit_load_slot_count_from_snapshot);
Ok(accounts_db)
}

View File

@ -73,6 +73,7 @@ where
&ClusterType::Development,
AccountSecondaryIndexes::default(),
false,
None,
)
}
@ -226,6 +227,7 @@ fn test_bank_serialize_style(serde_style: SerdeStyle) {
None,
AccountSecondaryIndexes::default(),
false,
None,
)
.unwrap();
dbank.src = ref_sc;

View File

@ -603,6 +603,7 @@ pub fn bank_from_archive<P: AsRef<Path>>(
additional_builtins: Option<&Builtins>,
account_indexes: AccountSecondaryIndexes,
accounts_db_caching_enabled: bool,
limit_load_slot_count_from_snapshot: Option<usize>,
) -> Result<Bank> {
let unpack_dir = tempfile::Builder::new()
.prefix(TMP_SNAPSHOT_PREFIX)
@ -633,6 +634,7 @@ pub fn bank_from_archive<P: AsRef<Path>>(
additional_builtins,
account_indexes,
accounts_db_caching_enabled,
limit_load_slot_count_from_snapshot,
)?;
if !bank.verify_snapshot_bank() {
@ -791,6 +793,7 @@ fn rebuild_bank_from_snapshots(
additional_builtins: Option<&Builtins>,
account_indexes: AccountSecondaryIndexes,
accounts_db_caching_enabled: bool,
limit_load_slot_count_from_snapshot: Option<usize>,
) -> Result<Bank> {
info!("snapshot version: {}", snapshot_version);
@ -826,6 +829,7 @@ fn rebuild_bank_from_snapshots(
additional_builtins,
account_indexes,
accounts_db_caching_enabled,
limit_load_slot_count_from_snapshot,
),
}?)
})?;