Skip to content

Commit

Permalink
feat(en): add manual vacuum step in db pruning (#1652)
Browse files Browse the repository at this point in the history
Signed-off-by: tomg10 <lemures64@gmail.com>
  • Loading branch information
tomg10 committed Apr 12, 2024
1 parent 5ed92b9 commit c818be3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 22 additions & 1 deletion core/lib/dal/src/pruning_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ impl PruningDal<'_, '_> {
i64::from(last_miniblock_to_prune.0),
PruneType::Hard as PruneType
)
.instrument("soft_prune_batches_range#insert_pruning_log")
.instrument("hard_prune_batches_range#insert_pruning_log")
.with_arg("last_l1_batch_to_prune", &last_l1_batch_to_prune)
.with_arg("last_miniblock_to_prune", &last_miniblock_to_prune)
.with_arg("prune_type", &PruneType::Hard)
Expand All @@ -414,4 +414,25 @@ impl PruningDal<'_, '_> {

Ok(())
}

// This method must be separate as VACUUM is not supported inside a transaction
pub async fn run_vacuum_after_hard_pruning(&mut self) -> DalResult<()> {
sqlx::query!(
r#"
VACUUM l1_batches,
miniblocks,
storage_logs,
events,
call_traces,
l2_to_l1_logs,
transactions
"#,
)
.instrument("hard_prune_batches_range#vacuum")
.report_latency()
.execute(self.storage)
.await?;

Ok(())
}
}
6 changes: 6 additions & 0 deletions core/lib/zksync_core/src/db_pruner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ impl DbPruner {

transaction.commit().await?;

let mut storage = pool.connection_tagged("db_pruner").await?;
storage
.pruning_dal()
.run_vacuum_after_hard_pruning()
.await?;

let latency = latency.observe();
tracing::info!(
"Hard pruned db l1_batches up to {} and miniblocks up to {}, operation took {:?}",
Expand Down

0 comments on commit c818be3

Please sign in to comment.