Repository navigation
fix(io): delete hierarchical storage directories after their contents - #9827
Conversation
zhangyue19921010
left a comment
There was a problem hiding this comment.
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_storeandobject_store_wrapper; - removes the exact path match between two listings. If a wrapper rewrites paths,
directory_locations.contains(...)stops matching and the409 CannotDeletecomes 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.
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this comment.
✅ Gate recommendation: approve.
The batch-concurrency risk is fixed. Cleanup now preserves backend concurrency, directory ordering, and wrapper behavior. No changes requested.
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_allnow 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 continuousdelete_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 --allandgit diff --check.cargo clippy -p lance-io --features tos --tests --benches -- -D warnings.cargo clippy --all --tests --benches -- -D warnings(Rust 1.98.1).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:
unsafe-libyamladvisory blocker was addressed upstream in #9896. The new CI run onb31ed5953passes the dependency audit and license-header check. This PR adds no advisory exception.