Repository navigation
perf(cleanup): delete cleanup candidates in bulk - #10787
Merged
Merged
Conversation
Cleanup deleted one object per request, which costs a round trip per file (~30/s against a cloud store). The object store already exposes bulk deletion (S3 DeleteObjects: up to 1000 keys per request), but cleanup did not use it. The execute path now processes candidates in chunks sized at `delete_concurrency * 1000`. Non-manifest files are split into 1000-path sub-batches and handed to `ObjectStore::delete_stream`, with up to `delete_concurrency` bulk requests in flight and one shared semaphore permit per request. Manifest files still use a single-object delete so a failure keeps its commit-handler record, and batches below 100 paths do the same because one request per path costs no more and reports each outcome exactly. Bulk results are mapped back to their candidates by path. A `NotFound` path counts as removed; paths the store could not resolve are counted conservatively in `RemovalStats::failed_deletes`, and one failed bulk request does not abort the sweep. `delete_rate_limit` continues to meter paths per second (bulk requests can carry many paths), so the HTTP request rate is lower than the configured path rate. - `lance-io`: add `ObjectStore::delete_stream`, delegating to the backend's bulk implementation. - `cleanup`: chunk candidates, bulk-delete non-manifest files, keep manifests and small batches on the precise single-object path. - Update `delete_concurrency` and `delete_rate_limit` docs to describe bulk requests and path-based metering. Tests: - `lance-io`: `test_delete_stream_removes_every_path`. - `cleanup`: `cleanup_deletes_a_large_orphan_sweep` (200 orphan files take the bulk path). - Existing cleanup rate-limit, concurrency, and wrapped-error tests still pass.
# Conflicts: # rust/lance/src/dataset/cleanup.rs
`ObjectStore::delete` recognizes the hidden local staging names ending in `#<digits>`, unlinks them from the filesystem, and records the delete, because `LocalFileSystem` rejects those names. `delete_stream` forwarded the whole batch to the backend, so once cleanup had enough candidates to take the bulk path every staging file came back as an invalid path and was counted as a failed delete instead of being removed. Move the staging-path resolution into owned state that both entry points share, and remove staging files through the same helper `delete` uses. A store that can hold hidden staging files dispatches each location individually, since it has no bulk request to coalesce into; other stores keep passing the batch to the backend. An already-absent staging file is reported as not-found so callers can still count it as removed. Also state in the docs that a failed batch request can end the stream or omit per-input outcomes, which is why cleanup counts unresolved inputs as failures.
Extend the bulk-delete tests past the 100-path threshold, where single-object deletes no longer cover the behavior. - Cross the threshold with hidden staging files on a local store and assert they are unlinked, counted as removed with their bytes, and not reported as failed. - Drive a coalescing store through a mixed batch: success, a key another writer removed, a rejected key, and a key the response omits although it was removed. Assert removed bytes and counts, that only rejected keys survive, that an unreported key counts as a failure, and that a retry converges. - Reject a whole request with one pathless error and assert every unresolved path is counted, not just the error. - Assert one bulk request is one delete-semaphore unit across several requests, and that the per-path rate budget is not multiplied by the batch size.
Contributor
There was a problem hiding this comment.
✅ Gate recommendation: approve.
Bulk deletion remains appropriate: coalescing backends receive bounded batches while manifest retirement stays tied to individual delete outcomes. The staging-file repair preserves local cleanup behavior, and unreported outcomes remain failures. No merge-blocking findings.
Xuanwo
approved these changes
Nov 14, 2026
Xuanwo
added a commit
to wjones127/lance
that referenced
this pull request
Nov 15, 2026
…-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
added a commit
that referenced
this pull request
Nov 15, 2026
## 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]>
Xuanwo
added a commit
that referenced
this pull request
Nov 18, 2026
#10787 started grouping cleanup candidates with `try_chunks(delete_concurrency * 1000)`. `try_chunks` reserves its full capacity up front, for the first chunk and again after every chunk it yields, so the reservation grows with `delete_concurrency` and not with the number of files to delete. `validate_delete_concurrency` accepts any value up to `Semaphore::MAX_PERMITS`. At that bound the multiplication saturates to `usize::MAX` and cleanup panics with "capacity overflow". A value like 1,000,000 asks for tens of gigabytes per chunk, which usually aborts the process on allocation failure. Before #10787 every accepted value worked, since `buffer_unordered` does not preallocate. The value can also come from the `lance.auto_cleanup.delete_concurrency` table config, so an auto cleanup after a commit can abort the writer. This change collects each chunk into a `Vec` that grows with the files actually read, keeping the same chunk size and the same per-chunk deletes. ## How was this patch tested `test_cleanup_with_large_delete_concurrency` runs a cleanup with `delete_concurrency` set to 1,000,000 and to `Semaphore::MAX_PERMITS` and checks that the old version is removed without failed deletes. On main the test process aborts with `memory allocation of 40000000000 bytes failed`. With this change both cases pass, as do the existing `dataset::cleanup` tests. Co-authored-by: Maha Yadavalli <[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 issued one object-store delete per unreferenced file. S3's
DeleteObjectsaccepts up to 1000 keys per request, so a large cleanup sweeppaid one request per file even when the provider could coalesce them.
This adds a bulk-delete path to cleanup. Manifests and small batches keep
single-object deletes, so a failed manifest delete still keeps its
commit-handler record and per-path outcomes stay exact.
What changed
ObjectStore::delete_stream, delegating to the underlying object store'sbulk delete. It keeps the local-staging behavior
ObjectStore::deletealreadyowned: hidden staging names (ending in
#<digits>) are unlinked through thelocal filesystem, because the local backend rejects those names, and the delete
is recorded the same way. A store that can hold staging files has no bulk
request to coalesce into, so it dispatches one delete per path; remote stores
pass the batch through.
its commit-handler record so
forget_versionis not called ahead of themanifest removal.
per-path outcomes.
delete_concurrencycovers both manifest deletes and bulk requests. Oneoperation is one manifest delete or one bulk request; a backend may coalesce or
fan out the paths inside a request.
NotFoundcounts as removed;failed_deletes, includingwhen a failed request ends the stream early or a response omits the path;
delete_rate_limitas a per-path budget. Bulk requests may carryseveral paths, so the HTTP request rate can be lower than the configured
path rate.
Measurement
The counter in the benchmark added by #10511 is
delete_streamcalls observed bya wrapper installed in front of the store. On the local
file-object-storeruns of
cleanup/orphans/2000andcleanup/versions/200recorded whiledeveloping this change, it moved from one call per path to one call per
sub-batch (2000 → 2 and 597 → 200), while wall-clock moved within noise: a local
filesystem charges nothing per request, and cleanup time is dominated by listing,
manifest reads and classification.
Those counts are Lance-level store calls against a local wrapper. They are not S3
HTTP requests and not filesystem syscalls, and they were recorded before the
staging-path repair above: a local store now dispatches one delete per path, so
this counter no longer drops for local runs. A separate estimate charged a
synthetic 1 ms per request; that was a model, not measured cloud performance,
and is not a result of this change.
This change makes no claim about provider-side latency or request rates. The
reduction applies to backends whose
delete_streamcoalesces into one requestand should be measured against one; no benchmark is added here.
Tests
cargo test --profile ci --locked -p lance-io --lib— 688 passedcargo test --profile ci --locked -p lance --lib -- dataset::cleanup::tests— 261 passedcargo fmt --all -- --checkcargo clippy --profile ci --locked --all --tests --benches -- -D warningsNew coverage crosses the bulk threshold with hidden staging files, drives a
coalescing store through success, already gone, rejected and unreported keys, and
asserts one bulk request is one semaphore unit and one rate permit per path.
Notes for reviewers
ObjectStore::delete_streamis additive; no existing API changes.failed_deletes,NotFound, rate limits,and commit-handler records are preserved.
ObjectStore::remove_streamis unchanged: it predates this change and nocleanup path sends staging names through it.