Repository navigation
fix(workflow-core): paginate S3 deleteDirectory deletions - #5569
Conversation
deleteDirectory issued a single listObjectsV2 call (capped at 1000 keys per page) and one deleteObjects batch, so any objects beyond the first 1000 under a prefix were silently orphaned. AWS DeleteObjects also accepts at most 1000 keys per request, and reports per-key failures in its response rather than throwing. List via listObjectsV2Paginator, which transparently follows the continuation token across all pages, deleting keys in batches of at most 1000. Inspect each DeleteObjects response and raise if any key failed, so partial deletions are no longer swallowed. Also remove the unused MD5 computation (digested over the request's toString and never used). Closes apache#5281
1b4b0c3 to
e3deaba
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5569 +/- ##
============================================
- Coverage 52.42% 52.14% -0.28%
- Complexity 2481 2496 +15
============================================
Files 1070 1068 -2
Lines 41359 41309 -50
Branches 4441 4455 +14
============================================
- Hits 21682 21542 -140
- Misses 18406 18496 +90
Partials 1271 1271
*This pull request uses carry forward flags. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…ry docs - Cap throwOnDeleteErrors enumeration at MAX_LISTED_DELETE_ERRORS (10) and summarize the remainder, so a fully-failed batch can't produce an unbounded message. - Update the LargeBinaryManager doc that still described the pre-pagination single-page (<=1000) behavior of deleteDirectory.
|
/request-review @Xiao-zhen-Liu |
|
@xuang7 I think this may need to be back ported to v1.2 |
|
@kunwp1 if you agree this needs backport, it may need to be manually backported as there are commits missing between two branches. |
|
Needs to be backported because it's a bug fix. |
Sounds good! I'll create a PR that includes both #5249 and #5280 |
…release/v1.2 backport] (#5602) ### What changes were proposed in this PR? Backport of #5280 ("scope large binary storage and cleanup by execution id") to `release/v1.2`. As noted in #5569, #5280 cannot be backported as a single cherry-pick: its changes to `large_binary_output_stream.py` build on top of #5249 ("keep failed-upload cleanup inside the upload worker"), which is not present on `release/v1.2`. Cherry-picking #5280 alone leaves a dangling reference to the `large_binary_manager` module in `_cleanup_failed_upload()` (a method #5249 removes), producing a `NameError` at runtime. This PR therefore backports the dependency chain, both as clean `git cherry-pick -x` of the original squash commits: 1. **#5249** — keep failed-upload cleanup inside the upload worker (prerequisite) 2. **#5280** — scope large binary storage and cleanup by execution id `#4707` (which #5249 follows up on) is already present on `release/v1.2`, so the chain stops there. After applying both commits, every file touched by #5280 is byte-identical to its state on `main` at the merged #5280 commit (`48e800e4`), and `release/v1.2` had no independent changes to any of those files. ### Any related issues, documentation, discussions? Backports #5280 (which closes #4123 on `main`). Prerequisite: #5249. Unblocks the #5569 backport, which can then cherry-pick cleanly onto `release/v1.2`. ### How was this PR tested? This is a backport with no changes beyond the two cherry-picked commits, so it relies on the existing tests carried over from #5249 and #5280 (`LargeBinaryManagerSpec`, `LargeBinaryManagerUnitSpec`, `test_large_binary_output_stream.py`, `test_large_binary_manager.py`, etc.). Backport fidelity was verified locally by confirming that, after the chain is applied onto `release/v1.2`: - all files touched by #5280 are byte-identical to `main@48e800e`; - no callers of the removed `deleteAllObjects()` remain; - `deleteByExecution` is wired in `WorkflowResource` and `WorkflowService`. Full compile and unit-test runs are left to CI. ### Was this PR authored or co-authored using generative AI tooling? Generated-by: Claude Code (Claude Opus 4.8) --------- Signed-off-by: Matthew B. <[email protected]> Signed-off-by: Kunwoo (Chris) <[email protected]> Co-authored-by: Matthew B. <[email protected]> Co-authored-by: Xiaozhen Liu <[email protected]>
Xiao-zhen-Liu
left a comment
There was a problem hiding this comment.
Correct, well-scoped fix for a real storage leak, with a proper >1000-object regression test. I confirmed the removed MD5 block was dead code and that directoryExists is the only other list site (already safe), so this closes the bug class rather than one instance. Inline comments are all non-blocking.
- Attempt every delete batch before raising, collecting per-key failures across batches and throwing once. One undeletable key no longer strands the keys behind it — DatasetResource can't retry past its already-deleted LakeFS repo, so each attempt now makes maximum progress. - Set quiet(true) on DeleteObjects so each batch response carries only the failures we inspect, not an echo of every deleted key. - Reject an empty prefix instead of silently normalizing it to "/" (which matched nothing); guards against an accidental whole-bucket wipe. - Clarify the Scaladoc: S3 prefix semantics and why the trailing "/" matters. - Pin the trailing-slash guard with a sibling-object test, and split the throwOnDeleteErrors test into three focused cases.
Trim the verbose comments added in the review pass to their essentials — no behavior or test changes. The deleteDirectory Scaladoc still explains S3 prefix semantics, the trailing-slash boundary, and the empty-prefix rejection.
### What changes were proposed in this PR? `S3StorageClient.deleteDirectory` listed objects with a single `listObjectsV2` call and issued one `deleteObjects` batch. Both S3 APIs cap at 1000 keys per call, so for any prefix holding more than 1000 objects only the first 1000 were deleted and the rest causes a storage leak. This affects dataset deletion (`DatasetResource`) and per-execution cleanup (`LargeBinaryManager`), either of which can exceed 1000 objects under one prefix. This PR: - Lists via `listObjectsV2Paginator`, which follows the continuation token across all pages, and deletes in batches of at most 1000 keys. Keys are streamed so memory stays bounded to a single batch. - Inspects each `DeleteObjects` response and throws if any key failed. ### Any related issues, documentation, discussions? Closes #5281 ### How was this PR tested? 1. Create more than 1000 files `for i in {1..1100}; do printf 'x' > "file_$i.txt"; done` 2. Upload them in a dataset. (There is a frontend memory issue when you upload all 1100 files at the same time. Try to upload batch-by-batch) 3. Delete the dataset. 4. Check if all the files are removed in the minio console. (Before this fix, some files remain) ### Was this PR authored or co-authored using generative AI tooling? (backported from commit 227cbd7) Generated-by: Claude Code (Claude Opus 4.8)
|
Backport to |
### What changes were proposed in this PR? `S3StorageClient.deleteDirectory` listed objects with a single `listObjectsV2` call and issued one `deleteObjects` batch. Both S3 APIs cap at 1000 keys per call, so for any prefix holding more than 1000 objects only the first 1000 were deleted and the rest causes a storage leak. This affects dataset deletion (`DatasetResource`) and per-execution cleanup (`LargeBinaryManager`), either of which can exceed 1000 objects under one prefix. This PR: - Lists via `listObjectsV2Paginator`, which follows the continuation token across all pages, and deletes in batches of at most 1000 keys. Keys are streamed so memory stays bounded to a single batch. - Inspects each `DeleteObjects` response and throws if any key failed. ### Any related issues, documentation, discussions? Closes apache#5281 ### How was this PR tested? 1. Create more than 1000 files `for i in {1..1100}; do printf 'x' > "file_$i.txt"; done` 2. Upload them in a dataset. (There is a frontend memory issue when you upload all 1100 files at the same time. Try to upload batch-by-batch) 3. Delete the dataset. 4. Check if all the files are removed in the minio console. (Before this fix, some files remain) ### Was this PR authored or co-authored using generative AI tooling? Generated-by: Claude Code (Claude Opus 4.8)
### What changes were proposed in this PR? `S3StorageClient.deleteDirectory` listed objects with a single `listObjectsV2` call and issued one `deleteObjects` batch. Both S3 APIs cap at 1000 keys per call, so for any prefix holding more than 1000 objects only the first 1000 were deleted and the rest causes a storage leak. This affects dataset deletion (`DatasetResource`) and per-execution cleanup (`LargeBinaryManager`), either of which can exceed 1000 objects under one prefix. This PR: - Lists via `listObjectsV2Paginator`, which follows the continuation token across all pages, and deletes in batches of at most 1000 keys. Keys are streamed so memory stays bounded to a single batch. - Inspects each `DeleteObjects` response and throws if any key failed. ### Any related issues, documentation, discussions? Closes apache#5281 ### How was this PR tested? 1. Create more than 1000 files `for i in {1..1100}; do printf 'x' > "file_$i.txt"; done` 2. Upload them in a dataset. (There is a frontend memory issue when you upload all 1100 files at the same time. Try to upload batch-by-batch) 3. Delete the dataset. 4. Check if all the files are removed in the minio console. (Before this fix, some files remain) ### Was this PR authored or co-authored using generative AI tooling? Generated-by: Claude Code (Claude Opus 4.8)
What changes were proposed in this PR?
S3StorageClient.deleteDirectorylisted objects with a singlelistObjectsV2call and issued onedeleteObjectsbatch. Both S3 APIs cap at 1000 keys per call, so for any prefix holding more than 1000 objects only the first 1000 were deleted and the rest causes a storage leak. This affects dataset deletion (DatasetResource) and per-execution cleanup (LargeBinaryManager), either of which can exceed 1000 objects under one prefix.This PR:
listObjectsV2Paginator, which follows the continuation token across all pages, and deletes in batches of at most 1000 keys. Keys are streamed so memory stays bounded to a single batch.DeleteObjectsresponse and throws if any key failed.Any related issues, documentation, discussions?
Closes #5281
How was this PR tested?
for i in {1..1100}; do printf 'x' > "file_$i.txt"; doneWas this PR authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Claude Opus 4.8)