From 90d2a00a2da0b9baf9c5bdb95420ab933148cb66 Mon Sep 17 00:00:00 2001 From: Alexey Shekhirin Date: Tue, 15 Aug 2023 18:19:52 +0100 Subject: [PATCH] fix(pruner): percentage progress (#4197) --- crates/prune/src/pruner.rs | 8 ++------ .../storage/provider/src/providers/database/provider.rs | 6 +++--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/crates/prune/src/pruner.rs b/crates/prune/src/pruner.rs index dda0304d3..e39cd5b4c 100644 --- a/crates/prune/src/pruner.rs +++ b/crates/prune/src/pruner.rs @@ -240,16 +240,14 @@ impl Pruner { }; let total = range.clone().count(); - let mut processed = 0; provider.prune_table_with_iterator_in_batches::( 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 Pruner { }; let total = range.clone().count(); - let mut processed = 0; provider.prune_table_with_range_in_batches::( 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" ); }, diff --git a/crates/storage/provider/src/providers/database/provider.rs b/crates/storage/provider/src/providers/database/provider.rs index 2f122fbe2..ba1474afd 100644 --- a/crates/storage/provider/src/providers/database/provider.rs +++ b/crates/storage/provider/src/providers/database/provider.rs @@ -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( @@ -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)