Skip to content

Commit

Permalink
fix some ancient stats (solana-labs#33791)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington authored Oct 23, 2023
1 parent 34103e0 commit a41b24f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
26 changes: 16 additions & 10 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2041,7 +2041,7 @@ pub(crate) struct ShrinkAncientStats {
pub(crate) random_shrink: AtomicU64,
pub(crate) slots_considered: AtomicU64,
pub(crate) ancient_scanned: AtomicU64,
pub(crate) second_pass_one_ref: AtomicU64,
pub(crate) bytes_ancient_created: AtomicU64,
}

#[derive(Debug, Default)]
Expand Down Expand Up @@ -2072,7 +2072,7 @@ impl ShrinkStatsSub {
#[derive(Debug, Default)]
pub struct ShrinkStats {
last_report: AtomicInterval,
num_slots_shrunk: AtomicUsize,
pub(crate) num_slots_shrunk: AtomicUsize,
storage_read_elapsed: AtomicU64,
index_read_elapsed: AtomicU64,
create_and_insert_store_elapsed: AtomicU64,
Expand Down Expand Up @@ -2346,8 +2346,8 @@ impl ShrinkAncientStats {
i64
),
(
"second_pass_one_ref",
self.second_pass_one_ref.swap(0, Ordering::Relaxed) as i64,
"bytes_ancient_created",
self.bytes_ancient_created.swap(0, Ordering::Relaxed) as i64,
i64
),
);
Expand Down Expand Up @@ -4204,14 +4204,20 @@ impl AccountsDb {
);
}

Self::update_shrink_stats(&self.shrink_stats, stats_sub);
Self::update_shrink_stats(&self.shrink_stats, stats_sub, true);
self.shrink_stats.report();
}

pub(crate) fn update_shrink_stats(shrink_stats: &ShrinkStats, stats_sub: ShrinkStatsSub) {
shrink_stats
.num_slots_shrunk
.fetch_add(1, Ordering::Relaxed);
pub(crate) fn update_shrink_stats(
shrink_stats: &ShrinkStats,
stats_sub: ShrinkStatsSub,
increment_count: bool,
) {
if increment_count {
shrink_stats
.num_slots_shrunk
.fetch_add(1, Ordering::Relaxed);
}
shrink_stats.create_and_insert_store_elapsed.fetch_add(
stats_sub.create_and_insert_store_elapsed_us,
Ordering::Relaxed,
Expand Down Expand Up @@ -4752,7 +4758,7 @@ impl AccountsDb {
// we should not try to shrink any of the stores from this slot anymore. All shrinking for this slot is now handled by ancient append vec code.
self.shrink_candidate_slots.lock().unwrap().remove(&slot);

Self::update_shrink_stats(&self.shrink_ancient_stats.shrink_stats, stats_sub);
Self::update_shrink_stats(&self.shrink_ancient_stats.shrink_stats, stats_sub, true);
}

/// each slot in 'dropped_roots' has been combined into an ancient append vec.
Expand Down
12 changes: 11 additions & 1 deletion accounts-db/src/ancient_append_vecs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl AccountsDb {
&mut stats_sub
));

Self::update_shrink_stats(&self.shrink_ancient_stats.shrink_stats, stats_sub);
Self::update_shrink_stats(&self.shrink_ancient_stats.shrink_stats, stats_sub, false);
self.shrink_ancient_stats
.total_us
.fetch_add(total_us, Ordering::Relaxed);
Expand Down Expand Up @@ -516,6 +516,9 @@ impl AccountsDb {
self.thread_pool_clean.install(|| {
packer.par_iter().for_each(|(target_slot, pack)| {
let mut write_ancient_accounts_local = WriteAncientAccounts::default();
self.shrink_ancient_stats
.bytes_ancient_created
.fetch_add(pack.bytes, Ordering::Relaxed);
self.write_one_packed_storage(
pack,
**target_slot,
Expand Down Expand Up @@ -694,6 +697,13 @@ impl AccountsDb {
INCLUDE_SLOT_IN_HASH_IRRELEVANT_APPEND_VEC_OPERATION,
);

self.shrink_ancient_stats
.bytes_ancient_created
.fetch_add(packed.bytes, Ordering::Relaxed);
self.shrink_ancient_stats
.shrink_stats
.num_slots_shrunk
.fetch_add(1, Ordering::Relaxed);
self.write_ancient_accounts(*bytes_total, accounts_to_write, write_ancient_accounts)
}

Expand Down

0 comments on commit a41b24f

Please sign in to comment.