Home / Data Platform / Lakehouse

Data PlatformRunbookAdvanced

Sev1: VACUUM RETAIN 0 HOURS on a live Delta table broke readers, streams and time travel

Someone vacuumed a Delta table with zero retention. Running queries and streams fail with FileNotFoundException and time travel is gone. Stop further vacuums, restore files from storage soft delete, repair the log.

Deepak Bhardwaj6 min read

Applies toDelta Lake 2.x-4.x on Apache Spark, Databricks Runtime (Azure, AWS, GCP); ADLS Gen2 and Amazon S3 storage

Symptoms

  • Jobs and streaming queries that were running against the table fail with java.io.FileNotFoundException or a Databricks error that mentions files referenced in the transaction log that cannot be found.
  • SELECT ... VERSION AS OF or TIMESTAMP AS OF for any older version fails, and RESTORE TABLE to an earlier version fails for the same reason.
  • DESCRIBE HISTORY shows VACUUM START / VACUUM END entries a few minutes before the first failure.
  • Someone set spark.databricks.delta.retentionDurationCheck.enabled = false in a notebook or job to get past the safety check.

VACUUM with a short retention deletes data files that are no longer in the latest snapshot. Readers still on an older snapshot, streams behind the head of the log, and concurrent writers that started before the vacuum all lose files they need. Time travel to any version older than the retention window can no longer work.

Caution

VACUUM physically deletes files. Delta Lake cannot bring them back. Your only routes back are storage-level soft delete or versioning, a deep clone, a backup, or reprocessing from source. Check soft delete first: the retention clock is already running.

1. Confirm scope and impact

Find the vacuum and what it removed:

DESCRIBE HISTORY prod.sales.orders LIMIT 20;

Look at operation, timestamp, userName and operationMetrics on the VACUUM END row (numDeletedFiles, numVacuumedDirectories). VACUUM shows up in history when vacuum logging is on. That is the default on Databricks; on open-source Delta it depends on spark.databricks.delta.vacuum.logging.enabled.

Check whether the current version still reads:

SELECT COUNT(*) FROM prod.sales.orders;

If this works, the latest snapshot is intact. Only older snapshots, lagging streams and failed concurrent writes are hit. That is the common case and the impact is smaller. If it fails, a writer committed while the vacuum ran, or the vacuum targeted the wrong path. Treat the table as corrupted.

List the other tables the same notebook or job vacuumed. Engineers often loop over a whole schema:

-- Databricks: find recent VACUUM commands (system tables must be enabled)
SELECT event_time, user_identity.email, request_params
FROM system.access.audit
WHERE action_name = 'commandSubmit'
  AND request_params.commandText ILIKE '%vacuum%retain%'
  AND event_time > current_timestamp() - INTERVAL 1 DAY;

Audit event names and fields vary by workspace configuration and release. If this returns nothing, check the notebook revision history or the job run output.

2. Stop it getting worse

  1. Pause the job or notebook schedule that ran the vacuum. Remove the retentionDurationCheck.enabled = false setting from its code and cluster config.
  2. Pause downstream jobs that would publish partial results from failed or retried reads.
  3. Do not run another VACUUM, OPTIMIZE or bulk DELETE on the affected tables until recovery is done. Those operations create more unreferenced files and make the restore harder to reason about.

3. Recover deleted files from storage (best option)

If soft delete or versioning was on, the deleted Parquet files can be undeleted in place. The transaction log still references them by their original paths, so restored files fix older versions and lagging streams immediately.

ADLS Gen2 with blob soft delete (hierarchical namespace accounts support soft delete; check the current feature support for your account):

# List soft-deleted blobs under the table path
az storage blob list --account-name <acct> --container-name <container> \
  --prefix "sales/orders/" --include d --auth-mode login \
  --query "[?deleted].name" -o tsv > deleted.txt

# Undelete each one
while read -r blob; do
  az storage blob undelete --account-name <acct> --container-name <container> \
    --name "$blob" --auth-mode login
done < deleted.txt

Amazon S3 with versioning: remove the delete markers created by the vacuum:

aws s3api list-object-versions --bucket <bucket> --prefix sales/orders/ \
  --query 'DeleteMarkers[?IsLatest==`true`].[Key,VersionId]' --output text |
while read -r key vid; do
  aws s3api delete-object --bucket <bucket> --key "$key" --version-id "$vid"
done

Warning

Scope the restore to the vacuum window. Files deleted by earlier, legitimate vacuums should normally stay deleted. Filter by deletion time (deletedOn in the Azure listing, LastModified on S3 delete markers) before you undelete.

Then verify:

SELECT COUNT(*) FROM prod.sales.orders VERSION AS OF <version_before_vacuum>;

4. No soft delete: repair and reload

If the files are gone for good, decide per table.

Situation Action
Latest version reads fine, only history lost Accept the loss of time travel. Restart streams (below). Record the incident.
Latest version fails with missing files Restore from a deep clone or backup if you have one, or rebuild from source / bronze
No backup, a source replay is possible Rebuild the table from source for the affected partitions
No backup, no source On Databricks, use FSCK REPAIR TABLE to drop references to the missing files, then reconcile counts with data owners

On Databricks, preview the repair before you run it:

FSCK REPAIR TABLE prod.sales.orders DRY RUN;
FSCK REPAIR TABLE prod.sales.orders;

Caution

FSCK REPAIR TABLE removes file entries from the log. The table then reads, but the rows in those files are gone from it. Use it only after storage recovery has failed, and record what was lost.

As a last resort, a reader can skip missing files for a one-off extract: SET spark.sql.files.ignoreMissingFiles = true. Never leave it on in production jobs, because it hides data loss.

Restart streaming readers

A stream that was reading a version whose files are gone fails again on every restart. If storage recovery worked, restart it as usual. If not, start a new checkpoint at the current version and backfill the gap in batch:

(spark.readStream.format("delta")
   .option("startingVersion", "<current_version>")
   .table("prod.sales.orders")
   .writeStream
   .option("checkpointLocation", "abfss://chk@<acct>.dfs.core.windows.net/orders_v2")
   .toTable("prod.sales.orders_silver"))

5. Verify recovery

  • DESCRIBE HISTORY shows no new VACUUM entries since the incident.
  • The current version and the last good version both read without errors.
  • Streams are running and their lag is falling.
  • Row counts for the affected partitions match source or the last good report.

Communicate

Tell data consumers which tables failed, for how long, and whether time travel before the vacuum is still available. If you ran FSCK REPAIR TABLE, give the row and partition ranges that were lost and the plan to backfill them.

Prevent it next time

  • Keep the default retention (7 days) or longer. Set it on the table so a session-level RETAIN cannot go lower without tripping the check:
ALTER TABLE prod.sales.orders SET TBLPROPERTIES (
  'delta.deletedFileRetentionDuration' = 'interval 7 days',
  'delta.logRetentionDuration' = 'interval 30 days');
  • Block spark.databricks.delta.retentionDurationCheck.enabled in cluster policies, and treat it in code review the same way as rm -rf.
  • Turn on soft delete (ADLS) or versioning (S3) for lake storage, with a retention longer than your incident response time.
  • Run VACUUM ... DRY RUN first in any manual maintenance, and let predictive optimization or a single owned maintenance job handle routine vacuums.
  • Keep deep clones of critical gold tables. See Delta Lake backup and recovery.