Repository navigation
feat: add new cleanup policy to retain latest n versions - #4614
Conversation
2f942e8 to
1ada29b
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4614 +/- ##
==========================================
- Coverage 80.62% 80.59% -0.03%
==========================================
Files 317 317
Lines 118785 119426 +641
Branches 118785 119426 +641
==========================================
+ Hits 95769 96256 +487
- Misses 19568 19714 +146
- Partials 3448 3456 +8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| dataset: &'a Dataset, | ||
| before: DateTime<Utc>, | ||
| policy: CleanupPolicy, | ||
| delete_unverified: bool, |
There was a problem hiding this comment.
why delete_unverified and error_if_old_versions_tagged are not a part of the policy?
There was a problem hiding this comment.
My thoughts on this is: the CleanupPolicy only determines which manifests need to be cleaned. The delete_unverified and error_if_old_versions_tagged determines the behavior of cleanup task.
#[derive(Clone, Debug)]
struct CleanupTask<'a> {
dataset: &'a Dataset,
/// The policy determines which versions should be cleanup
policy: CleanupPolicy,
/// If true, delete unverified data files even if they are recent
delete_unverified: bool,
/// If true, return an Error if a tagged version is old
error_if_old_versions_tagged: bool,
}
| } | ||
|
|
||
| #[derive(Debug, Clone)] | ||
| pub enum CleanupPolicy { |
There was a problem hiding this comment.
I feel it makes more sense for this to be a struct, instead of an enum, so that people can express composite policies like "cleanup all versions before version X and also timestamp Y"
There was a problem hiding this comment.
"composite policies" is a great idea. Let me try this.
| return Ok(None); | ||
| } | ||
|
|
||
| // TODO: Support complex composite policies. |
There was a problem hiding this comment.
We need to support configuring more complex composite policies. May be we can add a new key lance.auto_cleanup.cleanup_policy, and the value could be something like this.
{
"must": [{"retian_versions": 100}],
"should":[],
"must_not": [{"older_than": "2025-03-10T12:00:00Z"}],
}
I think may be I can add this at another pr, so I can keep this one clean.
|
Hi @jackye1995 @wjones127 , could you help review this when you have time, thanks very much! |
|
@wojiaodoubao I am thinking if doing this composite policy is a bit too much of a complication. I like the fact that it is trying to make the framework extensible, but when I said "composite policy", I was just thinking about the case that user gives a condition both for time and number of versions, because in your original version, the code allows either specifying time or version but not both. When I look into other expiration APIs like Iceberg ExpireSnapshots, allowing users to configure these 2 seems sufficient, and we can just allow the API (e.g. having a CleanupBuilder) to take both and then handle the case that user specify both conditions. What do you think? |
7cae2bc to
da31fe3
Compare
Thanks @jackye1995 your detailed explanation, it makes sense to me. I think I also understand why you said "delete_unverified and error_if_old_versions_tagged part of policy", we can use a CleanupPolicy struct to wrap all. Let me fix it. |
2b64fca to
0b02218
Compare
0b02218 to
f2d802a
Compare
|
Hi @jackye1995 , I have updated the pr. Please review when you have time, thanks very much! |
| policy: CleanupPolicy, | ||
| } | ||
|
|
||
| impl CleanupBuilder { |
There was a problem hiding this comment.
this should be CleanupPolicyBuilder? Since it's building a policy.
When I say having a CleanupBuilder, I was more thinking about
CleanupBuilder::new(dataset)
. before_timestamp(...)
.execute()
kind of experience similar to MergeInsertBuilder, but the current one seems also fine.
| if let Some(unmodified_since_val) = unmodified_since { | ||
| output | ||
| .try_filter(move |file| future::ready(file.last_modified < unmodified_since_val)) | ||
| .try_filter(move |file| future::ready(file.last_modified <= unmodified_since_val)) |
There was a problem hiding this comment.
ah nice catch! I think you are right
…t#4614) Related to lance-format#4036 --------- Co-authored-by: lijinglun <[email protected]>
## 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]>
Related to #4036