Skip to content

Commit

Permalink
fix(pruner): percentage progress (paradigmxyz#4197)
Browse files Browse the repository at this point in the history
  • Loading branch information
shekhirin authored and alessandromazza98 committed Aug 19, 2023
1 parent 7c2ce14 commit 335dc45
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
8 changes: 2 additions & 6 deletions crates/prune/src/pruner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
},
Expand Down Expand Up @@ -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"
);
},
Expand Down
6 changes: 3 additions & 3 deletions crates/storage/provider/src/providers/database/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,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>(
Expand All @@ -658,12 +658,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)
Expand Down

0 comments on commit 335dc45

Please sign in to comment.