Skip to content

fix(workflow-core): paginate S3 deleteDirectory deletions - #5569

Merged
kunwp1 merged 7 commits into
apache:mainfrom
kunwp1:fix/s3-delete-directory-pagination
Jun 12, 2026
Merged

kunwp1 merged 7 commits into
apache:mainfrom
kunwp1:fix/s3-delete-directory-pagination

Conversation

@kunwp1

@kunwp1 kunwp1 commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

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?

Generated-by: Claude Code (Claude Opus 4.8)

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
@kunwp1
kunwp1 force-pushed the fix/s3-delete-directory-pagination branch from 1b4b0c3 to e3deaba Compare June 8, 2026 22:07
@codecov-commenter

codecov-commenter commented Jun 8, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 52.14%. Comparing base (cd60535) to head (e8d0b92).
⚠️ Report is 6 commits behind head on main.

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              
Flag Coverage Δ *Carryforward flag
access-control-service 64.61% <ø> (ø)
agent-service 33.76% <ø> (ø) Carriedforward from adc9bb1
amber 53.39% <100.00%> (+0.11%) ⬆️
computing-unit-managing-service 1.65% <ø> (ø)
config-service 58.57% <ø> (+2.51%) ⬆️
file-service 38.21% <ø> (ø)
frontend 46.36% <ø> (-0.67%) ⬇️ Carriedforward from adc9bb1
pyamber 90.61% <ø> (-0.11%) ⬇️ Carriedforward from adc9bb1
python 90.75% <ø> (ø) Carriedforward from adc9bb1
workflow-compiling-service 58.69% <ø> (ø)

*This pull request uses carry forward flags. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

kunwp1 added 2 commits June 8, 2026 15:22
…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.
@kunwp1
kunwp1 requested a review from Xiao-zhen-Liu June 9, 2026 07:59
@kunwp1

kunwp1 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

/request-review @Xiao-zhen-Liu

@Yicong-Huang

Copy link
Copy Markdown
Contributor

@xuang7 I think this may need to be back ported to v1.2

@xuang7 xuang7 added the release/v1.2 back porting to release/v1.2 label Jun 10, 2026
@Yicong-Huang

Copy link
Copy Markdown
Contributor

@kunwp1 if you agree this needs backport, it may need to be manually backported as there are commits missing between two branches.

@kunwp1

kunwp1 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

Needs to be backported because it's a bug fix.

@kunwp1

kunwp1 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

I noticed that the conflict comes from this PR: #5280 . Might be better to backport this #5280 @xuang7

@xuang7

xuang7 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

I noticed that the conflict comes from this PR: #5280 . Might be better to backport this #5280 @xuang7

Since this fix needs to be manually backported and is related to #5280, could you open a backport PR for #5280 targeting the release/v1.2 branch? Thanks!

@kunwp1

kunwp1 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

I noticed that the conflict comes from this PR: #5280 . Might be better to backport this #5280 @xuang7

Since this fix needs to be manually backported and is related to #5280, could you open a backport PR for #5280 targeting the release/v1.2 branch? Thanks!

Sounds good! I'll create a PR that includes both #5249 and #5280

xuang7 pushed a commit that referenced this pull request Jun 10, 2026
…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 Xiao-zhen-Liu 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.

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.

kunwp1 added 2 commits June 11, 2026 14:51
- 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.
@kunwp1
kunwp1 added this pull request to the merge queue Jun 12, 2026
Merged via the queue into apache:main with commit 227cbd7 Jun 12, 2026
28 checks passed
@kunwp1
kunwp1 deleted the fix/s3-delete-directory-pagination branch June 12, 2026 19:03
Yicong-Huang pushed a commit that referenced this pull request Jun 12, 2026
### 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)
@github-actions

Copy link
Copy Markdown
Contributor

Backport to release/v1.2 succeeded as c9d3a73. Run

Ma77Ball pushed a commit to Ma77Ball/texera that referenced this pull request Jun 12, 2026
### 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)
yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 22, 2026
### 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

common fix release/v1.2 back porting to release/v1.2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

S3StorageClient.deleteDirectory only deletes the first ≤1000 objects per prefix

5 participants