Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions accounts-db/benches/append_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ extern crate test;
use {
rand::{thread_rng, Rng},
solana_accounts_db::{
account_storage::meta::{
StorableAccountsWithHashesAndWriteVersions, StoredAccountInfo, StoredMeta,
},
account_storage::meta::{StorableAccountsWithHashes, StoredAccountInfo, StoredMeta},
accounts_hash::AccountHash,
append_vec::{
test_utils::{create_test_account, get_append_vec_path},
Expand Down Expand Up @@ -39,12 +37,7 @@ fn append_account(
let accounts = [(&storage_meta.pubkey, account)];
let slice = &accounts[..];
let accounts = (slot_ignored, slice);
let storable_accounts =
StorableAccountsWithHashesAndWriteVersions::new_with_hashes_and_write_versions(
&accounts,
vec![&hash],
vec![storage_meta.write_version_obsolete],
);
let storable_accounts = StorableAccountsWithHashes::new_with_hashes(&accounts, vec![&hash]);
let res = vec.append_accounts(&storable_accounts, 0);
res.and_then(|res| res.first().cloned())
}
Expand Down
12 changes: 5 additions & 7 deletions accounts-db/benches/bench_accounts_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use {
criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion, Throughput},
solana_accounts_db::{
account_storage::meta::StorableAccountsWithHashesAndWriteVersions,
account_storage::meta::StorableAccountsWithHashes,
accounts_hash::AccountHash,
append_vec::{self, AppendVec},
tiered_storage::hot::HotStorageWriter,
Expand Down Expand Up @@ -46,12 +46,10 @@ fn bench_write_accounts_file(c: &mut Criterion) {
.collect();
let accounts_refs: Vec<_> = accounts.iter().collect();
let accounts_data = (Slot::MAX, accounts_refs.as_slice());
let storable_accounts =
StorableAccountsWithHashesAndWriteVersions::new_with_hashes_and_write_versions(
&accounts_data,
vec![AccountHash(Hash::default()); accounts_count],
vec![0; accounts_count],
);
let storable_accounts = StorableAccountsWithHashes::new_with_hashes(
&accounts_data,
vec![AccountHash(Hash::default()); accounts_count],
);

group.bench_function(BenchmarkId::new("append_vec", accounts_count), |b| {
b.iter_batched_ref(
Expand Down
40 changes: 17 additions & 23 deletions accounts-db/src/account_storage/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ lazy_static! {
/// This struct contains what is needed to store accounts to a storage
/// 1. account & pubkey (StorableAccounts)
/// 2. hash per account (Maybe in StorableAccounts, otherwise has to be passed in separately)
/// 3. write version per account (Maybe in StorableAccounts, otherwise has to be passed in separately)
pub struct StorableAccountsWithHashesAndWriteVersions<
pub struct StorableAccountsWithHashes<
'a: 'b,
'b,
T: ReadableAccount + Sync + 'b,
Expand All @@ -35,10 +34,10 @@ pub struct StorableAccountsWithHashesAndWriteVersions<
> {
/// accounts to store
/// always has pubkey and account
/// may also have hash and write_version per account
/// may also have hash per account
pub(crate) accounts: &'b U,
/// if accounts does not have hash and write version, this has a hash and write version per account
hashes_and_write_versions: Option<(Vec<V>, Vec<StoredMetaWriteVersion>)>,
/// if accounts does not have hash, this has a hash per account
hashes: Option<Vec<V>>,
_phantom: PhantomData<&'a T>,
}

Expand All @@ -48,45 +47,40 @@ impl<
T: ReadableAccount + Sync + 'b,
U: StorableAccounts<'a, T>,
V: Borrow<AccountHash>,
> StorableAccountsWithHashesAndWriteVersions<'a, 'b, T, U, V>
> StorableAccountsWithHashes<'a, 'b, T, U, V>
{
/// used when accounts contains hash and write version already
/// used when accounts contains hash already
pub fn new(accounts: &'b U) -> Self {
assert!(accounts.has_hash());
Self {
accounts,
hashes_and_write_versions: None,
hashes: None,
_phantom: PhantomData,
}
}
/// used when accounts does NOT contains hash or write version
/// In this case, hashes and write_versions have to be passed in separately and zipped together.
pub fn new_with_hashes_and_write_versions(
accounts: &'b U,
hashes: Vec<V>,
write_versions: Vec<StoredMetaWriteVersion>,
) -> Self {
/// used when accounts does NOT contains hash
/// In this case, hashes have to be passed in separately.
pub fn new_with_hashes(accounts: &'b U, hashes: Vec<V>) -> Self {
assert!(!accounts.has_hash());
assert_eq!(accounts.len(), hashes.len());
assert_eq!(write_versions.len(), hashes.len());
Self {
accounts,
hashes_and_write_versions: Some((hashes, write_versions)),
hashes: Some(hashes),
_phantom: PhantomData,
}
}

/// get all account fields at 'index'
pub fn get(&self, index: usize) -> (Option<&T>, &Pubkey, &AccountHash, StoredMetaWriteVersion) {
pub fn get(&self, index: usize) -> (Option<&T>, &Pubkey, &AccountHash) {
let account = self.accounts.account_default_if_zero_lamport(index);
let pubkey = self.accounts.pubkey(index);
let (hash, write_version) = if self.accounts.has_hash() {
(self.accounts.hash(index), StoredMetaWriteVersion::default())
let hash = if self.accounts.has_hash() {
self.accounts.hash(index)
} else {
let item = self.hashes_and_write_versions.as_ref().unwrap();
(item.0[index].borrow(), item.1[index])
let item = self.hashes.as_ref().unwrap();
item[index].borrow()
};
(account, pubkey, hash, write_version)
(account, pubkey, hash)
}

/// None if account at index has lamports == 0
Expand Down
Loading