Skip to content

perf(cleanup): stop reading expired manifests when delete_unverified is set - #9764

Merged
jackye1995 merged 5 commits into
lance-format:mainfrom
jackye1995:jack/cleanup-skip-expired-reads
Oct 24, 2026
Merged

jackye1995 merged 5 commits into
lance-format:mainfrom
jackye1995:jack/cleanup-skip-expired-reads

Conversation

@jackye1995

@jackye1995 jackye1995 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

When delete_unverified=true, cleanup skips reading expired manifests selected by before_version or explicit versions. Retained, tagged, and current manifests are still read to protect live files. This addresses the expired-manifest read amplification discussed in #9438 without adding an API.

Timestamp policies always read the manifest's logical commit time. Storage write timestamps cannot prove expiry because their clocks and precision can differ from the writer's. Skipping any manifest read also disables the directory-listing time cutoff so cleanup still finds all expired files.

Rebased onto main and removed the unnecessary ManifestLocation.last_modified change, resolving the Rust CI compilation failures. Added regression coverage for timestamp precision and clock skew, alongside read-skipping and retention coverage. Local builds, tests, and clippy were omitted as requested; CI provides validation. Formatting passed.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Oct 7, 2026
@wjones127
wjones127 self-requested a review October 16, 2026 19:01
`list_manifests` reads `ObjectMeta`, which carries `last_modified`, then drops it
converting to `ManifestLocation`. A caller that only needs a version's age has no
choice but to read the whole manifest for `Manifest::timestamp`, which on a table
with millions of versions means reading terabytes to answer a question the
listing already answered.

The field is the object write time, not the logical commit time, and the doc
comment says so: rewriting an object by copy or migration moves one and not the
other. It is `None` when the location came from somewhere that never saw an
`ObjectMeta`, such as probing a known version or a namespace response.

Same shape as carrying the manifest size instead of issuing a HEAD per manifest.
…is set

Cleanup reads every manifest to split files into referenced (live) and verified
(seen in a version being deleted). The verified set exists only to honour
`delete_unverified=false`, which withholds deletion from files it cannot prove
came from an expired version.

When the caller sets `delete_unverified=true` they have said that proof is not
required, so reading an expired manifest contributes nothing: its path, version,
size and store identity all come from the listing. Retained manifests are still
read, because the live set is what stops cleanup deleting live data.

This is the whole cost on a table that accumulated versions faster than it
cleaned them, where nearly every manifest is expired — the case where cleanup
currently cannot finish at all.

`proven_expired` answers "is this expired" from the listing alone and refuses to
guess: a false means "not proven", never "retained", because misclassifying a
retained manifest would delete live data. `before_timestamp` compares the
object's write time, which is set after the commit time, so a write time before
the cutoff proves the commit was too; the converse does not hold and falls back
to reading.

Skipping a read also loses that manifest's commit time, so the listing cutoff is
dropped and the subtree is scanned in full. Missing a file would orphan it
permanently; an extra listing only costs time.

The tests are paired so neither can pass vacuously: one asserts no expired
manifest is opened with the flag, the other asserts they all are without it.
@jackye1995
jackye1995 force-pushed the jack/cleanup-skip-expired-reads branch from 5180f4a to e8c62bb Compare October 23, 2026 19:13
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Oct 23, 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 timestamp-retention issue is fixed. The version-only fast path preserves live references, including the row maps of rescued branch roots.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 23, 2026

@wjones127 wjones127 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.

This seems like a worthwhile optimization. I noted a potential follow up that might save a lot in some situations.

Comment on lines +2198 to +2200
/// Timestamp policies require reading the logical commit time: storage clocks and
/// timestamp precision do not guarantee that object write time is an upper bound.
/// All version conditions must be satisfied, and at least one must be specified.

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.

suggestion: it would be cool if once we found a manifest with a commit time before the timestamp cutoff, we could assume that all manifests with lower versions can also be excluded. This would require changing our commit logic to enforcing monotonically increasing timestamps so we don't get hit by clock skew.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks — I found and reopened my earlier implementation in #5899, rebased it onto current main, and requested your review there. Let's handle the monotonic commit timestamp behavior in that PR. #9764 is now merged with the version-filter optimization.

@jackye1995
jackye1995 merged commit eb29354 into lance-format:main Oct 24, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

K-approved Latest Gatekeeper recommendation permits acceptance. performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants