Skip to content

cleanup_old_versions never lists unreferenced data files newer than the oldest retained manifest #8942

Description

@jennifermell

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:

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

Logs / traceback

Activity

  1. added
    bug
    on Sep 2, 2026
  2. added a commit that references this issue on Sep 15, 2026
    29f5f81
  3. added a commit that references this issue on Oct 23, 2026
    53be381
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions