Repository navigation
fix(cleanup): list transaction and deletion orphans newer than the oldest retained version - #10899
Conversation
…ed deletion file in the test
wjones127
left a comment
There was a problem hiding this comment.
Thanks, this is a clean follow-up to #8945. Every listed file still goes through the maybe_in_progress age check, so this only changes which files reach it, and dropping skipped_expired_manifest_read is safe now that all four listings share the delete_unverified bypass. One non-blocking test suggestion inline.
| // The two expired versions' transaction files, and the orphan. | ||
| assert_eq!(removed.transaction_files_removed, 3); | ||
| assert_eq!(removed.deletion_files_removed, 1); | ||
| for orphan in &orphans { |
There was a problem hiding this comment.
suggestion: Both cases expect the orphans to be deleted. Could we add a case for the other side, e.g. #[case::fresh(false, 4)], where the default policy keeps the day-3 txn and deletion orphans (transaction_files_removed == 2, deletion_files_removed == 0, orphans still exist)?
Before this PR, those files were safe only because they were never listed. Now their safety depends on the new cutoff plus maybe_in_progress, and that's the property where a mistake loses data.
There was a problem hiding this comment.
Added case::fresh. With only the day-3 orphans it would pass even without the maybe_in_progress check, because in that case they are newer than the cutoff and cleanup never lists them. So the test now also writes a set of orphans before the oldest retained version, which every case lists, and fresh keeps those only through maybe_in_progress. Skipping that check for either transaction or deletion files makes fresh fail.
…ewer-txn-deletion-orphans
…-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).
## Summary
`cleanup_file_if_not_referenced` had 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:
```text
cleanup_file_if_not_referenced(path)
ListedFile::classify(path) -> (kind, FileReference) | None (unmanaged: keep)
ReferencedFiles::contains(ref) -> is_referenced / is_verified
Verdict::decide(is_referenced, is_verified, maybe_in_progress) -> Keep | Delete { unverified }
```
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 `unverified` drift. A data, index, deletion or
`_fri` file that is old and also referenced by an expiring manifest was
reported as `unverified: true` in `explain()`, and the audit log
recorded it as `delete_unverified`. It now reports as verified, which is
what transaction and `_blobs` files 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 for `decide`, and 18 for key lookup. The
`decide::verified_old` case is the regression test for the drift.
Seven integration tests only checked this rule, so they are removed:
- `cleanup_unreferenced_data_files`
- `do_not_cleanup_newer_data`
- `cleanup_old_index`
- `clean_old_delete_files`
- `dont_clean_index_data_files`
- `dont_cleanup_in_progress_write`
- `orphan_map_ages_out`
Their keep-side checks moved into
`every_removed_file_kind_contributes_its_bytes`, renamed to
`cleanup_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 keys `classify` derives from paths is
still caught end to end.
Per-test time from `--test-threads=1 --report-time`, debug build,
measured before the current-`main` integration:
| | Tests | Time |
|---|---|---|
| Rule tests before (8 integration) | 8 | 0.187 s |
| Rule tests after (1 integration + 52 unit) | 53 | 0.075 s |
| Whole `dataset::cleanup` suite, sum of per-test times | 233 → 278 |
8.96 s → 8.85 s |
The 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_lineage` tests (~4.4 s), which this rule
doesn't affect. Parallel wall time is unchanged at about 1.8 s.
## Integration
Merged `main` at `57bd7ff59` with 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 tree `cargo fmt --all --check`,
`cargo check --workspace --tests --benches --profile ci --locked`,
`cargo clippy --all --tests --benches --profile ci --locked -- -D
warnings` and `cargo test --workspace --profile ci --locked` (23,129
passed, 0 failed) pass, as do the 52 rule cases in isolation and
`cleanup_keeps_and_removes_every_file_kind` with 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 `unverified` flag in `explain()` and
the audit-log mode change.
Fixes #10903
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Xuanwo <[email protected]>
|
Thank you @Xuanwo @wjones127 |
cleanup_old_versionslisted_transactions/and_deletions/only up to the commit time of the oldest retained manifest, unless a deleted version was newer than it. A transaction or deletion file that no manifest references and that was written after that version was never listed, so the 7-day rule never removed it, anddelete_unverifiedremoved it only when a version-only policy let cleanup skip reading expired manifests, which also dropped the cutoff. #8944 fixed the same problem fordata/, and_blobs/has used that cutoff since it was added.These two directories now use the same cutoff as
data/: the later of the oldest retained manifest's commit time andnow - 7 days, or no cutoff when a deleted version is newer than the oldest retained one ordelete_unverifiedis set. Every listed file still goes through the reference check, so a file that a retained manifest references is kept, and a file that no manifest references is kept while it is younger than 7 days, unlessdelete_unverifiedis set.Fixes #10898.
The 7-day rule in the module docs now reaches every unreferenced file in these two directories. A deletion file written by an uncommitted delete and committed more than 7 days later can now be removed by a cleanup that runs before the commit, as a data file written by an uncommitted append already can.
Under
delete_unverifiedno listing uses the retained-manifest cutoff any more, so the flag that thedelete_unverifiedfast path set to drop that cutoff is removed. Thedelete_unverifieddocs in Rust and Java now say it applies to files that no manifest references, not only data files, and that it is only safe when no other operation is in progress; the module docs now list unreferenced transaction files.Testing
cleanup_deletes_aged_orphan_newer_than_retained_manifestsnow also writes unreferenced transaction and deletion files, one set before the oldest retained version and one after every manifest, and commits a delete after the oldest retained version, so that delete's deletion file is newer than the version. The orphans must be removed by age and underdelete_unverified, and the default policy must keep them while they are younger than 7 days, including the set the cutoff lists. The retained deletion file and the row count stay in every case. Reverting the cutoff of either directory fails the removal cases, and skipping the age check for either kind of file fails the case that keeps them.