Skip to content

cleanup_old_versions on a tagged dataset removes manifests but strands their data files (permanent, silent leak) #8705

Closed

Description

@chrisblaschke

Verified on a production store on 2026-08-21 with pylance 10.0.0
and lancedb 0.37.1, Linux, local filesystem store. The store carries 18.4 GB of data
files that no manifest names — 40.9% of all data bytes across 212 tables.

Summary

When a dataset carries any tag, cleanup_old_versions() removes the old manifests and
their transaction files but does not remove the data files those versions owned. The
call reports the manifest bytes as freed. The data files stay on disk forever: after their
manifests are gone, no version references them, so no later cleanup can ever find them
either. The leak is silent and permanent, and it scales with write volume.

With no tag present, the same call deletes the data files as expected. The tag is the
trigger.

Minimal repro

The trigger needs a version whose files are later REPLACED, so the repro compacts once.
Copy-paste; it runs in about a second.

import datetime, time
import lance, pyarrow as pa
from pathlib import Path

uri = "/tmp/lance-tag-orphan/t.lance"
Path(uri).parent.mkdir(parents=True, exist_ok=True)

def files():
    return sorted(p.name for p in (Path(uri) / "data").iterdir())

lance.write_dataset(pa.table({"i": pa.array([0], pa.int64())}), uri, mode="overwrite")
for i in range(1, 6):
    lance.write_dataset(pa.table({"i": pa.array([i], pa.int64())}), uri, mode="append")
lance.dataset(uri).optimize.compact_files()      # 6 small files -> 1 compacted file

ds = lance.dataset(uri)
ds.tags.create("keepme", 2)                      # ANY tag, on ANY version
print("versions", len(ds.versions()), "files", len(files()))

time.sleep(1.1)
stats = lance.dataset(uri).cleanup_old_versions(
    older_than=datetime.timedelta(seconds=0), error_if_tagged_old_versions=False
)
print("removed versions", stats.old_versions, "bytes freed", stats.bytes_removed)

ds2 = lance.dataset(uri)
ref = set()
for v in [v["version"] for v in ds2.versions()]:
    ref |= {f.path() for fr in lance.dataset(uri, version=v).get_fragments() for f in fr.data_files()}
print("versions now", len(ds2.versions()), "files now", len(files()),
      "orphaned", len(set(files()) - ref), "rows", ds2.count_rows())

Observed (pylance 10.0.0):

versions 8 files 7
removed versions 6 bytes freed 3660
versions now 2 files now 7 orphaned 4 rows 6

Six versions were removed and 3,660 bytes were reported freed — manifests and transaction
files only. No data file was deleted, and four of the seven files on disk are now
referenced by no version at all. They can never be collected again.

The control isolates the tag. Delete it and run the same cleanup:

lance.dataset(uri).tags.delete("keepme")
stats = lance.dataset(uri).cleanup_old_versions(
    older_than=datetime.timedelta(seconds=0), error_if_tagged_old_versions=False
)
# control: removed 1 bytes 1223 -> versions now 1, files now 5, rows 6

With no tag in the way, removing a version DOES delete the data files it held (7 files ->
5). The four files stranded by the tagged run stay stranded.

Production evidence

A byte-for-byte copy of a 3.656 GB production table (1,858 files, 457 versions, two tags):

  1. cleanup_old_versions(older_than=1s, error_if_tagged_old_versions=False) with the tags
    present: removed 454 versions, freed 4,858,603 B — manifests and transactions only.
    Files on disk 1,858 before and 1,858 after. Files referenced by no retained version:
    1,410 before, 1,855 after. The call created 445 new orphans.
  2. Both tags deleted, same call: removed the 2 remaining tagged versions and freed
    190,169,973 B, deleting exactly the 2 data files those versions held.
  3. End state: 1 version, 1,856 files, 1,855 orphaned — 3.370 GB of garbage around a 95 MB
    live file.

Store-wide, a reachability census of 212 tables found 18.382 GB in 3,273 unreferenced data
files plus 7.379 GB of _indices/<uuid>/ directories that no version references. Index
directories leak the same way.

Why it matters

  • The bytes are unrecoverable through the Lance API. Once the manifests are gone, nothing
    in Lance knows the files exist, so cleanup_old_versions can never collect them. The
    only fix is an out-of-band reachability sweep (ours: a
    quarantine-then-verify reachability sweep, never unlink).
  • The leak is invisible. bytes_removed reports success, count_rows() is correct, and
    every query works. Only du disagrees.
  • Tags are cheap to create and nothing expires them, so a store that uses tags as restore
    points leaks proportionally to its write rate.

What we would expect

Either of these would have prevented 18 GB of garbage:

  • cleanup_old_versions deletes the data files of every version it removes, tag or no tag
    (a tagged version's own files are of course retained), or
  • the call refuses to remove a version whose files it will not delete, so the operator
    sees the trade instead of silently paying it.

A third, weaker option: report the stranded bytes in CleanupStats so the leak is at
least observable.

Environment

  • pylance 10.0.0, lancedb 0.37.1, Python 3.11, Linux 6.x, ext4, local (non-object) store
  • datasets in storage format 2.1, written by lancedb AsyncTable upserts and compactions
  • tags created by our own maintenance scripts as pre-change restore points

Activity

  1. added a commit that references this issue on Aug 23, 2026
    c3a476b
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions