Skip to content

Stream retry support part 2: Introduce a new split method in AsyncRequestBody that returns an SdkP… #6346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: feature/master/mpu-stream-retry
Choose a base branch
from

Conversation

zoewangg
Copy link
Contributor

@zoewangg zoewangg commented Aug 13, 2025

…ublisher of ClosableAsyncRequestBody and use it in s3 multipart client

Motivation and Context

  • This PR introduces a new split method, splitClosable in AsyncRequestBody that returns an SdkPublisher of ClosableAsyncRequestBody instead of AsyncRequestBody, enabling proper resource management for split request bodies. The change is primarily implemented to support streaming retry for S3 multipart client for retry Support retries for individual parts of a multipart upload in Java SDK V2 #6198

  • Introduces ClosableAsyncRequestBody interface extending AsyncRequestBody with close capability

  • Updates S3 multipart client implementation to use the new splitClosable method

Testing

Added wiremock tests

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

  • I confirm that this pull request can be released under the Apache 2 license

@zoewangg zoewangg requested a review from Copilot August 13, 2025 23:12
Copilot

This comment was marked as outdated.

@zoewangg zoewangg requested a review from Copilot August 14, 2025 18:38
Copilot

This comment was marked as outdated.

@zoewangg zoewangg changed the title Introduce a new split method in AsyncRequestBody that returns an SdkP… Stream retry support part 2: Introduce a new split method in AsyncRequestBody that returns an SdkP… Aug 14, 2025
@zoewangg zoewangg requested a review from Copilot August 14, 2025 19:57
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new splitV2 method in AsyncRequestBody that returns an SdkPublisher of ClosableAsyncRequestBody instead of AsyncRequestBody, enabling proper resource management for split request bodies. This change is designed to support streaming retry for S3 multipart uploads.

  • Adds ClosableAsyncRequestBody interface extending AsyncRequestBody with close capability
  • Updates S3 multipart client implementation to use the new splitV2 method
  • Maintains backward compatibility by deprecating the original split method

Reviewed Changes

Copilot reviewed 17 out of 18 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
ClosableAsyncRequestBody.java New interface extending AsyncRequestBody with close capability
AsyncRequestBody.java Adds splitV2 method and deprecates original split method
SplittingPublisher.java Updates to return ClosableAsyncRequestBody and improve resource management
UploadWithUnknownContentLengthHelper.java Updated to use splitV2 and properly close request bodies
UploadWithKnownContentLengthHelper.java Updated to use splitV2 method
KnownContentLengthAsyncRequestBodySubscriber.java Updated to handle ClosableAsyncRequestBody and close resources
Test files Updated tests to use new interfaces and verify retry behavior

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

…ublisher of ClosableAsyncRequestBody and use it in s3 multipart client
@zoewangg zoewangg marked this pull request as ready for review August 14, 2025 22:54
@zoewangg zoewangg requested a review from a team as a code owner August 14, 2025 22:54
}

private void stubUploadFailsInitialAttemptCalls(int partNumber, ResponseDefinitionBuilder responseDefinitionBuilder) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have end to end test cases with Wiremock/stubs to test end to end to retryable error cases ?
Or can have separate task to cover end to end test w.r.t Multipart client error cases with different Part sizes and part numbers.

Copy link
Contributor Author

@zoewangg zoewangg Aug 20, 2025

Choose a reason for hiding this comment

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

I've added wiremock test for retryable error cases and this method is actually used in that test

https://github.com/aws/aws-sdk-java-v2/pull/6346/files#diff-1202818b28c2d2d4382e4113baa11a572895fa9bd35c8b0f336dc5f0e546d44bR149

@zoewangg zoewangg force-pushed the zoewang/splitV2 branch 3 times, most recently from 3b244ec to 29f911a Compare August 21, 2025 03:07

@Override
public void close() {
// no op
Copy link
Contributor

Choose a reason for hiding this comment

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

Why no op comment would be helpful ?

Copy link
Contributor Author

@zoewangg zoewangg Aug 21, 2025

Choose a reason for hiding this comment

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

Basically making it more explicit that this is deliberately left empty and not by mistake.

if (subscribeCalled.compareAndSet(false, true)) {
delegate.subscribe(s);
} else {
s.onSubscribe(new NoopSubscription(s));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why doe we need to do this ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Per reactive spec, onSubscribe must be signaled

Publisher.subscribe MUST call onSubscribe on the provided Subscriber prior to any other signals to that Subscriber

delegate.subscribe(s);
} else {
s.onSubscribe(new NoopSubscription(s));
s.onError(NonRetryableException.create(
Copy link
Contributor

Choose a reason for hiding this comment

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

Is retry only the use case case where this re subscription can occur ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes for the SDK use case, but I suppose it could be some other use case if customers use split directly (although we don't expect it to be used by users directly). I can update the message to make it more clear

log.debug(() -> "requesting data after closing" + partNumber);
}
} catch (Throwable e) {
log.warn(() -> String.format("Unexpected error thrown from cleaning up AsyncRequestBody for part number %d, "
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this just WARN and not error log ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used warn because it's not a immediate request failure per se. WDYT?

log.debug(() -> "Received complete() for part number: " + partNumber);
// ByteBuffersAsyncRequestBody MUST be created before we complete the current
// request because retry may happen right after
bufferedAsyncRequestBody = ByteBuffersAsyncRequestBody.of(buffers, bufferedLength);
Copy link
Contributor

Choose a reason for hiding this comment

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

We are passing buffers as it to ByteBuffersAsyncRequestBody , should we pass a copy new ArrayList<>(buffers) and make it threadsafe too using synchronized (buffersLock)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Extra copy/buffering is not necessary because it's entirely used internally and we know we will not modify it. Yup, will add synchronized

// For unknown content length, we always create a new DownstreamBody because we don't know if there is data
// left or not, so we need to only send the body if there is actually data
long bufferedLength = currentBody.receivedBytesLength();
if (bufferedLength == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If possible just in response to this comment can you tell me how we will end up bufferedLength == 0 here ? As in for touch files () byte files)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's explained above :) Will move it down and clarify

For unknown content length, we always create a new DownstreamBody because we don't know if there is data eft or not, so we need to only send the body if there is actually data

Comment on lines 69 to 72
onNumBytesConsumed.accept((long) length);
if (t != null) {
error(t);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Just for my understanding, why is onNumBytesConsumed always updated, instead of only when t == null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The data is considered consumed once the future completes (exceptionally or not) since there's no retry anyway.

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
76.6% Coverage on New Code (required ≥ 80%)
8.9% Duplication on New Code (required ≤ 3%)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants