Skip to content
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

fix: update grpc based ReadObject rpcs to remove race condition between cancellation and message handling #2708

Merged
merged 4 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@

import com.google.api.core.ApiFutures;
import com.google.api.core.SettableApiFuture;
import com.google.api.gax.retrying.ResultRetryAlgorithm;
import com.google.api.gax.rpc.ServerStreamingCallable;
import com.google.cloud.storage.BufferedReadableByteChannelSession.BufferedReadableByteChannel;
import com.google.cloud.storage.Retrying.RetryingDependencies;
import com.google.cloud.storage.UnbufferedReadableByteChannelSession.UnbufferedReadableByteChannel;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.storage.v2.Object;
Expand All @@ -43,27 +45,32 @@ public static GapicDownloadSessionBuilder create() {
return INSTANCE;
}

/**
* Any retry capability must be defined within the provided ServerStreamingCallable. The
* ultimately produced channel will not do any retries of its own.
*/
public ReadableByteChannelSessionBuilder byteChannel(
ServerStreamingCallable<ReadObjectRequest, ReadObjectResponse> read,
RetryingDependencies retryingDependencies,
ResultRetryAlgorithm<?> resultRetryAlgorithm,
ResponseContentLifecycleManager responseContentLifecycleManager) {
return new ReadableByteChannelSessionBuilder(read, responseContentLifecycleManager);
return new ReadableByteChannelSessionBuilder(
read, retryingDependencies, resultRetryAlgorithm, responseContentLifecycleManager);
}

public static final class ReadableByteChannelSessionBuilder {

private final ServerStreamingCallable<ReadObjectRequest, ReadObjectResponse> read;
private final RetryingDependencies retryingDependencies;
private final ResultRetryAlgorithm<?> resultRetryAlgorithm;
private final ResponseContentLifecycleManager responseContentLifecycleManager;
private boolean autoGzipDecompression;
private Hasher hasher;

private ReadableByteChannelSessionBuilder(
ServerStreamingCallable<ReadObjectRequest, ReadObjectResponse> read,
RetryingDependencies retryingDependencies,
ResultRetryAlgorithm<?> resultRetryAlgorithm,
ResponseContentLifecycleManager responseContentLifecycleManager) {
this.read = read;
this.retryingDependencies = retryingDependencies;
this.resultRetryAlgorithm = resultRetryAlgorithm;
this.responseContentLifecycleManager = responseContentLifecycleManager;
this.hasher = Hasher.noop();
this.autoGzipDecompression = false;
Expand Down Expand Up @@ -105,12 +112,24 @@ public UnbufferedReadableByteChannelSessionBuilder unbuffered() {
if (autoGzipDecompression) {
return new GzipReadableByteChannel(
new GapicUnbufferedReadableByteChannel(
resultFuture, read, object, hasher, responseContentLifecycleManager),
resultFuture,
read,
object,
hasher,
retryingDependencies,
resultRetryAlgorithm,
responseContentLifecycleManager),
ApiFutures.transform(
resultFuture, Object::getContentEncoding, MoreExecutors.directExecutor()));
} else {
return new GapicUnbufferedReadableByteChannel(
resultFuture, read, object, hasher, responseContentLifecycleManager);
resultFuture,
read,
object,
hasher,
retryingDependencies,
resultRetryAlgorithm,
responseContentLifecycleManager);
}
};
}
Expand Down
Loading
Loading