add Copy trait to AccountInfo for fast copies to mmapped file (#19524)
This commit is contained in:
committed by
GitHub
parent
c550b32a44
commit
12dc8749cf
@ -212,7 +212,7 @@ impl GenerateIndexTimings {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug, PartialEq, Clone)]
|
#[derive(Default, Debug, PartialEq, Clone, Copy)]
|
||||||
pub struct AccountInfo {
|
pub struct AccountInfo {
|
||||||
/// index identifying the append storage
|
/// index identifying the append storage
|
||||||
store_id: AppendVecId,
|
store_id: AppendVecId,
|
||||||
@ -7933,12 +7933,12 @@ pub mod tests {
|
|||||||
let (slot1, account_info1) = accounts
|
let (slot1, account_info1) = accounts
|
||||||
.accounts_index
|
.accounts_index
|
||||||
.get(&pubkey1, Some(&ancestors), None)
|
.get(&pubkey1, Some(&ancestors), None)
|
||||||
.map(|(account_list1, index1)| account_list1.slot_list()[index1].clone())
|
.map(|(account_list1, index1)| account_list1.slot_list()[index1])
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let (slot2, account_info2) = accounts
|
let (slot2, account_info2) = accounts
|
||||||
.accounts_index
|
.accounts_index
|
||||||
.get(&pubkey2, Some(&ancestors), None)
|
.get(&pubkey2, Some(&ancestors), None)
|
||||||
.map(|(account_list2, index2)| account_list2.slot_list()[index2].clone())
|
.map(|(account_list2, index2)| account_list2.slot_list()[index2])
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(slot1, 0);
|
assert_eq!(slot1, 0);
|
||||||
assert_eq!(slot1, slot2);
|
assert_eq!(slot1, slot2);
|
||||||
@ -8490,12 +8490,12 @@ pub mod tests {
|
|||||||
let (slot1, account_info1) = accounts
|
let (slot1, account_info1) = accounts
|
||||||
.accounts_index
|
.accounts_index
|
||||||
.get(&pubkey, None, None)
|
.get(&pubkey, None, None)
|
||||||
.map(|(account_list1, index1)| account_list1.slot_list()[index1].clone())
|
.map(|(account_list1, index1)| account_list1.slot_list()[index1])
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let (slot2, account_info2) = accounts
|
let (slot2, account_info2) = accounts
|
||||||
.accounts_index
|
.accounts_index
|
||||||
.get(&pubkey2, None, None)
|
.get(&pubkey2, None, None)
|
||||||
.map(|(account_list2, index2)| account_list2.slot_list()[index2].clone())
|
.map(|(account_list2, index2)| account_list2.slot_list()[index2])
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(slot1, current_slot);
|
assert_eq!(slot1, current_slot);
|
||||||
assert_eq!(slot1, slot2);
|
assert_eq!(slot1, slot2);
|
||||||
@ -10324,7 +10324,7 @@ pub mod tests {
|
|||||||
&Pubkey::default(),
|
&Pubkey::default(),
|
||||||
&[],
|
&[],
|
||||||
&AccountSecondaryIndexes::default(),
|
&AccountSecondaryIndexes::default(),
|
||||||
info1.clone(),
|
info1,
|
||||||
&mut reclaims,
|
&mut reclaims,
|
||||||
UPSERT_PREVIOUS_SLOT_ENTRY_WAS_CACHED_FALSE,
|
UPSERT_PREVIOUS_SLOT_ENTRY_WAS_CACHED_FALSE,
|
||||||
);
|
);
|
||||||
@ -10344,7 +10344,7 @@ pub mod tests {
|
|||||||
&Pubkey::default(),
|
&Pubkey::default(),
|
||||||
&[],
|
&[],
|
||||||
&AccountSecondaryIndexes::default(),
|
&AccountSecondaryIndexes::default(),
|
||||||
info2.clone(),
|
info2,
|
||||||
&mut reclaims,
|
&mut reclaims,
|
||||||
UPSERT_PREVIOUS_SLOT_ENTRY_WAS_CACHED_FALSE,
|
UPSERT_PREVIOUS_SLOT_ENTRY_WAS_CACHED_FALSE,
|
||||||
);
|
);
|
||||||
@ -11142,7 +11142,7 @@ pub mod tests {
|
|||||||
.get_account_read_entry(&account.meta.pubkey)
|
.get_account_read_entry(&account.meta.pubkey)
|
||||||
.map(|locked_entry| {
|
.map(|locked_entry| {
|
||||||
// Should only be one entry per key, since every key was only stored to slot 0
|
// Should only be one entry per key, since every key was only stored to slot 0
|
||||||
locked_entry.slot_list()[0].clone()
|
locked_entry.slot_list()[0]
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let removed_data_size = account_info.1.stored_size;
|
let removed_data_size = account_info.1.stored_size;
|
||||||
|
@ -46,7 +46,7 @@ pub type AccountMap<V> = HashMap<Pubkey, V>;
|
|||||||
|
|
||||||
type AccountMapEntry<T> = Arc<AccountMapEntryInner<T>>;
|
type AccountMapEntry<T> = Arc<AccountMapEntryInner<T>>;
|
||||||
|
|
||||||
pub trait IsCached: 'static + Clone + Debug + PartialEq + ZeroLamport {
|
pub trait IsCached: 'static + Clone + Debug + PartialEq + ZeroLamport + Copy {
|
||||||
fn is_cached(&self) -> bool;
|
fn is_cached(&self) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1363,7 +1363,7 @@ impl<T: IsCached> AccountsIndex<T> {
|
|||||||
slot_list.retain(|(slot, item)| {
|
slot_list.retain(|(slot, item)| {
|
||||||
let should_purge = slots_to_purge.contains(slot);
|
let should_purge = slots_to_purge.contains(slot);
|
||||||
if should_purge {
|
if should_purge {
|
||||||
reclaims.push((*slot, item.clone()));
|
reclaims.push((*slot, *item));
|
||||||
false
|
false
|
||||||
} else {
|
} else {
|
||||||
true
|
true
|
||||||
@ -1709,7 +1709,7 @@ impl<T: IsCached> AccountsIndex<T> {
|
|||||||
Self::can_purge_older_entries(max_clean_root, newest_root_in_slot_list, *slot)
|
Self::can_purge_older_entries(max_clean_root, newest_root_in_slot_list, *slot)
|
||||||
&& !value.is_cached();
|
&& !value.is_cached();
|
||||||
if should_purge {
|
if should_purge {
|
||||||
reclaims.push((*slot, value.clone()));
|
reclaims.push((*slot, *value));
|
||||||
}
|
}
|
||||||
!should_purge
|
!should_purge
|
||||||
});
|
});
|
||||||
@ -2885,12 +2885,12 @@ pub mod tests {
|
|||||||
&Pubkey::default(),
|
&Pubkey::default(),
|
||||||
&[],
|
&[],
|
||||||
&AccountSecondaryIndexes::default(),
|
&AccountSecondaryIndexes::default(),
|
||||||
account_infos[0].clone(),
|
account_infos[0],
|
||||||
&mut gc,
|
&mut gc,
|
||||||
UPSERT_PREVIOUS_SLOT_ENTRY_WAS_CACHED_FALSE,
|
UPSERT_PREVIOUS_SLOT_ENTRY_WAS_CACHED_FALSE,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
let items = vec![(key, account_infos[0].clone())];
|
let items = vec![(key, account_infos[0])];
|
||||||
index.insert_new_if_missing_into_primary_index(slot0, items.len(), items.into_iter());
|
index.insert_new_if_missing_into_primary_index(slot0, items.len(), items.into_iter());
|
||||||
}
|
}
|
||||||
assert!(gc.is_empty());
|
assert!(gc.is_empty());
|
||||||
@ -2899,10 +2899,9 @@ pub mod tests {
|
|||||||
{
|
{
|
||||||
let entry = index.get_account_read_entry(&key).unwrap();
|
let entry = index.get_account_read_entry(&key).unwrap();
|
||||||
assert_eq!(entry.ref_count(), if is_cached { 0 } else { 1 });
|
assert_eq!(entry.ref_count(), if is_cached { 0 } else { 1 });
|
||||||
let expected = vec![(slot0, account_infos[0].clone())];
|
let expected = vec![(slot0, account_infos[0])];
|
||||||
assert_eq!(entry.slot_list().to_vec(), expected);
|
assert_eq!(entry.slot_list().to_vec(), expected);
|
||||||
let new_entry =
|
let new_entry = WriteAccountMapEntry::new_entry_after_update(slot0, account_infos[0]);
|
||||||
WriteAccountMapEntry::new_entry_after_update(slot0, account_infos[0].clone());
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
entry.slot_list().to_vec(),
|
entry.slot_list().to_vec(),
|
||||||
new_entry.slot_list.read().unwrap().to_vec(),
|
new_entry.slot_list.read().unwrap().to_vec(),
|
||||||
@ -2917,12 +2916,12 @@ pub mod tests {
|
|||||||
&Pubkey::default(),
|
&Pubkey::default(),
|
||||||
&[],
|
&[],
|
||||||
&AccountSecondaryIndexes::default(),
|
&AccountSecondaryIndexes::default(),
|
||||||
account_infos[1].clone(),
|
account_infos[1],
|
||||||
&mut gc,
|
&mut gc,
|
||||||
UPSERT_PREVIOUS_SLOT_ENTRY_WAS_CACHED_FALSE,
|
UPSERT_PREVIOUS_SLOT_ENTRY_WAS_CACHED_FALSE,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
let items = vec![(key, account_infos[1].clone())];
|
let items = vec![(key, account_infos[1])];
|
||||||
index.insert_new_if_missing_into_primary_index(slot1, items.len(), items.into_iter());
|
index.insert_new_if_missing_into_primary_index(slot1, items.len(), items.into_iter());
|
||||||
}
|
}
|
||||||
assert!(gc.is_empty());
|
assert!(gc.is_empty());
|
||||||
@ -2945,14 +2944,10 @@ pub mod tests {
|
|||||||
assert_eq!(entry.ref_count(), if is_cached { 0 } else { 2 });
|
assert_eq!(entry.ref_count(), if is_cached { 0 } else { 2 });
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
entry.slot_list().to_vec(),
|
entry.slot_list().to_vec(),
|
||||||
vec![
|
vec![(slot0, account_infos[0]), (slot1, account_infos[1])]
|
||||||
(slot0, account_infos[0].clone()),
|
|
||||||
(slot1, account_infos[1].clone())
|
|
||||||
]
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let new_entry =
|
let new_entry = WriteAccountMapEntry::new_entry_after_update(slot1, account_infos[1]);
|
||||||
WriteAccountMapEntry::new_entry_after_update(slot1, account_infos[1].clone());
|
|
||||||
assert_eq!(entry.slot_list()[1], new_entry.slot_list.read().unwrap()[0],);
|
assert_eq!(entry.slot_list()[1], new_entry.slot_list.read().unwrap()[0],);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user