Repository navigation
refactor(cleanup): decide file keep/delete with one rule - #10906
Merged
Xuanwo merged 2 commits intoNov 15, 2026
Merged
Conversation
Split `cleanup_file_if_not_referenced` into path classification and one verdict rule shared by every file kind, and unit test both without an object store. A verified file that is also old is now reported as verified for data, index, deletion and row-map files. Co-Authored-By: Claude Opus 5.5 <[email protected]>
wjones127
marked this pull request as ready for review
November 10, 2026 18:03
…-verdict Integrate the single keep/delete rule with main's bulk deletes (lance-format#10787), transaction and deletion orphan discovery (lance-format#10899) and the foreign-root fixture (lance-format#11095).
Xuanwo
approved these changes
Nov 15, 2026
Xuanwo
added a commit
that referenced
this pull request
Nov 15, 2026
## Summary
Cleanup decided whether a version expires in several places in
`CleanupTask` (`run` mutating `policy.before_timestamp`,
`cleanup_candidates`, `process_manifest_file`, `bucket_survivors` in
`CleanupInspection`, `CleanupPolicy::proven_expired`). The only way to
test retention semantics was to write real versions to a real dataset.
This PR moves that decision into `cleanup/expiry.rs`, which does no I/O:
```text
VersionExpiry::new(legacy filters, retention rules, now, thinning anchor, read_version)
.with_tagged(..).with_branch_held(..)
classify(version, timestamp) -> Retained | TaggedOld | Expired | Thinned(candidate)
is_old(version, timestamp) -> used to pick referenced branches to cascade into
is_expired_by_version(version) -> the delete_unverified fast path (was proven_expired)
ThinningSurvivors<T>::offer(candidate, T) / into_survivors()
```
`CleanupTask` still does the I/O: it resolves the anchor from the
version hint (now `resolve_thinning_anchor`), lists manifests, and
re-reads one survivor per bucket. Behavior is unchanged.
Answers to the issue's open questions:
- Expiry can't be decided before reading the manifest, because the
timestamp is in the manifest. Survivors are still re-read once, which
keeps memory bounded by bucket count.
- Legacy filters stay a separate input. Internally, `before_timestamp`
and `RemoveAll` combine into one cutoff, so `run` no longer mutates the
policy.
- No rename of the second `CleanupPolicy`; that's a public API change
and can be a separate PR.
## Evidence
Rule semantics (ladder, independent bands, per-period buckets, hint
anchoring, `RemoveAll` vs. samples, filters, tags, branch-held and
detached versions, the version-only fast path, out-of-range ages) are
now covered by 29 synchronous tests in `expiry::tests`, which also check
that survivors do not depend on manifest listing order. The retention
integration matrices drop from 32 cases to 8, keeping one case for each
I/O path they exercise (config parsing, hint reads, pinned snapshots,
tag/filter wiring, `delete_unverified`).
`cleanup_retention_bands_have_independent_buckets` is now only a unit
test.
Cleanup test runtime (`dataset::cleanup::`, `--test-threads=1`, debug
build, 3 runs each on the same machine, both on `1b89c0041`):
| | tests | wall time | retention + expiry tests |
|---|---|---|---|
| main | 256 | 8.83–8.89 s | 1.86 s (73 tests) |
| this PR | 255 | 7.82–8.25 s | 0.72 s (73 tests, 25 of them ~0 ms) |
Most of what's left in the cleanup suite is branch-lineage and
managed-blob I/O, which this PR doesn't touch.
Those timings are a historical measurement on `1b89c0041`; they were not
re-run on the integrated tree.
Merged with `main` at `1e6aa0b`, which includes the `file_verdict`
extraction from #10906, so both modules coexist with their `Verdict`
types aliased at the integration boundary. The expiry, retention and
`file_verdict` suites plus the workspace check, format and clippy gates
pass on the integrated tree.
## Merge Risk
**Door:** One-way in effect. This is an internal refactor with no API or
format change, but it sits on the path that deletes data, so a semantic
slip would delete versions.
**Blast Radius:** cleanup (auto-cleanup, `cleanup_old_versions`,
retention policies, branch cascade).
Fixes #10904
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Xuanwo <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cleanup_file_if_not_referencedhad a separate copy of the keep/delete rule for each file kind, and the copies had drifted. This PR splits it into two steps that apply to every kind and are unit tested without an object store:The staging-manifest authority check is now the only per-kind special case. The new code lives in
cleanup/file_verdict.rs.This also fixes the
unverifieddrift. A data, index, deletion or_frifile that is old and also referenced by an expiring manifest was reported asunverified: trueinexplain(), and the audit log recorded it asdelete_unverified. It now reports as verified, which is what transaction and_blobsfiles already did. Deletions are unchanged: the same files get deleted either way.Evidence
The new unit tests are tables over path × reference state × age: 27 cases for
classify, 7 fordecide, and 18 for key lookup. Thedecide::verified_oldcase is the regression test for the drift.Seven integration tests only checked this rule, so they are removed:
cleanup_unreferenced_data_filesdo_not_cleanup_newer_datacleanup_old_indexclean_old_delete_filesdont_clean_index_data_filesdont_cleanup_in_progress_writeorphan_map_ages_outTheir keep-side checks moved into
every_removed_file_kind_contributes_its_bytes, renamed tocleanup_keeps_and_removes_every_file_kind. It now asserts exact removed and surviving counts for every kind, so a mismatch between the keys manifests record and the keysclassifyderives from paths is still caught end to end.Per-test time from
--test-threads=1 --report-time, debug build, measured before the current-mainintegration:dataset::cleanupsuite, sum of per-test timesThe rule tests now take 60% less time, but they were already cheap. Over the whole suite the saving is within run-to-run noise. Most of the suite's time goes to
branch_lineagetests (~4.4 s), which this rule doesn't affect. Parallel wall time is unchanged at about 1.8 s.Integration
Merged
mainat57bd7ff59with no conflicts, so the rule runs on top of the landed bulk-delete path (#10787), transaction and deletion orphan discovery (#10899) and the foreign-root fixture (#11095); their code and tests are unchanged. On the merged treecargo fmt --all --check,cargo check --workspace --tests --benches --profile ci --locked,cargo clippy --all --tests --benches --profile ci --locked -- -D warningsandcargo test --workspace --profile ci --locked(23,129 passed, 0 failed) pass, as do the 52 rule cases in isolation andcleanup_keeps_and_removes_every_file_kindwith its exact per-kind counts. The timings above were not re-measured after the merge.Merge Risk
Door: Two-way. No format or API change. But a mistake in this code would delete live files, and deleted files can't be recovered.
Blast Radius: cleanup. Only the
unverifiedflag inexplain()and the audit-log mode change.Fixes #10903
🤖 Generated with Claude Code