remove 'stored_size' from account info (#30407)
This commit is contained in:
parent
2ba76e4235
commit
6a66d4631c
|
@ -90,8 +90,6 @@ pub struct AccountInfo {
|
||||||
/// offset = 'packed_offset_and_flags.offset_reduced()' * ALIGN_BOUNDARY_OFFSET into the storage
|
/// offset = 'packed_offset_and_flags.offset_reduced()' * ALIGN_BOUNDARY_OFFSET into the storage
|
||||||
/// Note this is a smaller type than 'Offset'
|
/// Note this is a smaller type than 'Offset'
|
||||||
packed_offset_and_flags: PackedOffsetAndFlags,
|
packed_offset_and_flags: PackedOffsetAndFlags,
|
||||||
|
|
||||||
stored_size: StoredSize,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ZeroLamport for AccountInfo {
|
impl ZeroLamport for AccountInfo {
|
||||||
|
@ -116,7 +114,7 @@ impl IsCached for StorageLocation {
|
||||||
const CACHE_VIRTUAL_STORAGE_ID: AppendVecId = AppendVecId::MAX;
|
const CACHE_VIRTUAL_STORAGE_ID: AppendVecId = AppendVecId::MAX;
|
||||||
|
|
||||||
impl AccountInfo {
|
impl AccountInfo {
|
||||||
pub fn new(storage_location: StorageLocation, stored_size: StoredSize, lamports: u64) -> Self {
|
pub fn new(storage_location: StorageLocation, lamports: u64) -> Self {
|
||||||
let mut packed_offset_and_flags = PackedOffsetAndFlags::default();
|
let mut packed_offset_and_flags = PackedOffsetAndFlags::default();
|
||||||
let store_id = match storage_location {
|
let store_id = match storage_location {
|
||||||
StorageLocation::AppendVec(store_id, offset) => {
|
StorageLocation::AppendVec(store_id, offset) => {
|
||||||
|
@ -142,7 +140,6 @@ impl AccountInfo {
|
||||||
Self {
|
Self {
|
||||||
store_id,
|
store_id,
|
||||||
packed_offset_and_flags,
|
packed_offset_and_flags,
|
||||||
stored_size,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,10 +161,6 @@ impl AccountInfo {
|
||||||
(reduced_offset as Offset) * ALIGN_BOUNDARY_OFFSET
|
(reduced_offset as Offset) * ALIGN_BOUNDARY_OFFSET
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stored_size(&self) -> StoredSize {
|
|
||||||
self.stored_size
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn storage_location(&self) -> StorageLocation {
|
pub fn storage_location(&self) -> StorageLocation {
|
||||||
if self.is_cached() {
|
if self.is_cached() {
|
||||||
StorageLocation::Cached
|
StorageLocation::Cached
|
||||||
|
@ -192,7 +185,7 @@ mod test {
|
||||||
ALIGN_BOUNDARY_OFFSET,
|
ALIGN_BOUNDARY_OFFSET,
|
||||||
4 * ALIGN_BOUNDARY_OFFSET,
|
4 * ALIGN_BOUNDARY_OFFSET,
|
||||||
] {
|
] {
|
||||||
let info = AccountInfo::new(StorageLocation::AppendVec(0, offset), 0, 0);
|
let info = AccountInfo::new(StorageLocation::AppendVec(0, offset), 0);
|
||||||
assert!(info.offset() == offset);
|
assert!(info.offset() == offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -201,13 +194,13 @@ mod test {
|
||||||
#[should_panic(expected = "illegal offset")]
|
#[should_panic(expected = "illegal offset")]
|
||||||
fn test_illegal_offset() {
|
fn test_illegal_offset() {
|
||||||
let offset = (MAXIMUM_APPEND_VEC_FILE_SIZE - (ALIGN_BOUNDARY_OFFSET as u64)) as Offset;
|
let offset = (MAXIMUM_APPEND_VEC_FILE_SIZE - (ALIGN_BOUNDARY_OFFSET as u64)) as Offset;
|
||||||
AccountInfo::new(StorageLocation::AppendVec(0, offset), 0, 0);
|
AccountInfo::new(StorageLocation::AppendVec(0, offset), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic(expected = "illegal offset")]
|
#[should_panic(expected = "illegal offset")]
|
||||||
fn test_alignment() {
|
fn test_alignment() {
|
||||||
let offset = 1; // not aligned
|
let offset = 1; // not aligned
|
||||||
AccountInfo::new(StorageLocation::AppendVec(0, offset), 0, 0);
|
AccountInfo::new(StorageLocation::AppendVec(0, offset), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
use {
|
use {
|
||||||
crate::{
|
crate::{
|
||||||
account_info::{AccountInfo, StorageLocation, StoredSize},
|
account_info::{AccountInfo, StorageLocation},
|
||||||
account_storage::{AccountStorage, AccountStorageStatus, ShrinkInProgress},
|
account_storage::{AccountStorage, AccountStorageStatus, ShrinkInProgress},
|
||||||
accounts_background_service::{DroppedSlotsSender, SendDroppedBankCallback},
|
accounts_background_service::{DroppedSlotsSender, SendDroppedBankCallback},
|
||||||
accounts_cache::{AccountsCache, CachedAccount, SlotCache},
|
accounts_cache::{AccountsCache, CachedAccount, SlotCache},
|
||||||
|
@ -129,10 +129,6 @@ pub const PUBKEY_BINS_FOR_CALCULATING_HASHES: usize = 65536;
|
||||||
// Metrics indicate a sweet spot in the 2.5k-5k range for mnb.
|
// Metrics indicate a sweet spot in the 2.5k-5k range for mnb.
|
||||||
const MAX_ITEMS_PER_CHUNK: Slot = 2_500;
|
const MAX_ITEMS_PER_CHUNK: Slot = 2_500;
|
||||||
|
|
||||||
/// A place holder stored size for a cached entry. We don't need to store the size for cached entries, but we have to pass something.
|
|
||||||
/// stored size is only used for shrinking. We don't shrink items in the write cache.
|
|
||||||
const CACHE_VIRTUAL_STORED_SIZE: StoredSize = 0;
|
|
||||||
|
|
||||||
// When getting accounts for shrinking from the index, this is the # of accounts to lookup per thread.
|
// When getting accounts for shrinking from the index, this is the # of accounts to lookup per thread.
|
||||||
// This allows us to split up accounts index accesses across multiple threads.
|
// This allows us to split up accounts index accesses across multiple threads.
|
||||||
const SHRINK_COLLECT_CHUNK_SIZE: usize = 50;
|
const SHRINK_COLLECT_CHUNK_SIZE: usize = 50;
|
||||||
|
@ -6175,7 +6171,6 @@ impl AccountsDb {
|
||||||
|
|
||||||
infos.push(AccountInfo::new(
|
infos.push(AccountInfo::new(
|
||||||
StorageLocation::AppendVec(storage.append_vec_id(), offsets[0]),
|
StorageLocation::AppendVec(storage.append_vec_id(), offsets[0]),
|
||||||
stored_size as StoredSize, // stored_size should never exceed StoredSize::MAX because of max data len const
|
|
||||||
accounts_and_meta_to_store
|
accounts_and_meta_to_store
|
||||||
.account(i)
|
.account(i)
|
||||||
.map(|account| account.lamports())
|
.map(|account| account.lamports())
|
||||||
|
@ -6608,11 +6603,7 @@ impl AccountsDb {
|
||||||
.account_default_if_zero_lamport(i)
|
.account_default_if_zero_lamport(i)
|
||||||
.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(StorageLocation::Cached, account.lamports());
|
||||||
StorageLocation::Cached,
|
|
||||||
CACHE_VIRTUAL_STORED_SIZE,
|
|
||||||
account.lamports(),
|
|
||||||
);
|
|
||||||
|
|
||||||
self.notify_account_at_accounts_update(
|
self.notify_account_at_accounts_update(
|
||||||
slot,
|
slot,
|
||||||
|
@ -7936,17 +7927,10 @@ impl AccountsDb {
|
||||||
"AccountsDB::accounts_index corrupted. Storage pointed to: {}, expected: {}, should only point to one slot",
|
"AccountsDB::accounts_index corrupted. Storage pointed to: {}, expected: {}, should only point to one slot",
|
||||||
store.slot(), *slot
|
store.slot(), *slot
|
||||||
);
|
);
|
||||||
let account = store.accounts.get_account(account_info.offset()).unwrap();
|
let offset = account_info.offset();
|
||||||
if account.1
|
let account = store.accounts.get_account(offset).unwrap();
|
||||||
!= account_info
|
let stored_size = account.1.saturating_sub(offset);
|
||||||
.offset()
|
let count = store.remove_account(stored_size, reset_accounts);
|
||||||
.saturating_add(account_info.stored_size() as usize)
|
|
||||||
{
|
|
||||||
// this should never happen. This is a metrics based assert at the moment.
|
|
||||||
inc_new_counter_info!("remove_dead_accounts-stored_size_mismatch", 1);
|
|
||||||
}
|
|
||||||
let count =
|
|
||||||
store.remove_account(account_info.stored_size() as usize, reset_accounts);
|
|
||||||
if count == 0 {
|
if count == 0 {
|
||||||
self.dirty_stores
|
self.dirty_stores
|
||||||
.insert((*slot, store.append_vec_id()), store.clone());
|
.insert((*slot, store.append_vec_id()), store.clone());
|
||||||
|
@ -8695,7 +8679,6 @@ impl AccountsDb {
|
||||||
pubkey,
|
pubkey,
|
||||||
AccountInfo::new(
|
AccountInfo::new(
|
||||||
StorageLocation::AppendVec(store_id, stored_account.offset), // will never be cached
|
StorageLocation::AppendVec(store_id, stored_account.offset), // will never be cached
|
||||||
stored_account.stored_size as StoredSize, // stored_size should never exceed StoredSize::MAX because of max data len const
|
|
||||||
stored_account.account_meta.lamports,
|
stored_account.account_meta.lamports,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -8930,7 +8913,6 @@ impl AccountsDb {
|
||||||
account_info.store_id,
|
account_info.store_id,
|
||||||
account_info.stored_account.offset,
|
account_info.stored_account.offset,
|
||||||
), // will never be cached
|
), // will never be cached
|
||||||
account_info.stored_account.stored_size as StoredSize, // stored_size should never exceed StoredSize::MAX because of max data len const
|
|
||||||
account_info.stored_account.account_meta.lamports,
|
account_info.stored_account.account_meta.lamports,
|
||||||
);
|
);
|
||||||
assert_eq!(&ai, account_info2);
|
assert_eq!(&ai, account_info2);
|
||||||
|
@ -9418,6 +9400,7 @@ pub mod tests {
|
||||||
use {
|
use {
|
||||||
super::*,
|
super::*,
|
||||||
crate::{
|
crate::{
|
||||||
|
account_info::StoredSize,
|
||||||
accounts::Accounts,
|
accounts::Accounts,
|
||||||
accounts_hash::MERKLE_FANOUT,
|
accounts_hash::MERKLE_FANOUT,
|
||||||
accounts_index::{
|
accounts_index::{
|
||||||
|
@ -10439,7 +10422,6 @@ pub mod tests {
|
||||||
if let Some(index) = add_to_index {
|
if let Some(index) = add_to_index {
|
||||||
let account_info = AccountInfo::new(
|
let account_info = AccountInfo::new(
|
||||||
StorageLocation::AppendVec(storage.append_vec_id(), offsets[0]),
|
StorageLocation::AppendVec(storage.append_vec_id(), offsets[0]),
|
||||||
(offsets[1] - offsets[0]).try_into().unwrap(),
|
|
||||||
account.lamports(),
|
account.lamports(),
|
||||||
);
|
);
|
||||||
index.upsert(
|
index.upsert(
|
||||||
|
@ -12339,6 +12321,10 @@ pub mod tests {
|
||||||
assert!(accounts_equal(&account, &stored_account));
|
assert!(accounts_equal(&account, &stored_account));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A place holder stored size for a cached entry. We don't need to store the size for cached entries, but we have to pass something.
|
||||||
|
/// stored size is only used for shrinking. We don't shrink items in the write cache.
|
||||||
|
const CACHE_VIRTUAL_STORED_SIZE: StoredSize = 0;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_hash_stored_account() {
|
fn test_hash_stored_account() {
|
||||||
// This test uses some UNSAFE tricks to detect most of account's field
|
// This test uses some UNSAFE tricks to detect most of account's field
|
||||||
|
@ -13580,10 +13566,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(StorageLocation::AppendVec(0, 0), 0, 0);
|
let info0 = AccountInfo::new(StorageLocation::AppendVec(0, 0), 0);
|
||||||
let info1 = AccountInfo::new(StorageLocation::AppendVec(1, 0), 0, 0);
|
let info1 = AccountInfo::new(StorageLocation::AppendVec(1, 0), 0);
|
||||||
let info2 = AccountInfo::new(StorageLocation::AppendVec(2, 0), 0, 0);
|
let info2 = AccountInfo::new(StorageLocation::AppendVec(2, 0), 0);
|
||||||
let info3 = AccountInfo::new(StorageLocation::AppendVec(3, 0), 0, 0);
|
let info3 = AccountInfo::new(StorageLocation::AppendVec(3, 0), 0);
|
||||||
let mut reclaims = vec![];
|
let mut reclaims = vec![];
|
||||||
accounts_index.upsert(
|
accounts_index.upsert(
|
||||||
0,
|
0,
|
||||||
|
@ -14598,10 +14584,6 @@ pub mod tests {
|
||||||
locked_entry.slot_list()[0]
|
locked_entry.slot_list()[0]
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let removed_data_size = account_info.1.stored_size();
|
|
||||||
// Fetching the account from storage should return the same
|
|
||||||
// stored size as in the index.
|
|
||||||
assert_eq!(removed_data_size, account.stored_size as StoredSize);
|
|
||||||
assert_eq!(account_info.0, slot);
|
assert_eq!(account_info.0, slot);
|
||||||
let reclaims = vec![account_info];
|
let reclaims = vec![account_info];
|
||||||
accounts_db.remove_dead_accounts(reclaims.iter(), None, None, true);
|
accounts_db.remove_dead_accounts(reclaims.iter(), None, None, true);
|
||||||
|
@ -16035,7 +16017,7 @@ pub mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
let do_test = |test_params: TestParameters| {
|
let do_test = |test_params: TestParameters| {
|
||||||
let account_info = AccountInfo::new(StorageLocation::AppendVec(42, 128), 234, 0);
|
let account_info = AccountInfo::new(StorageLocation::AppendVec(42, 128), 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);
|
||||||
|
@ -17608,7 +17590,6 @@ pub mod tests {
|
||||||
storage.accounts.account_iter().for_each(|account| {
|
storage.accounts.account_iter().for_each(|account| {
|
||||||
let info = AccountInfo::new(
|
let info = AccountInfo::new(
|
||||||
StorageLocation::AppendVec(storage.append_vec_id(), account.offset),
|
StorageLocation::AppendVec(storage.append_vec_id(), account.offset),
|
||||||
account.stored_size as u32,
|
|
||||||
account.lamports(),
|
account.lamports(),
|
||||||
);
|
);
|
||||||
db.accounts_index.upsert(
|
db.accounts_index.upsert(
|
||||||
|
|
Loading…
Reference in New Issue