add stats inserts, deletes, updates_in_mem (#19807)

This commit is contained in:
Jeff Washington (jwash)
2021-09-13 15:59:01 -05:00
committed by GitHub
parent ef749a2506
commit e1a038e791
2 changed files with 32 additions and 9 deletions

View File

@ -11,9 +11,11 @@ pub struct BucketMapHolderStats {
pub entries_from_mem: AtomicU64, pub entries_from_mem: AtomicU64,
pub entry_missing_us: AtomicU64, pub entry_missing_us: AtomicU64,
pub entries_missing: AtomicU64, pub entries_missing: AtomicU64,
pub updates_in_mem: AtomicU64,
pub items: AtomicU64, pub items: AtomicU64,
pub keys: AtomicU64, pub keys: AtomicU64,
pub deletes: AtomicU64, pub deletes: AtomicU64,
pub inserts: AtomicU64,
} }
impl BucketMapHolderStats { impl BucketMapHolderStats {
@ -60,6 +62,12 @@ impl BucketMapHolderStats {
self.entry_missing_us.swap(0, Ordering::Relaxed) / 1000, self.entry_missing_us.swap(0, Ordering::Relaxed) / 1000,
i64 i64
), ),
(
"updates_in_mem",
self.updates_in_mem.swap(0, Ordering::Relaxed),
i64
),
("inserts", self.inserts.swap(0, Ordering::Relaxed), i64),
("deletes", self.deletes.swap(0, Ordering::Relaxed), i64), ("deletes", self.deletes.swap(0, Ordering::Relaxed), i64),
("items", self.items.swap(0, Ordering::Relaxed), i64), ("items", self.items.swap(0, Ordering::Relaxed), i64),
("keys", self.keys.swap(0, Ordering::Relaxed), i64), ("keys", self.keys.swap(0, Ordering::Relaxed), i64),

View File

@ -90,11 +90,13 @@ impl<T: IsCached> InMemAccountsIndex<T> {
if let Entry::Occupied(index_entry) = self.entry(pubkey) { if let Entry::Occupied(index_entry) = self.entry(pubkey) {
if index_entry.get().slot_list.read().unwrap().is_empty() { if index_entry.get().slot_list.read().unwrap().is_empty() {
index_entry.remove(); index_entry.remove();
self.storage.stats.deletes.fetch_add(1, Ordering::Relaxed);
return true; return true;
} }
} }
false false
} }
pub fn upsert( pub fn upsert(
&mut self, &mut self,
pubkey: &Pubkey, pubkey: &Pubkey,
@ -111,9 +113,11 @@ impl<T: IsCached> InMemAccountsIndex<T> {
reclaims, reclaims,
previous_slot_entry_was_cached, previous_slot_entry_was_cached,
); );
Self::update_stat(&self.storage.stats.updates_in_mem, 1);
} }
Entry::Vacant(vacant) => { Entry::Vacant(vacant) => {
vacant.insert(new_value); vacant.insert(new_value);
Self::update_stat(&self.storage.stats.inserts, 1);
} }
} }
} }
@ -212,19 +216,30 @@ impl<T: IsCached> InMemAccountsIndex<T> {
pubkey: Pubkey, pubkey: Pubkey,
new_entry: AccountMapEntry<T>, new_entry: AccountMapEntry<T>,
) -> Option<(WriteAccountMapEntry<T>, T, Pubkey)> { ) -> Option<(WriteAccountMapEntry<T>, T, Pubkey)> {
let account_entry = self.entry(pubkey); let result = match self.entry(pubkey) {
match account_entry { Entry::Occupied(account_entry) => {
Entry::Occupied(account_entry) => Some(( Some((
WriteAccountMapEntry::from_account_map_entry(account_entry.get().clone()), WriteAccountMapEntry::from_account_map_entry(account_entry.get().clone()),
// extract the new account_info from the unused 'new_entry' // extract the new account_info from the unused 'new_entry'
new_entry.slot_list.write().unwrap().remove(0).1, new_entry.slot_list.write().unwrap().remove(0).1,
*account_entry.key(), *account_entry.key(),
)), ))
}
Entry::Vacant(account_entry) => { Entry::Vacant(account_entry) => {
account_entry.insert(new_entry); account_entry.insert(new_entry);
None None
} }
} };
let stats = self.stats();
Self::update_stat(
if result.is_none() {
&stats.inserts
} else {
&stats.updates_in_mem
},
1,
);
result
} }
fn stats(&self) -> &BucketMapHolderStats { fn stats(&self) -> &BucketMapHolderStats {