Skip to content

Commit

Permalink
vacuum sqlite after pruning data (#2697)
Browse files Browse the repository at this point in the history
* vaccum sqlite database

* use pruned height table for opening sqlite write txn

* move vacuum after each batch delete
  • Loading branch information
imabdulbasit authored Feb 27, 2025
1 parent 4162475 commit 06c7f62
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions hotshot-query-service/src/data_source/storage/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,13 @@ impl PruneStorage for SqlStorage {
}
}

#[cfg(feature = "embedded-db")]
{
let mut conn = self.pool().acquire().await?;
query("VACUUM").execute(conn.as_mut()).await?;
conn.close().await?;
}

// If threshold is set, prune data exceeding minimum retention in batches
// This parameter is needed for SQL storage as there is no direct way to get free space.
if let Some(threshold) = cfg.pruning_threshold() {
Expand Down Expand Up @@ -765,6 +772,13 @@ impl PruneStorage for SqlStorage {
message: format!("failed to commit {e}"),
})?;

#[cfg(feature = "embedded-db")]
{
let mut conn = self.pool().acquire().await?;
query("VACUUM").execute(conn.as_mut()).await?;
conn.close().await?;
}

pruner.pruned_height = Some(height);

return Ok(Some(height));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl TransactionMode for Write {
// statement that has no actual effect on the database is suitable for this purpose, hence
// the `WHERE false`.
#[cfg(feature = "embedded-db")]
conn.execute("UPDATE header SET height = height WHERE false")
conn.execute("UPDATE pruned_height SET id = id WHERE false")
.await?;

// With Postgres things are much more straightforward: just tell Postgres we want a write
Expand Down

0 comments on commit 06c7f62

Please sign in to comment.