From de9358638bb04db2b5f4823c4b05811d942b139a Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" Date: Wed, 13 Mar 2024 18:47:55 -0500 Subject: [PATCH] allow FlushStats to accumulate (#215) --- accounts-db/src/accounts_db.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/accounts-db/src/accounts_db.rs b/accounts-db/src/accounts_db.rs index eab5ca33af417c..e706958af8d0f2 100644 --- a/accounts-db/src/accounts_db.rs +++ b/accounts-db/src/accounts_db.rs @@ -1721,6 +1721,14 @@ struct FlushStats { total_size: u64, } +impl FlushStats { + fn accumulate(&mut self, other: &Self) { + saturating_add_assign!(self.num_flushed, other.num_flushed); + saturating_add_assign!(self.num_purged, other.num_purged); + saturating_add_assign!(self.total_size, other.total_size); + } +} + #[derive(Debug, Default)] struct LatestAccountsIndexRootsStats { roots_len: AtomicUsize, @@ -6078,9 +6086,7 @@ impl AccountsDb { if old_slot > max_flushed_root { if self.should_aggressively_flush_cache() { if let Some(stats) = self.flush_slot_cache(old_slot) { - flush_stats.num_flushed += stats.num_flushed; - flush_stats.num_purged += stats.num_purged; - flush_stats.total_size += stats.total_size; + flush_stats.accumulate(&stats); } } } else {