AcctInfo: create AcctInfo with cache explicitly (#21847)
This commit is contained in:
parent
b81124deec
commit
50f26ea9c0
@ -1,4 +1,16 @@
|
|||||||
use crate::{accounts_db::AppendVecId, accounts_index::ZeroLamport};
|
use crate::{
|
||||||
|
accounts_db::{AppendVecId, CACHE_VIRTUAL_OFFSET, CACHE_VIRTUAL_STORAGE_ID},
|
||||||
|
accounts_index::{IsCached, ZeroLamport},
|
||||||
|
};
|
||||||
|
|
||||||
|
/// offset within an append vec to account data
|
||||||
|
pub type Offset = usize;
|
||||||
|
|
||||||
|
/// specify where account data is located
|
||||||
|
pub enum StorageLocation {
|
||||||
|
AppendVec(AppendVecId, Offset),
|
||||||
|
Cached,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug, PartialEq, Clone, Copy)]
|
#[derive(Default, Debug, PartialEq, Clone, Copy)]
|
||||||
pub struct AccountInfo {
|
pub struct AccountInfo {
|
||||||
@ -6,7 +18,7 @@ pub struct AccountInfo {
|
|||||||
pub store_id: AppendVecId,
|
pub store_id: AppendVecId,
|
||||||
|
|
||||||
/// offset into the storage
|
/// offset into the storage
|
||||||
offset: usize,
|
offset: Offset,
|
||||||
|
|
||||||
/// needed to track shrink candidacy in bytes. Used to update the number
|
/// needed to track shrink candidacy in bytes. Used to update the number
|
||||||
/// of alive bytes in an AppendVec as newer slots purge outdated entries
|
/// of alive bytes in an AppendVec as newer slots purge outdated entries
|
||||||
@ -23,8 +35,18 @@ impl ZeroLamport for AccountInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl IsCached for AccountInfo {
|
||||||
|
fn is_cached(&self) -> bool {
|
||||||
|
self.store_id == CACHE_VIRTUAL_STORAGE_ID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl AccountInfo {
|
impl AccountInfo {
|
||||||
pub fn new(store_id: AppendVecId, offset: usize, stored_size: usize, lamports: u64) -> Self {
|
pub fn new(storage_location: StorageLocation, stored_size: usize, lamports: u64) -> Self {
|
||||||
|
let (store_id, offset) = match storage_location {
|
||||||
|
StorageLocation::AppendVec(store_id, offset) => (store_id, offset),
|
||||||
|
StorageLocation::Cached => (CACHE_VIRTUAL_STORAGE_ID, CACHE_VIRTUAL_OFFSET),
|
||||||
|
};
|
||||||
Self {
|
Self {
|
||||||
store_id,
|
store_id,
|
||||||
offset,
|
offset,
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
use std::{thread::sleep, time::Duration};
|
use std::{thread::sleep, time::Duration};
|
||||||
use {
|
use {
|
||||||
crate::{
|
crate::{
|
||||||
account_info::AccountInfo,
|
account_info::{AccountInfo, StorageLocation},
|
||||||
accounts_background_service::{DroppedSlotsSender, SendDroppedBankCallback},
|
accounts_background_service::{DroppedSlotsSender, SendDroppedBankCallback},
|
||||||
accounts_cache::{AccountsCache, CachedAccount, SlotCache},
|
accounts_cache::{AccountsCache, CachedAccount, SlotCache},
|
||||||
accounts_hash::{AccountsHash, CalculateHashIntermediate, HashStats, PreviousPass},
|
accounts_hash::{AccountsHash, CalculateHashIntermediate, HashStats, PreviousPass},
|
||||||
@ -114,7 +114,7 @@ const MAX_ITEMS_PER_CHUNK: Slot = 2_500;
|
|||||||
// operations that take a storage entry can maintain a common interface
|
// operations that take a storage entry can maintain a common interface
|
||||||
// when interacting with cached accounts. This id is "virtual" in that it
|
// when interacting with cached accounts. This id is "virtual" in that it
|
||||||
// doesn't actually refer to an actual storage entry.
|
// doesn't actually refer to an actual storage entry.
|
||||||
const CACHE_VIRTUAL_STORAGE_ID: AppendVecId = AppendVecId::MAX;
|
pub(crate) const CACHE_VIRTUAL_STORAGE_ID: AppendVecId = AppendVecId::MAX;
|
||||||
|
|
||||||
// A specially reserved write version (identifier for ordering writes in an AppendVec)
|
// 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
|
// for entries in the cache, so that operations that take a storage entry can maintain
|
||||||
@ -126,7 +126,7 @@ const CACHE_VIRTUAL_WRITE_VERSION: StoredMetaWriteVersion = 0;
|
|||||||
// for entries in the cache, so that operations that take a storage entry can maintain
|
// 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
|
// 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.
|
// that it doesn't actually map to an entry in an AppendVec.
|
||||||
const CACHE_VIRTUAL_OFFSET: usize = 0;
|
pub(crate) const CACHE_VIRTUAL_OFFSET: usize = 0;
|
||||||
const CACHE_VIRTUAL_STORED_SIZE: usize = 0;
|
const CACHE_VIRTUAL_STORED_SIZE: usize = 0;
|
||||||
|
|
||||||
pub const ACCOUNTS_DB_CONFIG_FOR_TESTING: AccountsDbConfig = AccountsDbConfig {
|
pub const ACCOUNTS_DB_CONFIG_FOR_TESTING: AccountsDbConfig = AccountsDbConfig {
|
||||||
@ -304,12 +304,6 @@ impl GenerateIndexTimings {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IsCached for AccountInfo {
|
|
||||||
fn is_cached(&self) -> bool {
|
|
||||||
self.store_id == CACHE_VIRTUAL_STORAGE_ID
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IndexValue for AccountInfo {}
|
impl IndexValue for AccountInfo {}
|
||||||
|
|
||||||
impl ZeroLamport for AccountSharedData {
|
impl ZeroLamport for AccountSharedData {
|
||||||
@ -4476,8 +4470,7 @@ impl AccountsDb {
|
|||||||
storage.add_account(stored_size);
|
storage.add_account(stored_size);
|
||||||
|
|
||||||
infos.push(AccountInfo::new(
|
infos.push(AccountInfo::new(
|
||||||
storage.append_vec_id(),
|
StorageLocation::AppendVec(storage.append_vec_id(), offsets[0]),
|
||||||
offsets[0],
|
|
||||||
stored_size,
|
stored_size,
|
||||||
account
|
account
|
||||||
.map(|account| account.lamports())
|
.map(|account| account.lamports())
|
||||||
@ -4895,8 +4888,7 @@ impl AccountsDb {
|
|||||||
.map(|account| account.to_account_shared_data())
|
.map(|account| account.to_account_shared_data())
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
let account_info = AccountInfo::new(
|
let account_info = AccountInfo::new(
|
||||||
CACHE_VIRTUAL_STORAGE_ID,
|
StorageLocation::Cached,
|
||||||
CACHE_VIRTUAL_OFFSET,
|
|
||||||
CACHE_VIRTUAL_STORED_SIZE,
|
CACHE_VIRTUAL_STORED_SIZE,
|
||||||
account.lamports(),
|
account.lamports(),
|
||||||
);
|
);
|
||||||
@ -6013,7 +6005,7 @@ impl AccountsDb {
|
|||||||
let mut measure = Measure::start("remove");
|
let mut measure = Measure::start("remove");
|
||||||
for (slot, account_info) in reclaims {
|
for (slot, account_info) in reclaims {
|
||||||
// No cached accounts should make it here
|
// No cached accounts should make it here
|
||||||
assert_ne!(account_info.store_id, CACHE_VIRTUAL_STORAGE_ID);
|
assert!(!account_info.is_cached());
|
||||||
if let Some(ref mut reclaimed_offsets) = reclaimed_offsets {
|
if let Some(ref mut reclaimed_offsets) = reclaimed_offsets {
|
||||||
reclaimed_offsets
|
reclaimed_offsets
|
||||||
.entry(account_info.store_id)
|
.entry(account_info.store_id)
|
||||||
@ -6716,8 +6708,7 @@ impl AccountsDb {
|
|||||||
(
|
(
|
||||||
pubkey,
|
pubkey,
|
||||||
AccountInfo::new(
|
AccountInfo::new(
|
||||||
store_id,
|
StorageLocation::AppendVec(store_id, stored_account.offset), // will never be cached
|
||||||
stored_account.offset,
|
|
||||||
stored_account.stored_size,
|
stored_account.stored_size,
|
||||||
stored_account.account_meta.lamports,
|
stored_account.account_meta.lamports,
|
||||||
),
|
),
|
||||||
@ -6967,8 +6958,10 @@ impl AccountsDb {
|
|||||||
if slot2 == slot {
|
if slot2 == slot {
|
||||||
count += 1;
|
count += 1;
|
||||||
let ai = AccountInfo::new(
|
let ai = AccountInfo::new(
|
||||||
account_info.store_id,
|
StorageLocation::AppendVec(
|
||||||
account_info.stored_account.offset,
|
account_info.store_id,
|
||||||
|
account_info.stored_account.offset,
|
||||||
|
), // will never be cached
|
||||||
account_info.stored_account.stored_size,
|
account_info.stored_account.stored_size,
|
||||||
account_info.stored_account.account_meta.lamports,
|
account_info.stored_account.account_meta.lamports,
|
||||||
);
|
);
|
||||||
@ -11012,10 +11005,10 @@ pub mod tests {
|
|||||||
let key0 = Pubkey::new_from_array([0u8; 32]);
|
let key0 = Pubkey::new_from_array([0u8; 32]);
|
||||||
let key1 = Pubkey::new_from_array([1u8; 32]);
|
let key1 = Pubkey::new_from_array([1u8; 32]);
|
||||||
let key2 = Pubkey::new_from_array([2u8; 32]);
|
let key2 = Pubkey::new_from_array([2u8; 32]);
|
||||||
let info0 = AccountInfo::new(0, 0, 0, 0);
|
let info0 = AccountInfo::new(StorageLocation::AppendVec(0, 0), 0, 0);
|
||||||
let info1 = AccountInfo::new(1, 0, 0, 0);
|
let info1 = AccountInfo::new(StorageLocation::AppendVec(1, 0), 0, 0);
|
||||||
let info2 = AccountInfo::new(2, 0, 0, 0);
|
let info2 = AccountInfo::new(StorageLocation::AppendVec(2, 0), 0, 0);
|
||||||
let info3 = AccountInfo::new(3, 0, 0, 0);
|
let info3 = AccountInfo::new(StorageLocation::AppendVec(3, 0), 0, 0);
|
||||||
let mut reclaims = vec![];
|
let mut reclaims = vec![];
|
||||||
accounts_index.upsert(
|
accounts_index.upsert(
|
||||||
0,
|
0,
|
||||||
@ -13324,7 +13317,7 @@ pub mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let do_test = |test_params: TestParameters| {
|
let do_test = |test_params: TestParameters| {
|
||||||
let account_info = AccountInfo::new(42, 123, 234, 0);
|
let account_info = AccountInfo::new(StorageLocation::AppendVec(42, 123), 234, 0);
|
||||||
let pubkey = solana_sdk::pubkey::new_rand();
|
let pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let mut key_set = HashSet::default();
|
let mut key_set = HashSet::default();
|
||||||
key_set.insert(pubkey);
|
key_set.insert(pubkey);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user