Skip to content

feat(gax): implement baseline Callable and Future for resumable uploads - #14241

Open
whowes wants to merge 1 commit into
mainfrom
whowes/resumable-upload-happy-path
Open

feat(gax): implement baseline Callable and Future for resumable uploads#14241
whowes wants to merge 1 commit into
mainfrom
whowes/resumable-upload-happy-path

Conversation

@whowes

@whowes whowes commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

This implementation supports the happy path only; retries, recovery, timeouts, per-call settings, and progress tracking will be added in subsequent phases.

gemini-code-assist[bot]

This comment was marked as outdated.

@whowes

whowes commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

gemini-code-assist[bot]

This comment was marked as outdated.

@whowes
whowes force-pushed the whowes/resumable-upload-happy-path branch 2 times, most recently from 234e79f to 6845669 Compare September 2, 2026 22:32
@whowes

whowes commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces the concrete implementation of ResumableUploadCallable and ResumableUploadFuture (ResumableUploadCallableImpl and ResumableUploadFutureImpl) to coordinate resumable upload sessions and stream chunks asynchronously, along with comprehensive unit tests. The feedback highlights a potential issue where performing blocking I/O (ByteStreams.read) inside asynchronous future callbacks could lead to thread starvation or deadlocks if a limited executor is used, suggesting either documenting executor requirements or offloading the blocking read.

byte[] buffer = new byte[chunkSize];
int bytesRead;
try {
bytesRead = ByteStreams.read(payload, buffer, 0, chunkSize);

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.

medium

Performing blocking I/O (ByteStreams.read) inside asynchronous future callbacks (which run on the provided executor) can lead to thread starvation or deadlocks if the executor is a direct executor or a limited thread pool (such as gRPC network threads). Consider documenting that the executor passed to the callable must be a dedicated thread pool suitable for blocking I/O operations, or offloading the blocking read to a dedicated I/O executor.

@whowes
whowes requested a review from blakeli0 September 2, 2026 22:59
@whowes
whowes marked this pull request as ready for review September 2, 2026 22:59
@whowes
whowes requested review from a team as code owners September 2, 2026 22:59
@whowes
whowes force-pushed the whowes/resumable-upload-happy-path branch from 6845669 to 61fd370 Compare September 3, 2026 05:29
ResumableUploadCallSettings effectiveSettings = defaultCallSettings.merge(settings);

return ResumableUploadFutureImpl.create(
client, request, payload, effectiveSettings.getChunkSize(), defaultCallContext, executor);

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.

Since we know there will be more configurations, can we pass the whole settings class to the future?

+ " incomplete status"));
}
// Continuation: asynchronously transmit subsequent chunk with updated offset.
return transmitChunks(

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.

Can we use a while loop instead of recursive calls? There is always stackoverflow concerns using recursives.

return transmitChunks(client, payload, chunkSize, callContext, url, 0L, executor);
},
executor);
sessionFuture.addListener(() -> closePayload(payload), executor);

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.

I think there are two issues here:

  1. Should we take the responsibility of closing the stream? Usually whoever creates the stream is responsible for it.
  2. If we do want to take the responsibility, using try-with-resources is preferred than manually closing it.

return transmitChunks(
client, payload, chunkSize, callContext, uploadSessionUrl, nextOffset, executor);
},
executor);

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.

I think the whole upload(including the initial call) can be done in a single thread. Using transformAsync may transform the future in a different thread, we can ended up with a lot of thread when uploading large files.

private static final byte[] EMPTY_PAYLOAD = new byte[0];

private final InputStream payload;
private final AtomicReference<@Nullable String> uploadSessionUrl;

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.

ResumableUploadFuture represents one main upload session and there should be only one thread modifying this url. I don't think we need to use AtomicReference.

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.

In general, I think the current structure of the how we make initial call and upload call can be improved. The nested calls of ApiFutures.transformAsync is not easy to read, and may have performance concerns. Some future calls can be made in the callable as well. There could also be a wrapper callable/future that does the whole uploading.

A pseudo code I'm thinking in the Callable is

StartUploadFuture startUploadFuture = client.startUploadCallable().futureCall();
UploadWholeCallable uploadWholeCallable = new UploadWholeCallable(startUploadFuture, client);
UploadWholeFuture uploadWholeFuture = uploadWholeCallable().futureCall();

return new ResumableUploadFuture(startUploadFuture, uploadWholeFuture).

This is similar to OperationCallableImpl.

Let me know what you think and if I missed anything.

@whowes
whowes force-pushed the whowes/resumable-upload-happy-path branch from 61fd370 to cf3098c Compare September 4, 2026 02:44
@whowes
whowes force-pushed the whowes/resumable-upload-happy-path branch from cf3098c to e237724 Compare September 4, 2026 03:01
@sonarqubecloud

sonarqubecloud Bot commented Sep 4, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed for 'gapic-generator-java-root'

Failed conditions
B 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

@sonarqubecloud

sonarqubecloud Bot commented Sep 4, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed for 'gapic-generator-java-root'

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)
B 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.

2 participants