fix(pruner): percentage progress (#4197)

This commit is contained in:
Alexey Shekhirin
2023-08-15 18:19:52 +01:00
committed by GitHub
parent 981873dca9
commit 90d2a00a2d
2 changed files with 5 additions and 9 deletions

View File

@ -240,16 +240,14 @@ impl<DB: Database> Pruner<DB> {
};
let total = range.clone().count();
let mut processed = 0;
provider.prune_table_with_iterator_in_batches::<tables::Receipts>(
range,
self.batch_sizes.receipts,
|rows| {
processed += rows;
trace!(
target: "pruner",
%rows,
progress = format!("{:.1}%", 100.0 * processed as f64 / total as f64),
progress = format!("{:.1}%", 100.0 * rows as f64 / total as f64),
"Pruned receipts"
);
},
@ -348,16 +346,14 @@ impl<DB: Database> Pruner<DB> {
};
let total = range.clone().count();
let mut processed = 0;
provider.prune_table_with_range_in_batches::<tables::TxSenders>(
range,
self.batch_sizes.transaction_senders,
|rows, _| {
processed += rows;
trace!(
target: "pruner",
%rows,
progress = format!("{:.1}%", 100.0 * processed as f64 / total as f64),
progress = format!("{:.1}%", 100.0 * rows as f64 / total as f64),
"Pruned transaction senders"
);
},

View File

@ -630,7 +630,7 @@ impl<'this, TX: DbTxMut<'this> + DbTx<'this>> DatabaseProvider<'this, TX> {
}
/// Prune the table for the specified pre-sorted key iterator, calling `chunk_callback` after
/// every `batch_size` pruned rows.
/// every `batch_size` pruned rows with number of total rows pruned.
///
/// Returns number of rows pruned.
pub fn prune_table_with_iterator_in_batches<T: Table>(
@ -649,12 +649,12 @@ impl<'this, TX: DbTxMut<'this> + DbTx<'this>> DatabaseProvider<'this, TX> {
deleted += 1;
if deleted % batch_size == 0 {
batch_callback(batch_size);
batch_callback(deleted);
}
}
if deleted % batch_size != 0 {
batch_callback(deleted % batch_size);
batch_callback(deleted);
}
Ok(deleted)