Skip to content

Commit

Permalink
feat(pruning): remove manual vaccum; add migration configuring autova…
Browse files Browse the repository at this point in the history
…cuum (#1983)

Signed-off-by: tomg10 <[email protected]>
  • Loading branch information
tomg10 authored May 20, 2024
1 parent 32d344c commit 3d98072
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 44 deletions.

This file was deleted.

21 changes: 0 additions & 21 deletions core/lib/dal/src/pruning_dal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,25 +443,4 @@ impl PruningDal<'_, '_> {
.await?;
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 FREEZE 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(())
}
}
12 changes: 1 addition & 11 deletions core/node/db_pruner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{fmt, sync::Arc, time::Duration};
use anyhow::Context as _;
use async_trait::async_trait;
use serde::Serialize;
use tokio::{sync::watch, time::Instant};
use tokio::sync::watch;
use zksync_dal::{pruning_dal::PruningInfo, Connection, ConnectionPool, Core, CoreDal};
use zksync_health_check::{Health, HealthStatus, HealthUpdater, ReactiveHealthCheck};
use zksync_types::{L1BatchNumber, L2BlockNumber};
Expand Down Expand Up @@ -272,7 +272,6 @@ impl DbPruner {
.collect::<Vec<_>>()
);

let mut last_vacuum_time = Instant::now();
while !*stop_receiver.borrow_and_update() {
if let Err(err) = self.update_l1_batches_metric().await {
tracing::warn!("Error updating DB pruning metrics: {err:?}");
Expand All @@ -294,15 +293,6 @@ impl DbPruner {
Ok(pruning_done) => !pruning_done,
};

if Instant::now().duration_since(last_vacuum_time) > Duration::from_secs(24 * 3600) {
let mut storage = self.connection_pool.connection_tagged("db_pruner").await?;
storage
.pruning_dal()
.run_vacuum_after_hard_pruning()
.await?;
last_vacuum_time = Instant::now();
}

if should_sleep
&& tokio::time::timeout(next_iteration_delay, stop_receiver.changed())
.await
Expand Down

0 comments on commit 3d98072

Please sign in to comment.