From 4c0373b72a06999eaa640710dff38525e205037f Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" Date: Sat, 11 Dec 2021 21:34:35 -0600 Subject: [PATCH] introduce AtomicAppendVecId (#21793) --- runtime/src/accounts_db.rs | 13 +++++++------ runtime/src/serde_snapshot.rs | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 9f0735fc5b..2e80422603 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -114,7 +114,7 @@ const MAX_ITEMS_PER_CHUNK: Slot = 2_500; // operations that take a storage entry can maintain a common interface // when interacting with cached accounts. This id is "virtual" in that it // doesn't actually refer to an actual storage entry. -const CACHE_VIRTUAL_STORAGE_ID: usize = AppendVecId::MAX; +const CACHE_VIRTUAL_STORAGE_ID: AppendVecId = AppendVecId::MAX; // A specially reserved write version (identifier for ordering writes in an AppendVec) // for entries in the cache, so that operations that take a storage entry can maintain @@ -365,6 +365,7 @@ impl<'a> MultiThreadProgress<'a> { } /// An offset into the AccountsDb::storage vector +pub type AtomicAppendVecId = AtomicUsize; pub type AppendVecId = usize; pub type SnapshotStorage = Vec>; pub type SnapshotStorages = Vec; @@ -627,7 +628,7 @@ struct CleanKeyTimings { /// Persistent storage structure holding the accounts #[derive(Debug)] pub struct AccountStorageEntry { - pub(crate) id: AtomicUsize, + pub(crate) id: AtomicAppendVecId, pub(crate) slot: AtomicU64, @@ -659,7 +660,7 @@ impl AccountStorageEntry { let accounts = AppendVec::new(&path, true, file_size as usize); Self { - id: AtomicUsize::new(id), + id: AtomicAppendVecId::new(id), slot: AtomicU64::new(slot), accounts, count_and_status: RwLock::new((0, AccountStorageStatus::Available)), @@ -675,7 +676,7 @@ impl AccountStorageEntry { num_accounts: usize, ) -> Self { Self { - id: AtomicUsize::new(id), + id: AtomicAppendVecId::new(id), slot: AtomicU64::new(slot), accounts, count_and_status: RwLock::new((0, AccountStorageStatus::Available)), @@ -979,7 +980,7 @@ pub struct AccountsDb { recycle_stores: RwLock, /// distribute the accounts across storage lists - pub next_id: AtomicUsize, + pub next_id: AtomicAppendVecId, /// Set of shrinkable stores organized by map of slot to append_vec_id pub shrink_candidate_slots: Mutex, @@ -1570,7 +1571,7 @@ impl AccountsDb { read_only_accounts_cache: ReadOnlyAccountsCache::new(MAX_READ_ONLY_CACHE_DATA_SIZE), recycle_stores: RwLock::new(RecycleStores::default()), uncleaned_pubkeys: DashMap::new(), - next_id: AtomicUsize::new(0), + next_id: AtomicAppendVecId::new(0), shrink_candidate_slots_v1: Mutex::new(Vec::new()), shrink_candidate_slots: Mutex::new(HashMap::new()), write_cache_limit_bytes: None, diff --git a/runtime/src/serde_snapshot.rs b/runtime/src/serde_snapshot.rs index adf59e00a6..e5423c07a9 100644 --- a/runtime/src/serde_snapshot.rs +++ b/runtime/src/serde_snapshot.rs @@ -5,7 +5,7 @@ use { accounts::Accounts, accounts_db::{ AccountShrinkThreshold, AccountStorageEntry, AccountsDb, AccountsDbConfig, AppendVecId, - BankHashInfo, IndexGenerationInfo, + AtomicAppendVecId, BankHashInfo, IndexGenerationInfo, }, accounts_index::AccountSecondaryIndexes, accounts_update_notifier_interface::AccountsUpdateNotifier, @@ -437,7 +437,7 @@ where // Remap the deserialized AppendVec paths to point to correct local paths let num_collisions = AtomicUsize::new(0); - let next_append_vec_id = AtomicUsize::new(0); + let next_append_vec_id = AtomicAppendVecId::new(0); let mut measure_remap = Measure::start("remap"); let mut storage = (0..snapshot_storages.len()) .into_par_iter()