Repository navigation
Description
Description
When listing unreferenced files to delete, the data/ listing is restricted to files modified before listing_unmodified_since(), which is the earliest_retained_manifest_time unless a manifest being deleted is newer than it.
#8708 dropped that cutoff for sparse retention and deliberately kept it otherwise ("Suffix-only cleanup keeps the original listing optimization"), on the invariant that "every retained version is newer than every deleted one". That invariant holds for files owned by a deleted version — they were written before the retained floor. It does not hold for files owned by no version: output of an abandoned write_fragments() is written whenever the writer ran, which may be after the oldest retained manifest. Those files are never deletion candidates, and cleanup is documented to collect them:
//! * Unreferenced data files - If a data file is not referenced by any
//! fragment in a valid manifest file then it will be deleted.
...
//! If the data is not referenced by any manifest then we look at the age of
//! the file. If the file is at least 7 days old then we assume it is probably
//! not part of any ongoing operation and we will delete it.
The documented criterion is the file's age. delete_unverified=True does not help either: the file is never listed, so its age is never consulted.
An advancing cutoff is also what this code had before #4614, as noted in #8516: the listing was filtered by the caller's before cutoff (now - older_than), which moves forward on every run. #8516 and #8705 both reported the tagged facet of this clamp; #8708 fixed that facet — #8516 is fixed in 11.0.0 but still open — and this is the facet it left, reachable with no tag at all.
Two consequences, in increasing severity:
- With suffix-only retention, an orphan is skipped until the retention floor advances past its mtime — a delay, and one that silently ignores
delete_unverified=True. - When every aged version is retained (e.g. pinned by tags), no manifest is deleted, so fix: delete data files when cleanup retains an older tag #8708's escape hatch cannot fire and the floor never advances. Those orphans are never collected by any run — the permanent leak of cleanup_old_versions on a tagged dataset removes manifests but strands their data files (permanent, silent leak) #8705, reached by a path its fix does not cover.
Output of the reproducer:
retained floor is newer than the orphan: False
stats.old_versions 3
stats.data_files_removed 0
orphan still on disk True
retained floor is newer than the orphan: True
stats.old_versions 4
stats.data_files_removed 1
orphan still on disk False
Note the first case is suffix-only retention with three versions actually deleted, and no tag anywhere.
Steps to reproduce
import datetime
import tempfile
import time
import uuid
from pathlib import Path
import lance
import pyarrow as pa
for advance_floor in (False, True):
with tempfile.TemporaryDirectory() as tmp:
path = Path(tmp) / "ds.lance"
table = pa.table({"i": pa.array(range(64))})
lance.write_dataset(table, path)
for _ in range(3):
lance.write_dataset(table, path, mode="append")
time.sleep(1.1) # the orphan is newer than every manifest written so far
orphan = path / "data" / f"{uuid.uuid4()}.lance"
orphan.write_bytes(b"x" * 4096)
if advance_floor:
time.sleep(1.1)
lance.write_dataset(table, path, mode="append") # newer than the orphan
stats = lance.dataset(path).cleanup_old_versions(
older_than=datetime.timedelta(0),
delete_unverified=True,
error_if_tagged_old_versions=False,
)
print(f"retained floor is newer than the orphan: {advance_floor}")
print(f" stats.old_versions {stats.old_versions}")
print(f" stats.data_files_removed {stats.data_files_removed}")
print(f" orphan still on disk {orphan.exists()}\n")Expected behavior
An unreferenced data file is a deletion candidate on its age, regardless of where its mtime falls relative to the retained floor, so both cases should reclaim it:
retained floor is newer than the orphan: False
stats.old_versions 3
stats.data_files_removed 1
orphan still on disk False
Lance version
11.0.0
Language binding
Python
Environment
macOS 26.6.2, arm64, local
Activity
fix: collect unreferenced data newer than retained manifests (#8944)
fix: list unreferenced data files newer than the retained floor (#8945)