Skip to content

Commit 9f63882

Browse files
authored
fix: retry rst stream (port of #3000) (#3211)
1 parent c26236c commit 9f63882

4 files changed

Lines changed: 45 additions & 2 deletions

File tree

bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/grpc/async/AbstractRetryingOperation.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ protected void onError(Status status, Metadata trailers) {
203203
String channelId = ChannelPool.extractIdentifier(trailers);
204204
// Non retry scenario
205205
if (!retryOptions.enableRetries()
206-
|| !retryOptions.isRetryable(code)
206+
|| !isStatusRetryable(status)
207207
// Unauthenticated is special because the request never made it to
208208
// to the server, so all requests are retryable
209209
|| !(isRequestRetryable() || code == Code.UNAUTHENTICATED || code == Code.UNAVAILABLE)) {
@@ -263,6 +263,10 @@ protected boolean isRequestRetryable() {
263263
return rpc.isRetryable(getRetryRequest());
264264
}
265265

266+
protected boolean isStatusRetryable(Status status) {
267+
return retryOptions.isRetryable(status.getCode());
268+
}
269+
266270
protected void setException(Exception exception) {
267271
completionFuture.setException(exception);
268272
}

bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/grpc/scanner/RetryingReadRowsOperation.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.google.protobuf.ByteString;
3232
import io.grpc.Metadata;
3333
import io.grpc.Status;
34+
import io.grpc.Status.Code;
3435
import io.grpc.stub.ClientResponseObserver;
3536
import io.grpc.stub.StreamObserver;
3637
import io.opencensus.trace.AttributeValue;
@@ -243,6 +244,24 @@ protected boolean isRequestRetryable() {
243244
return true;
244245
}
245246

247+
/** Read rows requests are retryable if the status is a rst stream error. */
248+
@Override
249+
protected boolean isStatusRetryable(Status status) {
250+
return retryOptions.isRetryable(status.getCode()) || isRstStream(status);
251+
}
252+
253+
private boolean isRstStream(Status status) {
254+
if (status.getCode() == Code.INTERNAL) {
255+
String description = status.getDescription();
256+
if (description != null) {
257+
return description.contains("Received Rst stream")
258+
|| description.contains("RST_STREAM closed stream")
259+
|| description.contains("Received RST_STREAM");
260+
}
261+
}
262+
return false;
263+
}
264+
246265
/** {@inheritDoc} */
247266
@Override
248267
protected boolean onOK(Metadata trailers) {

bigtable-client-core-parent/bigtable-client-core/src/test/java/com/google/cloud/bigtable/grpc/scanner/RetryingReadRowsOperationTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,26 @@ public Void answer(InvocationOnMock invocation) throws Throwable {
513513
Assert.assertTrue(underTest.getRowMerger().isComplete());
514514
}
515515

516+
@Test
517+
public void testRetryRstStream() throws Exception {
518+
RetryingReadRowsOperation underTest = createOperation();
519+
start(underTest);
520+
521+
ByteString key1 = ByteString.copyFrom("SomeKey1", "UTF-8");
522+
ByteString key2 = ByteString.copyFrom("SomeKey2", "UTF-8");
523+
underTest.onMessage(buildResponse(key1));
524+
underTest.onClose(
525+
Status.INTERNAL.withDescription("HTTP/2 error code: INTERNAL_ERROR\nReceived Rst stream"),
526+
null);
527+
Assert.assertFalse(underTest.getRowMerger().isComplete());
528+
underTest.onMessage(buildResponse(key2));
529+
verify(mockFlatRowObserver, times(2)).onNext(any(FlatRow.class));
530+
checkRetryRequest(underTest, key2, 8);
531+
verify(mockClientCall, times(4)).request(eq(1));
532+
533+
finishOK(underTest, 1);
534+
}
535+
516536
protected void performTimeout(RetryingReadRowsOperation underTest) {
517537
underTest.onClose(
518538
Status.CANCELLED.withCause(

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ limitations under the License.
5656
<compileSource.1.8>1.8</compileSource.1.8>
5757

5858
<!-- core dependency versions -->
59-
<bigtable.version>1.22.0-sp.1</bigtable.version>
59+
<bigtable.version>1.22.0-sp.2</bigtable.version>
6060
<dropwizard.metrics.version>3.2.6</dropwizard.metrics.version>
6161
<!-- keeping at this version to align with hbase-->
6262
<slf4j.version>1.7.25</slf4j.version>

0 commit comments

Comments
 (0)