From 3a56a56d69312a8f97e0b3f150c526f96e844a90 Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" <75863576+jeffwashington@users.noreply.github.com> Date: Mon, 17 May 2021 18:58:36 -0500 Subject: [PATCH] StoredMetaWriteVersion (#17293) --- runtime/src/accounts_db.rs | 15 ++++++++------- runtime/src/append_vec.rs | 4 +++- runtime/src/serde_snapshot.rs | 9 +++++++-- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 0b18684c86..3430776cc7 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -25,7 +25,7 @@ use crate::{ AccountIndexGetResult, AccountSecondaryIndexes, AccountsIndex, AccountsIndexRootsStats, Ancestors, IndexKey, IsCached, SlotList, SlotSlice, ZeroLamport, }, - append_vec::{AppendVec, StoredAccountMeta, StoredMeta}, + append_vec::{AppendVec, StoredAccountMeta, StoredMeta, StoredMetaWriteVersion}, contains::Contains, read_only_accounts_cache::ReadOnlyAccountsCache, }; @@ -90,7 +90,7 @@ const CACHE_VIRTUAL_STORAGE_ID: usize = AppendVecId::MAX; // for entries in the cache, so that operations that take a storage entry can maintain // a common interface when interacting with cached accounts. This version is "virtual" in // that it doesn't actually map to an entry in an AppendVec. -const CACHE_VIRTUAL_WRITE_VERSION: u64 = 0; +const CACHE_VIRTUAL_WRITE_VERSION: StoredMetaWriteVersion = 0; // A specially reserved offset (represents an offset into an AppendVec) // for entries in the cache, so that operations that take a storage entry can maintain @@ -307,7 +307,7 @@ impl<'a> LoadedAccount<'a> { } } - pub fn write_version(&self) -> u64 { + pub fn write_version(&self) -> StoredMetaWriteVersion { match self { LoadedAccount::Stored(stored_account_meta) => stored_account_meta.meta.write_version, LoadedAccount::Cached(_) => CACHE_VIRTUAL_WRITE_VERSION, @@ -3353,9 +3353,9 @@ impl AccountsDb { Hash(<[u8; solana_sdk::hash::HASH_BYTES]>::try_from(hasher.finalize().as_slice()).unwrap()) } - fn bulk_assign_write_version(&self, count: usize) -> u64 { + fn bulk_assign_write_version(&self, count: usize) -> StoredMetaWriteVersion { self.write_version - .fetch_add(count as u64, Ordering::Relaxed) + .fetch_add(count as StoredMetaWriteVersion, Ordering::Relaxed) } fn write_accounts_to_storage Arc>( @@ -4818,7 +4818,7 @@ impl AccountsDb { accounts: &[(&Pubkey, &impl ReadableAccount)], hashes: Option<&[impl Borrow]>, storage_finder: Option>, - write_version_producer: Option>>, + write_version_producer: Option>>, ) -> StoreAccountsTiming { // stores on a frozen slot should not reset // the append vec so that hashing could happen on the store @@ -4956,7 +4956,8 @@ impl AccountsDb { // BTreeMap because we want in-order traversal of oldest write_version to newest. // Thus, all instances of an account in a store are added to the index in oldest to newest // order and we update refcounts and track reclaims correctly. - type AccountsMap<'a> = HashMap)>>; + type AccountsMap<'a> = + HashMap)>>; let mut slots = self.storage.all_slots(); #[allow(clippy::stable_sort_primitive)] slots.sort(); diff --git a/runtime/src/append_vec.rs b/runtime/src/append_vec.rs index f0d7a74e35..ae18f94a5e 100644 --- a/runtime/src/append_vec.rs +++ b/runtime/src/append_vec.rs @@ -32,13 +32,15 @@ macro_rules! u64_align { const MAXIMUM_APPEND_VEC_FILE_SIZE: usize = 16 * 1024 * 1024 * 1024; // 16 GiB +pub type StoredMetaWriteVersion = u64; + /// Meta contains enough context to recover the index from storage itself /// This struct will be backed by mmaped and snapshotted data files. /// So the data layout must be stable and consistent across the entire cluster! #[derive(Clone, PartialEq, Debug)] pub struct StoredMeta { /// global write version - pub write_version: u64, + pub write_version: StoredMetaWriteVersion, /// key for the account pub pubkey: Pubkey, pub data_len: u64, diff --git a/runtime/src/serde_snapshot.rs b/runtime/src/serde_snapshot.rs index 109b3c335b..41044fbb84 100644 --- a/runtime/src/serde_snapshot.rs +++ b/runtime/src/serde_snapshot.rs @@ -3,7 +3,7 @@ use { accounts::Accounts, accounts_db::{AccountStorageEntry, AccountsDb, AppendVecId, BankHashInfo}, accounts_index::{AccountSecondaryIndexes, Ancestors}, - append_vec::AppendVec, + append_vec::{AppendVec, StoredMetaWriteVersion}, bank::{Bank, BankFieldsToDeserialize, BankRc, Builtins}, blockhash_queue::BlockhashQueue, epoch_stakes::EpochStakes, @@ -64,7 +64,12 @@ pub(crate) enum SerdeStyle { const MAX_STREAM_SIZE: u64 = 32 * 1024 * 1024 * 1024; #[derive(Clone, Debug, Default, Deserialize, Serialize, AbiExample)] -struct AccountsDbFields(HashMap>, u64, Slot, BankHashInfo); +struct AccountsDbFields( + HashMap>, + StoredMetaWriteVersion, + Slot, + BankHashInfo, +); trait TypeContext<'a> { type SerializableAccountStorageEntry: Serialize