From 0933f3d67d6b172f399dfad70f0e181fbc65c87f Mon Sep 17 00:00:00 2001 From: Igor Bernstein Date: Mon, 16 Nov 2026 22:46:14 +0000 Subject: [PATCH 1/2] fix(bigtable): honor per-call retryableCodes in MutateRowsAttemptCallable --- .../mutaterows/MutateRowsAttemptCallable.java | 14 +- .../MutateRowsAttemptCallableTest.java | 123 +++++++++++++++++- 2 files changed, 129 insertions(+), 8 deletions(-) diff --git a/java-bigtable/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsAttemptCallable.java b/java-bigtable/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsAttemptCallable.java index 4796ad48a094..ae0d2e1750f9 100644 --- a/java-bigtable/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsAttemptCallable.java +++ b/java-bigtable/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsAttemptCallable.java @@ -345,11 +345,13 @@ private ApiException createEntryError(com.google.rpc.Status protoStatus) { .withDescription(protoStatus.getMessage()); StatusCode gaxStatusCode = GrpcStatusCode.of(grpcStatus.getCode()); + Set effectiveRetryableCodes = + callContext.getRetryableCodes() != null ? callContext.getRetryableCodes() : retryableCodes; return ApiExceptionFactory.createException( grpcStatus.asRuntimeException(), gaxStatusCode, - retryableCodes.contains(gaxStatusCode.getCode())); + effectiveRetryableCodes.contains(gaxStatusCode.getCode())); } /** @@ -357,14 +359,20 @@ private ApiException createEntryError(com.google.rpc.Status protoStatus) { * implies that all entries failed as well. This helper is used to make that behavior explicit. * The generated exception will have the overall error as its cause. */ - private static ApiException createSyntheticErrorForRpcFailure(Throwable overallRequestError) { + private ApiException createSyntheticErrorForRpcFailure(Throwable overallRequestError) { if (overallRequestError instanceof ApiException) { ApiException requestApiException = (ApiException) overallRequestError; + boolean isRetryable = + callContext.getRetryableCodes() != null + ? callContext + .getRetryableCodes() + .contains(requestApiException.getStatusCode().getCode()) + : requestApiException.isRetryable(); return ApiExceptionFactory.createException( overallRequestError, requestApiException.getStatusCode(), - requestApiException.isRetryable(), + isRetryable, requestApiException.getErrorDetails()); } diff --git a/java-bigtable/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsAttemptCallableTest.java b/java-bigtable/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsAttemptCallableTest.java index 65f4f8a324f2..5a07d2b50a82 100644 --- a/java-bigtable/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsAttemptCallableTest.java +++ b/java-bigtable/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsAttemptCallableTest.java @@ -27,6 +27,7 @@ import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.retrying.RetryingFuture; import com.google.api.gax.retrying.TimedAttemptSettings; +import com.google.api.gax.rpc.AbortedException; import com.google.api.gax.rpc.ApiCallContext; import com.google.api.gax.rpc.ApiException; import com.google.api.gax.rpc.StatusCode.Code; @@ -76,11 +77,10 @@ public void setUp() { callContext = GrpcCallContext.createDefault(); parentFuture = new MockRetryingFuture(); Mockito.when(mockRetryAlgorithm.shouldRetry(any(), any(), any(), any())) - .thenAnswer( - input -> { - Throwable throwable = input.getArgument(1); - return ((ApiException) throwable).isRetryable(); - }); + .thenAnswer(input -> { + Throwable throwable = input.getArgument(1); + return ((ApiException) throwable).isRetryable(); + }); } @Test @@ -408,6 +408,119 @@ public ApiFuture> futureCall( assertThat(failedMutations.get(1).getError().getCause()).isEqualTo(rpcError); } + @Test + public void perCallRetryableCodesEntryErrorTest() throws Exception { + MutateRowsRequest request = + MutateRowsRequest.newBuilder() + .addEntries(Entry.newBuilder().setRowKey(ByteString.copyFromUtf8("0-aborted"))) + .addEntries(Entry.newBuilder().setRowKey(ByteString.copyFromUtf8("1-unavailable"))) + .build(); + + Status abortedStatusProto = + Status.newBuilder().setCode(com.google.rpc.Code.ABORTED_VALUE).build(); + innerCallable.response.add( + MutateRowsResponse.newBuilder() + .addEntries( + MutateRowsResponse.Entry.newBuilder().setIndex(0).setStatus(abortedStatusProto)) + .addEntries( + MutateRowsResponse.Entry.newBuilder() + .setIndex(1) + .setStatus(TRANSIENT_ERROR_STATUS_PROTO)) + .build()); + + ApiCallContext customCallContext = + callContext.withRetryableCodes(ImmutableSet.of(Code.ABORTED)); + MutateRowsAttemptCallable attemptCallable = + new MutateRowsAttemptCallable( + innerCallable, request, customCallContext, retryCodes, mockRetryAlgorithm); + attemptCallable.setExternalFuture(parentFuture); + attemptCallable.call(); + + MutateRowsAttemptResult result = parentFuture.attemptFuture.get(); + assertThat(result.getIsRetryable()).isTrue(); + List failedMutations = result.getFailedMutations(); + assertThat(failedMutations).hasSize(2); + + assertThat(failedMutations.get(0).getIndex()).isEqualTo(0); + assertThat(failedMutations.get(0).getError().getStatusCode().getCode()).isEqualTo(Code.ABORTED); + assertThat(failedMutations.get(0).getError().isRetryable()).isTrue(); + + assertThat(failedMutations.get(1).getIndex()).isEqualTo(1); + assertThat(failedMutations.get(1).getError().getStatusCode().getCode()) + .isEqualTo(Code.UNAVAILABLE); + assertThat(failedMutations.get(1).getError().isRetryable()).isFalse(); + } + + @Test + public void perCallRetryableCodesRpcErrorTest() { + MutateRowsRequest request = + MutateRowsRequest.newBuilder().addEntries(Entry.getDefaultInstance()).build(); + + // Stub default marks ABORTED as non-retryable and UNAVAILABLE as retryable, but per-call + // context overrides retryableCodes to {ABORTED}. + final AbortedException abortedError = + new AbortedException( + "aborted", null, GrpcStatusCode.of(io.grpc.Status.Code.ABORTED), false); + final UnavailableException unavailableError = + new UnavailableException( + "unavailable", null, GrpcStatusCode.of(io.grpc.Status.Code.UNAVAILABLE), true); + + ApiCallContext customCallContext = + callContext.withRetryableCodes(ImmutableSet.of(Code.ABORTED)); + + UnaryCallable> abortedCallable = + new UnaryCallable>() { + @Override + public ApiFuture> futureCall( + MutateRowsRequest req, ApiCallContext ctx) { + return ApiFutures.immediateFailedFuture(abortedError); + } + }; + + MutateRowsAttemptCallable attemptCallable1 = + new MutateRowsAttemptCallable( + abortedCallable, request, customCallContext, retryCodes, mockRetryAlgorithm); + attemptCallable1.setExternalFuture(parentFuture); + attemptCallable1.call(); + + Throwable actualError1 = null; + try { + parentFuture.attemptFuture.get(); + } catch (Throwable t) { + actualError1 = t.getCause(); + } + assertThat(actualError1).isInstanceOf(MutateRowsException.class); + MutateRowsException ex1 = (MutateRowsException) actualError1; + assertThat(ex1.isRetryable()).isTrue(); + assertThat(ex1.getFailedMutations().get(0).getError().isRetryable()).isTrue(); + + UnaryCallable> unavailableCallable = + new UnaryCallable>() { + @Override + public ApiFuture> futureCall( + MutateRowsRequest req, ApiCallContext ctx) { + return ApiFutures.immediateFailedFuture(unavailableError); + } + }; + + MutateRowsAttemptCallable attemptCallable2 = + new MutateRowsAttemptCallable( + unavailableCallable, request, customCallContext, retryCodes, mockRetryAlgorithm); + attemptCallable2.setExternalFuture(parentFuture); + attemptCallable2.call(); + + Throwable actualError2 = null; + try { + parentFuture.attemptFuture.get(); + } catch (Throwable t) { + actualError2 = t.getCause(); + } + assertThat(actualError2).isInstanceOf(MutateRowsException.class); + MutateRowsException ex2 = (MutateRowsException) actualError2; + assertThat(ex2.isRetryable()).isFalse(); + assertThat(ex2.getFailedMutations().get(0).getError().isRetryable()).isFalse(); + } + // static class MockInnerCallable extends UnaryCallable> { From 15faa90f156c043acbca41a3d70b1ac64687fa9a Mon Sep 17 00:00:00 2001 From: Igor Bernstein Date: Mon, 16 Nov 2026 22:56:00 +0000 Subject: [PATCH 2/2] docs(bigtable): document fallback to requestApiException.isRetryable() --- .../data/v2/stub/mutaterows/MutateRowsAttemptCallable.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/java-bigtable/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsAttemptCallable.java b/java-bigtable/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsAttemptCallable.java index ae0d2e1750f9..29583c37e43e 100644 --- a/java-bigtable/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsAttemptCallable.java +++ b/java-bigtable/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsAttemptCallable.java @@ -362,6 +362,10 @@ private ApiException createEntryError(com.google.rpc.Status protoStatus) { private ApiException createSyntheticErrorForRpcFailure(Throwable overallRequestError) { if (overallRequestError instanceof ApiException) { ApiException requestApiException = (ApiException) overallRequestError; + // When no per-call retryableCodes override is present on callContext, preserve + // requestApiException.isRetryable() so both the stub's configured retryableCodes (applied by + // GrpcRawCallableFactory) and ConvertExceptionCallable's retryable flag on transient + // INTERNAL errors (e.g. RST_STREAM / GOAWAY) are honored. boolean isRetryable = callContext.getRetryableCodes() != null ? callContext