Skip to content

fix: delete data files when cleanup retains an older tag - #8708

Merged
Xuanwo merged 1 commit into
lance-format:mainfrom
XuQianJin-Stars:fix/cleanup-tagged-orphan-data-files
Aug 23, 2026
Merged

Xuanwo merged 1 commit into
lance-format:mainfrom
XuQianJin-Stars:fix/cleanup-tagged-orphan-data-files

Conversation

@XuQianJin-Stars

@XuQianJin-Stars XuQianJin-Stars commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • cleanup_old_versions used the earliest retained manifest time as the read_dir_all cutoff. A tag on an old version pulled that cutoff backwards, so data files from newer deleted versions were never listed.
  • After those versions' manifests were removed, the skipped data files became permanent orphans. Same hole already existed for _indices/ and was fixed there; this applies the same rule to data / tx / deletions.
  • When a deleted manifest is newer than the earliest retained one, drop the cutoff and scan the subtree. Suffix-only cleanup keeps the original listing optimization.

Fixes #8705

flowchart TD
    A[cleanup_old_versions] --> B{Working set is a time suffix?}
    B -->|Yes: keep latest N versions| C[Scan files with last_modified <= earliest retained]
    C --> D[Delete unreferenced data / tx / deletions]
    B -->|No: tag keeps an older version| E[Deleted versions can be newer than the tag]
    E --> F[Old cutoff skips those newer data files]
    F --> G[Manifests are still removed]
    G --> H[Data files become permanent orphans]
    E --> I[New: drop unmodified_since cutoff]
    I --> D
Loading

Test plan

  • cleanup_deletes_data_files_newer_than_tagged_version — overwrite replaces files, tag v1, cleanup deletes the intermediate version's data file
  • dataset::cleanup::tests (43 tests)
  • cargo fmt --all
  • cargo check -p lance --tests
  • cargo clippy -p lance --tests --benches -- -D warnings

A tag on an old version pulled the listing cutoff backwards, so newer
deleted versions' data files were never scanned and became permanent
orphans after their manifests were removed.

Fixes lance-format#8705
@github-actions github-actions Bot added the bug Something isn't working label Aug 22, 2026

@lance-gatekeeper lance-gatekeeper Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Gate recommendation: approve.

The change fixes tagged sparse-retention cleanup at the correct listing boundary: it drops the timestamp cutoff only when a removed manifest is newer than the earliest retained manifest, while existing reachability and recent-write protections remain intact.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Aug 22, 2026
@Xuanwo
Xuanwo merged commit c3a476b into lance-format:main Aug 23, 2026
42 checks passed
ggozad added a commit to ggozad/haiku.rag that referenced this pull request Oct 5, 2026
vacuum moved its cleanup cutoff back to before the oldest tag, because
lancedb's optimize() hard-errors on a tagged version in the cleanup
window. Every version written after a tag was kept, and each compaction
added files that could not be removed: a tag, 8 single-document writes
with auto-vacuum, then vacuum(0) left 191.6 MB and 38 versions of
documents against 25.0 MB and 1 without the tag.

Every table's maintenance now runs through lance, ending in
cleanup_old_versions(error_if_tagged_old_versions=False), which keeps
the tagged versions and removes the others with their files
(lance-format/lance#8708, in pylance 11 and 12). The same case leaves
41.0 MB and 2 versions. optimize() is no longer called: its cleanup
defaults to 7 days.
Xuanwo added a commit that referenced this pull request Oct 23, 2026
## Summary

- `cleanup_old_versions` clamped its `data/` listing to
`earliest_retained_manifest_time`. That floor is only sound for a file
owned by a manifest being removed; a file owned by *no* manifest —
abandoned `write_fragments()` output — has an mtime unrelated to it.
- Such a file is documented to be removed on its age, but it was never
listed, so its age was never consulted and `delete_unverified=true` had
no effect on it.
- When every aged version is retained (e.g. pinned by a tag) no manifest
is deleted, so #8708's escape hatch cannot fire and the floor never
advances: the orphan is collected by no run at all.
- The `data/` listing now runs through the moving unverified threshold —
`earliest_retained.max(verification_threshold)` — and drops the cutoff
entirely under `delete_unverified`, where a file is a candidate at any
age. `CleanupInspection::listing_unmodified_since` is unchanged, so
#8708's sparse-retain case and the other listings behave exactly as
before.
- This restores an advancing cutoff, which is what the listing had
before #4614 (the caller's `now - older_than`, per #8516). #8516 and
#8705 reported the tagged facet of the same clamp and #8708 fixed it;
this is the facet left over, reachable with no tag at all.
- Documents the contract the change relies on, which the Rust API and
the guide had drifted from: an unverifiable file is removed once it is
at least 7 days old, that threshold is fixed and independent of
`older_than`, and `delete_unverified` removes the age protection
entirely and requires that no other process is operating on the dataset.
The Python docstring already said this.
- Adds `cleanup_deletes_aged_orphan_newer_than_retained_manifests`,
covering both paths: an aged orphan under the default policy, and a
fresh orphan under `delete_unverified`. Both are written after every
manifest, under suffix-only retention with no tag anywhere.

`_transactions/` and `_deletions/` are clamped the same way and can
strand a file for the same reason. Left for a follow-up so each gets its
own regression test rather than widening destructive discovery across
four subtrees at once.

Fixes #8942

## Test plan

- [x] `cargo fmt --all --check` — clean
- [x] `cargo check -p lance --tests` — clean
- [x] `cargo clippy -p lance --tests -- -D warnings` — clean
- [x] `cargo test -p lance --lib dataset::cleanup` — 46 passed, 0
failed, including both new cases and #8708's
`cleanup_deletes_data_files_newer_than_tagged_version`
- [x] Mutation check: reverting the `data/` cutoff to `unmodified_since`
fails `case_1_aged`; removing only the `delete_unverified` arm fails
`case_2_delete_unverified`. Each case is gated on the branch it covers,
and no other test changes outcome.

---------

Co-authored-by: Jennifer Mell <[email protected]>
Co-authored-by: Xuanwo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working K-approved Latest Gatekeeper recommendation permits acceptance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants