Skip to content

Commit 6ada222

Browse files
Bigtable: fix handling of unset rpc timeouts (#4323)
When the rpc timeout is zero, then it should be treated as disabled not actual 0
1 parent d468e04 commit 6ada222

2 files changed

Lines changed: 37 additions & 15 deletions

File tree

google-cloud-clients/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsAttemptCallable.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,14 @@ public Object getTransportCode() {
101101
};
102102

103103
// Everything needed to issue an RPC
104-
private final UnaryCallable<MutateRowsRequest, List<MutateRowsResponse>> innerCallable;
105-
private final ApiCallContext callContext;
106-
private MutateRowsRequest currentRequest;
104+
@Nonnull private final UnaryCallable<MutateRowsRequest, List<MutateRowsResponse>> innerCallable;
105+
@Nonnull private final ApiCallContext callContext;
106+
@Nonnull private MutateRowsRequest currentRequest;
107107

108108
// Everything needed to build a retry request
109-
private List<Integer> originalIndexes;
110-
private final Set<StatusCode.Code> retryableCodes;
111-
private final List<FailedMutation> permanentFailures;
109+
@Nullable private List<Integer> originalIndexes;
110+
@Nonnull private final Set<StatusCode.Code> retryableCodes;
111+
@Nullable private final List<FailedMutation> permanentFailures;
112112

113113
// Parent controller
114114
private RetryingFuture<Void> externalFuture;
@@ -135,12 +135,12 @@ public List<MutateRowsResponse> apply(Throwable throwable) {
135135
MutateRowsAttemptCallable(
136136
@Nonnull UnaryCallable<MutateRowsRequest, List<MutateRowsResponse>> innerCallable,
137137
@Nonnull MutateRowsRequest originalRequest,
138-
@Nullable ApiCallContext callContext,
138+
@Nonnull ApiCallContext callContext,
139139
@Nonnull Set<StatusCode.Code> retryableCodes) {
140-
this.innerCallable = Preconditions.checkNotNull(innerCallable);
141-
this.currentRequest = Preconditions.checkNotNull(originalRequest);
142-
this.callContext = callContext;
143-
this.retryableCodes = Preconditions.checkNotNull(retryableCodes);
140+
this.innerCallable = Preconditions.checkNotNull(innerCallable, "innerCallable");
141+
this.currentRequest = Preconditions.checkNotNull(originalRequest, "currentRequest");
142+
this.callContext = Preconditions.checkNotNull(callContext, "callContext");
143+
this.retryableCodes = Preconditions.checkNotNull(retryableCodes, "retryableCodes");
144144

145145
permanentFailures = Lists.newArrayList();
146146
}
@@ -167,10 +167,10 @@ public Void call() {
167167
currentRequest.getEntriesCount() > 0, "Request doesn't have any mutations to send");
168168

169169
// Configure the deadline
170-
ApiCallContext currentCallContext = null;
171-
if (callContext != null) {
170+
ApiCallContext currentCallContext = callContext;
171+
if (!externalFuture.getAttemptSettings().getRpcTimeout().isZero()) {
172172
currentCallContext =
173-
callContext.withTimeout(externalFuture.getAttemptSettings().getRpcTimeout());
173+
currentCallContext.withTimeout(externalFuture.getAttemptSettings().getRpcTimeout());
174174
}
175175

176176
// Handle concurrent cancellation

google-cloud-clients/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsAttemptCallableTest.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,28 @@ public void singleEntrySuccessTest() throws Exception {
9292
assertThat(innerCallable.lastRequest).isEqualTo(request);
9393
}
9494

95+
@Test
96+
public void testNoRpcTimeout() {
97+
parentFuture.timedAttemptSettings =
98+
parentFuture.timedAttemptSettings.toBuilder().setRpcTimeout(Duration.ZERO).build();
99+
100+
MutateRowsRequest request =
101+
MutateRowsRequest.newBuilder().addEntries(Entry.getDefaultInstance()).build();
102+
103+
innerCallable.response.add(
104+
MutateRowsResponse.newBuilder()
105+
.addEntries(
106+
MutateRowsResponse.Entry.newBuilder().setIndex(0).setStatus(OK_STATUS_PROTO))
107+
.build());
108+
109+
MutateRowsAttemptCallable attemptCallable =
110+
new MutateRowsAttemptCallable(innerCallable, request, callContext, retryCodes);
111+
attemptCallable.setExternalFuture(parentFuture);
112+
attemptCallable.call();
113+
114+
assertThat(innerCallable.lastContext.getTimeout()).isNull();
115+
}
116+
95117
@Test
96118
public void mixedTest() {
97119
// Setup the request & response
@@ -340,7 +362,7 @@ public ApiFuture<List<MutateRowsResponse>> futureCall(
340362
static class MockRetryingFuture extends AbstractApiFuture<Void> implements RetryingFuture<Void> {
341363
ApiFuture<Void> attemptFuture;
342364

343-
final TimedAttemptSettings timedAttemptSettings;
365+
TimedAttemptSettings timedAttemptSettings;
344366

345367
MockRetryingFuture() {
346368
this(Duration.ofSeconds(5));

0 commit comments

Comments
 (0)