remove unused return value from account index upsert (#18895)

This commit is contained in:
Jeff Washington (jwash)
2021-07-27 08:46:27 -05:00
committed by GitHub
parent eb6656a553
commit 53d8cad206

View File

@ -1453,10 +1453,9 @@ impl<
account_indexes: &AccountSecondaryIndexes, account_indexes: &AccountSecondaryIndexes,
account_info: T, account_info: T,
reclaims: &mut SlotList<T>, reclaims: &mut SlotList<T>,
) -> bool { ) {
let is_newly_inserted = {
// We don't atomically update both primary index and secondary index together. // We don't atomically update both primary index and secondary index together.
// This certainly creates small time window with inconsistent state across the two indexes. // This certainly creates a small time window with inconsistent state across the two indexes.
// However, this is acceptable because: // However, this is acceptable because:
// //
// - A strict consistent view at any given moment of time is not necessary, because the only // - A strict consistent view at any given moment of time is not necessary, because the only
@ -1470,13 +1469,8 @@ impl<
self.get_account_write_entry_else_create(pubkey, slot, account_info) self.get_account_write_entry_else_create(pubkey, slot, account_info)
{ {
w_account_entry.update(slot, account_info, reclaims); w_account_entry.update(slot, account_info, reclaims);
false
} else {
true
} }
};
self.update_secondary_indexes(pubkey, account_owner, account_data, account_indexes); self.update_secondary_indexes(pubkey, account_owner, account_data, account_indexes);
is_newly_inserted
} }
pub fn unref_from_storage(&self, pubkey: &Pubkey) { pub fn unref_from_storage(&self, pubkey: &Pubkey) {
@ -3279,30 +3273,52 @@ pub mod tests {
assert!(found_key); assert!(found_key);
} }
fn account_maps_len_expensive<
T: 'static
+ Sync
+ Send
+ Clone
+ IsCached
+ ZeroLamport
+ std::cmp::PartialEq
+ std::fmt::Debug,
>(
index: &AccountsIndex<T>,
) -> usize {
index
.account_maps
.iter()
.map(|bin_map| bin_map.read().unwrap().len())
.sum()
}
#[test] #[test]
fn test_purge() { fn test_purge() {
let key = Keypair::new(); let key = Keypair::new();
let index = AccountsIndex::<u64>::default(); let index = AccountsIndex::<u64>::default();
let mut gc = Vec::new(); let mut gc = Vec::new();
assert!(index.upsert( assert_eq!(0, account_maps_len_expensive(&index));
index.upsert(
1, 1,
&key.pubkey(), &key.pubkey(),
&Pubkey::default(), &Pubkey::default(),
&[], &[],
&AccountSecondaryIndexes::default(), &AccountSecondaryIndexes::default(),
12, 12,
&mut gc &mut gc,
)); );
assert_eq!(1, account_maps_len_expensive(&index));
assert!(!index.upsert( index.upsert(
1, 1,
&key.pubkey(), &key.pubkey(),
&Pubkey::default(), &Pubkey::default(),
&[], &[],
&AccountSecondaryIndexes::default(), &AccountSecondaryIndexes::default(),
10, 10,
&mut gc &mut gc,
)); );
assert_eq!(1, account_maps_len_expensive(&index));
let purges = index.purge_roots(&key.pubkey()); let purges = index.purge_roots(&key.pubkey());
assert_eq!(purges, (vec![], false)); assert_eq!(purges, (vec![], false));
@ -3311,15 +3327,17 @@ pub mod tests {
let purges = index.purge_roots(&key.pubkey()); let purges = index.purge_roots(&key.pubkey());
assert_eq!(purges, (vec![(1, 10)], true)); assert_eq!(purges, (vec![(1, 10)], true));
assert!(!index.upsert( assert_eq!(1, account_maps_len_expensive(&index));
index.upsert(
1, 1,
&key.pubkey(), &key.pubkey(),
&Pubkey::default(), &Pubkey::default(),
&[], &[],
&AccountSecondaryIndexes::default(), &AccountSecondaryIndexes::default(),
9, 9,
&mut gc &mut gc,
)); );
assert_eq!(1, account_maps_len_expensive(&index));
} }
#[test] #[test]