Replaces StorableAccountsWithHashes in AppendVec (#853)
This commit is contained in:
parent
63d4278cae
commit
4d2d95fe14
|
@ -4,8 +4,7 @@ extern crate test;
|
|||
use {
|
||||
rand::{thread_rng, Rng},
|
||||
solana_accounts_db::{
|
||||
account_storage::meta::{StorableAccountsWithHashes, StoredAccountInfo, StoredMeta},
|
||||
accounts_hash::AccountHash,
|
||||
account_storage::meta::{StoredAccountInfo, StoredMeta},
|
||||
append_vec::{
|
||||
test_utils::{create_test_account, get_append_vec_path},
|
||||
AppendVec,
|
||||
|
@ -14,7 +13,6 @@ use {
|
|||
solana_sdk::{
|
||||
account::{AccountSharedData, ReadableAccount},
|
||||
clock::Slot,
|
||||
hash::Hash,
|
||||
},
|
||||
std::{
|
||||
sync::{Arc, Mutex},
|
||||
|
@ -31,13 +29,11 @@ fn append_account(
|
|||
vec: &AppendVec,
|
||||
storage_meta: StoredMeta,
|
||||
account: &AccountSharedData,
|
||||
hash: AccountHash,
|
||||
) -> Option<StoredAccountInfo> {
|
||||
let slot_ignored = Slot::MAX;
|
||||
let accounts = [(&storage_meta.pubkey, account)];
|
||||
let slice = &accounts[..];
|
||||
let accounts = (slot_ignored, slice);
|
||||
let storable_accounts = StorableAccountsWithHashes::new_with_hashes(&accounts, vec![&hash]);
|
||||
let storable_accounts = (slot_ignored, slice);
|
||||
let res = vec.append_accounts(&storable_accounts, 0);
|
||||
res.and_then(|res| res.first().cloned())
|
||||
}
|
||||
|
@ -48,7 +44,7 @@ fn append_vec_append(bencher: &mut Bencher) {
|
|||
let vec = AppendVec::new(&path.path, true, 64 * 1024);
|
||||
bencher.iter(|| {
|
||||
let (meta, account) = create_test_account(0);
|
||||
if append_account(&vec, meta, &account, AccountHash(Hash::default())).is_none() {
|
||||
if append_account(&vec, meta, &account).is_none() {
|
||||
vec.reset();
|
||||
}
|
||||
});
|
||||
|
@ -58,8 +54,7 @@ fn add_test_accounts(vec: &AppendVec, size: usize) -> Vec<(usize, usize)> {
|
|||
(0..size)
|
||||
.filter_map(|sample| {
|
||||
let (meta, account) = create_test_account(sample);
|
||||
append_account(vec, meta, &account, AccountHash(Hash::default()))
|
||||
.map(|info| (sample, info.offset))
|
||||
append_account(vec, meta, &account).map(|info| (sample, info.offset))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
@ -104,7 +99,7 @@ fn append_vec_concurrent_append_read(bencher: &mut Bencher) {
|
|||
spawn(move || loop {
|
||||
let sample = indexes1.lock().unwrap().len();
|
||||
let (meta, account) = create_test_account(sample);
|
||||
if let Some(info) = append_account(&vec1, meta, &account, AccountHash(Hash::default())) {
|
||||
if let Some(info) = append_account(&vec1, meta, &account) {
|
||||
indexes1.lock().unwrap().push((sample, info.offset))
|
||||
} else {
|
||||
break;
|
||||
|
@ -144,7 +139,7 @@ fn append_vec_concurrent_read_append(bencher: &mut Bencher) {
|
|||
bencher.iter(|| {
|
||||
let sample: usize = thread_rng().gen_range(0..256);
|
||||
let (meta, account) = create_test_account(sample);
|
||||
if let Some(info) = append_account(&vec, meta, &account, AccountHash(Hash::default())) {
|
||||
if let Some(info) = append_account(&vec, meta, &account) {
|
||||
indexes.lock().unwrap().push((sample, info.offset))
|
||||
}
|
||||
});
|
||||
|
|
|
@ -59,7 +59,9 @@ fn bench_write_accounts_file(c: &mut Criterion) {
|
|||
AppendVec::new(path, true, file_size)
|
||||
},
|
||||
|append_vec| {
|
||||
let res = append_vec.append_accounts(&storable_accounts, 0).unwrap();
|
||||
let res = append_vec
|
||||
.append_accounts(storable_accounts.accounts, 0)
|
||||
.unwrap();
|
||||
let accounts_written_count = res.len();
|
||||
assert_eq!(accounts_written_count, accounts_count);
|
||||
},
|
||||
|
|
|
@ -30,7 +30,7 @@ pub struct StorableAccountsWithHashes<'a: 'b, 'b, U: StorableAccounts<'a>, V: Bo
|
|||
/// accounts to store
|
||||
/// always has pubkey and account
|
||||
/// may also have hash per account
|
||||
pub(crate) accounts: &'b U,
|
||||
pub accounts: &'b U,
|
||||
/// if accounts does not have hash, this has a hash per account
|
||||
hashes: Option<Vec<V>>,
|
||||
_phantom: PhantomData<&'a ()>,
|
||||
|
|
|
@ -272,7 +272,7 @@ impl AccountsFile {
|
|||
skip: usize,
|
||||
) -> Option<Vec<StoredAccountInfo>> {
|
||||
match self {
|
||||
Self::AppendVec(av) => av.append_accounts(accounts, skip),
|
||||
Self::AppendVec(av) => av.append_accounts(accounts.accounts, skip),
|
||||
// Note: The conversion here is needed as the AccountsDB currently
|
||||
// assumes all offsets are multiple of 8 while TieredStorage uses
|
||||
// IndexOffset that is equivalent to AccountInfo::reduced_offset.
|
||||
|
|
|
@ -7,8 +7,7 @@
|
|||
use {
|
||||
crate::{
|
||||
account_storage::meta::{
|
||||
AccountMeta, StorableAccountsWithHashes, StoredAccountInfo, StoredAccountMeta,
|
||||
StoredMeta, StoredMetaWriteVersion,
|
||||
AccountMeta, StoredAccountInfo, StoredAccountMeta, StoredMeta, StoredMetaWriteVersion,
|
||||
},
|
||||
accounts_file::{AccountsFileError, MatchAccountOwnerError, Result, ALIGN_BOUNDARY_OFFSET},
|
||||
accounts_hash::AccountHash,
|
||||
|
@ -25,7 +24,6 @@ use {
|
|||
stake_history::Epoch,
|
||||
},
|
||||
std::{
|
||||
borrow::Borrow,
|
||||
convert::TryFrom,
|
||||
fs::{remove_file, OpenOptions},
|
||||
io::{Seek, SeekFrom, Write},
|
||||
|
@ -746,15 +744,15 @@ impl AppendVec {
|
|||
/// So, return.len() is 1 + (number of accounts written)
|
||||
/// After each account is appended, the internal `current_len` is updated
|
||||
/// and will be available to other threads.
|
||||
pub fn append_accounts<'a, 'b, U: StorableAccounts<'a>, V: Borrow<AccountHash>>(
|
||||
pub fn append_accounts<'a>(
|
||||
&self,
|
||||
accounts: &StorableAccountsWithHashes<'a, 'b, U, V>,
|
||||
accounts: &impl StorableAccounts<'a>,
|
||||
skip: usize,
|
||||
) -> Option<Vec<StoredAccountInfo>> {
|
||||
let _lock = self.append_lock.lock().unwrap();
|
||||
let default_hash: Hash = Hash::default(); // [0_u8; 32];
|
||||
let mut offset = self.len();
|
||||
let len = accounts.accounts.len();
|
||||
let len = accounts.len();
|
||||
// Here we have `len - skip` number of accounts. The +1 extra capacity
|
||||
// is for storing the aligned offset of the last entry to that is used
|
||||
// to compute the StoredAccountInfo of the last entry.
|
||||
|
@ -765,7 +763,7 @@ impl AppendVec {
|
|||
if stop {
|
||||
break;
|
||||
}
|
||||
accounts.get(i, |account, _hash| {
|
||||
accounts.account_default_if_zero_lamport(i, |account| {
|
||||
let account_meta = AccountMeta {
|
||||
lamports: account.lamports(),
|
||||
owner: *account.owner(),
|
||||
|
@ -826,6 +824,7 @@ impl AppendVec {
|
|||
pub mod tests {
|
||||
use {
|
||||
super::{test_utils::*, *},
|
||||
crate::account_storage::meta::StorableAccountsWithHashes,
|
||||
assert_matches::assert_matches,
|
||||
memoffset::offset_of,
|
||||
rand::{thread_rng, Rng},
|
||||
|
@ -846,10 +845,7 @@ pub mod tests {
|
|||
let slot_ignored = Slot::MAX;
|
||||
let accounts = [(&data.0.pubkey, &data.1)];
|
||||
let slice = &accounts[..];
|
||||
let account_data = (slot_ignored, slice);
|
||||
let hash = AccountHash(Hash::default());
|
||||
let storable_accounts =
|
||||
StorableAccountsWithHashes::new_with_hashes(&account_data, vec![&hash]);
|
||||
let storable_accounts = (slot_ignored, slice);
|
||||
|
||||
self.append_accounts(&storable_accounts, 0)
|
||||
.map(|res| res[0].offset)
|
||||
|
|
Loading…
Reference in New Issue