Ledger purge printing (#15176)

This commit is contained in:
sakridge 2021-02-06 15:45:08 -08:00 committed by GitHub
parent 11b84cb870
commit 774416a546
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 0 deletions

View File

@ -1,4 +1,5 @@
use super::*;
use std::time::Instant;
#[derive(Default)]
pub struct PurgeStats {
@ -47,6 +48,10 @@ impl Blockstore {
///
/// Dangerous; Use with care
pub fn purge_from_next_slots(&self, from_slot: Slot, to_slot: Slot) {
let mut count = 0;
let mut rewritten = 0;
let mut last_print = Instant::now();
let mut total_retain_us = 0;
for (slot, mut meta) in self
.slot_meta_iterator(0)
.expect("unable to iterate over meta")
@ -55,10 +60,23 @@ impl Blockstore {
break;
}
count += 1;
if last_print.elapsed().as_millis() > 2000 {
info!(
"purged: {} slots rewritten: {} retain_time: {}us",
count, rewritten, total_retain_us
);
count = 0;
rewritten = 0;
total_retain_us = 0;
last_print = Instant::now();
}
let mut time = Measure::start("retain");
let original_len = meta.next_slots.len();
meta.next_slots
.retain(|slot| *slot < from_slot || *slot > to_slot);
if meta.next_slots.len() != original_len {
rewritten += 1;
info!(
"purge_from_next_slots: meta for slot {} no longer refers to slots {:?}",
slot,
@ -70,6 +88,8 @@ impl Blockstore {
)
.expect("couldn't update meta");
}
time.stop();
total_retain_us += time.as_us();
}
}