Skip to content

fix(io): delete hierarchical storage directories after their contents - #9827

Merged
Xuanwo merged 10 commits into
lance-format:mainfrom
everySympathy:codex/fix-tos-branch-delete
Oct 23, 2026
Merged

Xuanwo merged 10 commits into
lance-format:mainfrom
everySympathy:codex/fix-tos-branch-delete

Conversation

@everySympathy

@everySympathy everySympathy commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Deleting a nonempty Lance branch on a TOS bucket with hierarchical namespace can fail with HTTP 409 CannotDelete: the OpenDAL bridge exposes directory entries as zero-size objects, and the generic deletion stream may remove a directory before its children.

The generic ObjectStore::remove_dir_all now defers zero-size entries and deletes them longest-path-first after nonempty files. Zero-byte files are deferred too, which is safe because child paths are longer than their parent directory. Nonempty files are forwarded through one continuous delete_stream, retaining each provider's batching and concurrency. All file deletes complete before deferred entries are deleted. Cleanup uses a single wrapped listing, so tracing, metrics, filtering, and path rewriting remain in effect; no native OpenDAL listing or provider directory-operation refactor is needed.

Regression tests cover hierarchical and flat TOS listings, pagination with each page read once, mixed nonempty and zero-byte files, nested/empty/missing directories, encoded paths, sibling-prefix isolation, deletion failures, rewritten paths, wrapped stores, and dynamic credentials. A synthetic S3-style backend test verifies that 20,000 nonempty files retain 20 concurrent batches and that deferred entries are deleted only after all file deletes finish.

Validation:

  • cargo test -p lance-io --features tos object_store::: 277 passed.
  • cargo fmt --all and git diff --check.
  • cargo clippy -p lance-io --features tos --tests --benches -- -D warnings.
  • cargo clippy --all --tests --benches -- -D warnings (Rust 1.98.1).
  • Reproduced the original failure on upstream 4323cdee1374bfe28971a83f72dddf43f9cbc863 (14.0.0-beta.8). Revalidated the revised fix on a disposable real TOS HNS dataset with two main fragments / four rows and a branch appended to six rows: branch deletion succeeds, its files and directories are removed, and the main dataset still reads all four rows. The disposable dataset was fully cleaned up.

This fixes deletion ordering; it does not add rollback of an already removed branch reference if cleanup fails.

CI status:

  • Lance Gatekeeper recommends approve without changes; the empty-commit revision preserves that review.
  • The earlier transitive unsafe-libyaml advisory blocker was addressed upstream in #9896. The new CI run on b31ed5953 passes the dependency audit and license-header check. This PR adds no advisory exception.
  • See the PR checks for the latest build and test results.

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

@github-actions github-actions Bot added A-encoding Encoding, IO, file reader/writer bug Something isn't working labels Oct 9, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 9, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 10, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 10, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 12, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 12, 2026
@zhangyue19921010 zhangyue19921010 self-assigned this Oct 12, 2026

@zhangyue19921010 zhangyue19921010 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The fix is correct: deleting files first and then directories longest-first means each directory is deleted only after everything inside it.

Suggestion: drop the native Operator listing. object_store_opendal already lists every directory entry with size == 0. Deferring the zero-size entries from the wrapped listing gives the same result:

if entry.size == 0 {   // instead of directory_locations.contains(&entry.location)
    deferred.push(entry.location);
} else {
    store.inner.delete(&entry.location).await?;
}

Zero-byte files get deferred too, but that only delays their deletion.

This change:

  • saves one full listing per call;
  • stops bypassing traced(), meter_store and object_store_wrapper;
  • removes the exact path match between two listings. If a wrapper rewrites paths, directory_locations.contains(...) stops matching and the 409 CannotDelete comes back.

If this goes into the generic branch of ObjectStore::remove_dir_all, the DirectoryOperations trait refactor isn't needed, and every OpenDAL-backed store gets the fix.

@everySympathy everySympathy changed the title fix(io): delete TOS branch directories after their contents fix(io): delete hierarchical storage directories after their contents Oct 12, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 12, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Oct 12, 2026
@lance-gatekeeper lance-gatekeeper Bot removed K-risk Latest Gatekeeper recommendation includes a non-blocking risk. K-approved Latest Gatekeeper recommendation permits acceptance. labels Oct 12, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

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

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 12, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 12, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 13, 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 batch-concurrency risk is fixed. Cleanup now preserves backend concurrency, directory ordering, and wrapper behavior. No changes requested.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. and removed K-approved Latest Gatekeeper recommendation permits acceptance. labels Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-encoding Encoding, IO, file reader/writer bug Something isn't working K-approved Latest Gatekeeper recommendation permits acceptance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants