From 3fe1db913b134e4fddee4c769ee4497847d8e01f Mon Sep 17 00:00:00 2001 From: Noah Dietz Date: Wed, 10 Mar 2021 15:40:13 -0800 Subject: [PATCH 1/3] fix: retain user RPC timeout if set via withTimeout (#1324) --- .../java/com/google/api/gax/rpc/ApiCallContext.java | 10 +++++++--- .../java/com/google/api/gax/rpc/AttemptCallable.java | 3 ++- .../com/google/api/gax/rpc/AttemptCallableTest.java | 3 +++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java b/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java index 1115027d6..2336be0e7 100644 --- a/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java +++ b/gax/src/main/java/com/google/api/gax/rpc/ApiCallContext.java @@ -63,9 +63,13 @@ public interface ApiCallContext extends RetryingContext { * Returns a new ApiCallContext with the given timeout set. * *

This sets the maximum amount of time a single unary RPC attempt can take. If retries are - * enabled, then this can take much longer. Unlike a deadline, timeouts are relative durations - * that are measure from the beginning of each RPC attempt. Please note that this will limit the - * duration of a server streaming RPC as well. + * enabled, then this can take much longer, as each RPC attempt will have the same constant + * timeout. Unlike a deadline, timeouts are relative durations that are measure from the beginning + * of each RPC attempt. Please note that this limits the duration of a server streaming RPC as + * well. + * + *

If a method has default {@link com.google.api.gax.retrying.RetrySettings}, the max attempts + * and/or total timeout is still respected when scheduling each RPC attempt. */ ApiCallContext withTimeout(@Nullable Duration timeout); diff --git a/gax/src/main/java/com/google/api/gax/rpc/AttemptCallable.java b/gax/src/main/java/com/google/api/gax/rpc/AttemptCallable.java index dbd9c995c..e053d5583 100644 --- a/gax/src/main/java/com/google/api/gax/rpc/AttemptCallable.java +++ b/gax/src/main/java/com/google/api/gax/rpc/AttemptCallable.java @@ -69,8 +69,9 @@ public ResponseT call() { ApiCallContext callContext = originalCallContext; try { + // Set the RPC timeout if the caller did not provide their own. Duration rpcTimeout = externalFuture.getAttemptSettings().getRpcTimeout(); - if (!rpcTimeout.isZero()) { + if (!rpcTimeout.isZero() && callContext.getTimeout() == null) { callContext = callContext.withTimeout(rpcTimeout); } diff --git a/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java b/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java index cb5133620..3b16b568d 100644 --- a/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java +++ b/gax/src/test/java/com/google/api/gax/rpc/AttemptCallableTest.java @@ -108,6 +108,9 @@ public void testRpcTimeoutIsNotErased() { Duration callerTimeout = Duration.ofMillis(10); ApiCallContext callerCallContext = FakeCallContext.createDefault().withTimeout(callerTimeout); + Duration timeout = Duration.ofMillis(5); + currentAttemptSettings = currentAttemptSettings.toBuilder().setRpcTimeout(timeout).build(); + AttemptCallable callable = new AttemptCallable<>(mockInnerCallable, "fake-request", callerCallContext); callable.setExternalFuture(mockExternalFuture); From bbd15564ce9708823a688c37b4e506f636983114 Mon Sep 17 00:00:00 2001 From: Yuri Golobokov Date: Mon, 15 Mar 2021 06:01:27 -0700 Subject: [PATCH 2/3] Fix BigtableGrpc.METHOD_READ_ROWS removal. (#1329) --- .../api/gax/grpc/ServerStreamingCallableBenchmark.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/benchmark/src/jmh/java/com/google/api/gax/grpc/ServerStreamingCallableBenchmark.java b/benchmark/src/jmh/java/com/google/api/gax/grpc/ServerStreamingCallableBenchmark.java index 8be3487aa..b37379055 100644 --- a/benchmark/src/jmh/java/com/google/api/gax/grpc/ServerStreamingCallableBenchmark.java +++ b/benchmark/src/jmh/java/com/google/api/gax/grpc/ServerStreamingCallableBenchmark.java @@ -146,12 +146,12 @@ public void setup(BenchmarkParams benchmarkParams) throws IOException { stub = BigtableGrpc.newStub(grpcChannel); // Direct Callable - directCallable = new GrpcDirectServerStreamingCallable<>(BigtableGrpc.METHOD_READ_ROWS); + directCallable = new GrpcDirectServerStreamingCallable<>(BigtableGrpc.getReadRowsMethod()); // Base Callable (direct + params extractor + exceptions + retries) GrpcCallSettings grpcCallSettings = GrpcCallSettings.newBuilder() - .setMethodDescriptor(BigtableGrpc.METHOD_READ_ROWS) + .setMethodDescriptor(BigtableGrpc.getReadRowsMethod()) .setParamsExtractor(new FakeRequestParamsExtractor()) .build(); @@ -212,7 +212,7 @@ public void teardown() { @Benchmark public void asyncGrpcListener(AsyncSettings asyncSettings, Blackhole blackhole) throws Exception { ClientCall clientCall = - grpcChannel.newCall(BigtableGrpc.METHOD_READ_ROWS, CallOptions.DEFAULT); + grpcChannel.newCall(BigtableGrpc.getReadRowsMethod(), CallOptions.DEFAULT); GrpcClientCallListener listener = new GrpcClientCallListener(clientCall, asyncSettings.autoFlowControl, blackhole); @@ -242,7 +242,7 @@ public void asyncGrpcObserver(AsyncSettings asyncSettings, Blackhole blackhole) public void syncGrpcIterator(Blackhole blackhole) { Iterator iterator = ClientCalls.blockingServerStreamingCall( - grpcChannel, BigtableGrpc.METHOD_READ_ROWS, CallOptions.DEFAULT, request); + grpcChannel, BigtableGrpc.getReadRowsMethod(), CallOptions.DEFAULT, request); while (iterator.hasNext()) { ReadRowsResponse response = iterator.next(); From 86d5c72b8502b9da032a77b17c410d33eaafad5a Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Mon, 15 Mar 2021 14:09:44 +0100 Subject: [PATCH 3/3] chore(deps): update dependency com.google.api.grpc:grpc-google-cloud-bigtable-v2 to v1.21.0 (#1322) Co-authored-by: Elliotte Rusty Harold --- benchmark/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmark/build.gradle b/benchmark/build.gradle index e6a57ef8b..87ca9b9f2 100644 --- a/benchmark/build.gradle +++ b/benchmark/build.gradle @@ -23,7 +23,7 @@ dependencies { compile project(':gax-grpc') compile "io.grpc:grpc-netty:${libraries['version.io_grpc']}" - compile 'com.google.api.grpc:grpc-google-cloud-bigtable-v2:1.16.1' + compile 'com.google.api.grpc:grpc-google-cloud-bigtable-v2:1.21.0' compile 'com.google.api.grpc:grpc-google-cloud-pubsub-v1:1.86.0' }