feat(pruner): percentage progress and prune only if key exists (#3932)

This commit is contained in:
Alexey Shekhirin
2023-07-26 17:38:36 +01:00
committed by GitHub
parent 1c4d127488
commit 0cfc424291
2 changed files with 21 additions and 17 deletions

View File

@@ -160,14 +160,18 @@ impl<DB: Database> Pruner<DB> {
return Ok(())
}
};
let total = range.clone().count();
let mut processed = 0;
provider.prune_table_in_batches::<tables::Receipts, _>(
range,
self.batch_sizes.receipts,
|receipts| {
|entries| {
processed += entries;
trace!(
target: "pruner",
%receipts,
%entries,
progress = format!("{:.1}%", 100.0 * processed as f64 / total as f64),
"Pruned receipts"
);
},
@@ -201,6 +205,8 @@ impl<DB: Database> Pruner<DB> {
}
};
let last_tx_num = *range.end();
let total = range.clone().count();
let mut processed = 0;
for i in range.step_by(self.batch_sizes.transaction_lookup) {
// The `min` ensures that the transaction range doesn't exceed the last transaction
@@ -223,19 +229,16 @@ impl<DB: Database> Pruner<DB> {
}
// Pre-sort hashes to prune them in order
hashes.sort();
hashes.sort_unstable();
provider.prune_table_in_batches::<tables::TxHashNumber, _>(
hashes,
self.batch_sizes.transaction_lookup,
|entries| {
trace!(
target: "pruner",
%entries,
"Pruned transaction lookup"
);
},
)?;
let entries = provider.prune_table::<tables::TxHashNumber, _>(hashes)?;
processed += entries;
trace!(
target: "pruner",
%entries,
progress = format!("{:.1}%", 100.0 * processed as f64 / total as f64),
"Pruned transaction lookup"
);
}
provider.save_prune_checkpoint(

View File

@@ -640,7 +640,7 @@ impl<'this, TX: DbTxMut<'this> + DbTx<'this>> DatabaseProvider<'this, TX> {
&self,
keys: impl IntoIterator<Item = K>,
batch_size: usize,
batch_callback: impl Fn(usize),
mut batch_callback: impl FnMut(usize),
) -> std::result::Result<usize, DatabaseError>
where
T: Table<Key = K>,
@@ -650,8 +650,9 @@ impl<'this, TX: DbTxMut<'this> + DbTx<'this>> DatabaseProvider<'this, TX> {
let mut deleted = 0;
for key in keys {
cursor.seek_exact(key)?;
cursor.delete_current()?;
if cursor.seek_exact(key)?.is_some() {
cursor.delete_current()?;
}
deleted += 1;
if deleted % batch_size == 0 {