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: retry pdml transaction on EOS internal error #360
Merged
thiagotnunes
merged 8 commits into
googleapis:master
from
thiagotnunes:retry-pdml-on-eos
Jul 26, 2020
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8a1d690
fix: retries PDML transactions on EOS errors
thiagotnunes d3683b0
Merge branch 'master' of https://github.com/googleapis/java-spanner i…
thiagotnunes 88f4bb5
fix: retries InternalException on PDML transaction
thiagotnunes b145058
refactor: re-uses spanner exception retry logic
thiagotnunes b8da6c1
fix: adds / changes headers in files
thiagotnunes 3be1346
fix: fixes formatting
thiagotnunes 5edd3eb
refactor: removes unused annotation
thiagotnunes 1ff9092
dummy: to re-trigger tests
thiagotnunes File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
google-cloud-spanner/src/main/java/com/google/cloud/spanner/IsRetryableInternalError.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.google.cloud.spanner; | ||
|
||
import com.google.api.gax.rpc.InternalException; | ||
import com.google.common.base.Predicate; | ||
import io.grpc.Status; | ||
import io.grpc.StatusRuntimeException; | ||
import org.checkerframework.checker.nullness.compatqual.NullableDecl; | ||
|
||
public class IsRetryableInternalError implements Predicate<Throwable> { | ||
|
||
private static final String HTTP2_ERROR_MESSAGE = "HTTP/2 error code: INTERNAL_ERROR"; | ||
private static final String CONNECTION_CLOSED_ERROR_MESSAGE = "Connection closed with unknown cause"; | ||
private static final String EOS_ERROR_MESSAGE = "Received unexpected EOS on DATA frame from server"; | ||
|
||
@Override | ||
public boolean apply(@NullableDecl Throwable cause) { | ||
if (isInternalError(cause)) { | ||
if (cause.getMessage().contains(HTTP2_ERROR_MESSAGE)) { | ||
// See b/25451313. | ||
return true; | ||
} else if (cause.getMessage().contains(CONNECTION_CLOSED_ERROR_MESSAGE)) { | ||
// See b/27794742. | ||
return true; | ||
} else if (cause.getMessage().contains(EOS_ERROR_MESSAGE)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
private boolean isInternalError(Throwable cause) { | ||
return (cause instanceof InternalException) | ||
|| (cause instanceof StatusRuntimeException | ||
&& ((StatusRuntimeException) cause).getStatus().getCode() | ||
== Status.Code.INTERNAL); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
google-cloud-spanner/src/main/java/com/google/cloud/spanner/IsSslHandshakeException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.google.cloud.spanner; | ||
|
||
import com.google.common.base.Predicate; | ||
import javax.net.ssl.SSLHandshakeException; | ||
import org.checkerframework.checker.nullness.compatqual.NullableDecl; | ||
|
||
public class IsSslHandshakeException implements Predicate<Throwable> { | ||
|
||
@Override | ||
public boolean apply(@NullableDecl Throwable input) { | ||
return input instanceof SSLHandshakeException; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,12 +26,10 @@ | |
import io.grpc.Context; | ||
import io.grpc.Metadata; | ||
import io.grpc.Status; | ||
import io.grpc.StatusRuntimeException; | ||
import io.grpc.protobuf.ProtoUtils; | ||
import java.util.concurrent.CancellationException; | ||
import java.util.concurrent.TimeoutException; | ||
import javax.annotation.Nullable; | ||
import javax.net.ssl.SSLHandshakeException; | ||
|
||
/** | ||
* A factory for creating instances of {@link SpannerException} and its subtypes. All creation of | ||
|
@@ -40,6 +38,7 @@ | |
* ErrorCode#ABORTED} are always represented by {@link AbortedException}. | ||
*/ | ||
public final class SpannerExceptionFactory { | ||
|
||
static final String SESSION_RESOURCE_TYPE = "type.googleapis.com/google.spanner.v1.Session"; | ||
static final String DATABASE_RESOURCE_TYPE = | ||
"type.googleapis.com/google.spanner.admin.database.v1.Database"; | ||
|
@@ -257,35 +256,8 @@ private static boolean hasCauseMatching( | |
} | ||
|
||
private static class Matchers { | ||
static final Predicate<Throwable> isRetryableInternalError = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I extracted these predicates into their own classes that are now exposed to the |
||
new Predicate<Throwable>() { | ||
@Override | ||
public boolean apply(Throwable cause) { | ||
if (cause instanceof StatusRuntimeException | ||
&& ((StatusRuntimeException) cause).getStatus().getCode() == Status.Code.INTERNAL) { | ||
if (cause.getMessage().contains("HTTP/2 error code: INTERNAL_ERROR")) { | ||
// See b/25451313. | ||
return true; | ||
} | ||
if (cause.getMessage().contains("Connection closed with unknown cause")) { | ||
// See b/27794742. | ||
return true; | ||
} | ||
if (cause | ||
.getMessage() | ||
.contains("Received unexpected EOS on DATA frame from server")) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
}; | ||
static final Predicate<Throwable> isSSLHandshakeException = | ||
new Predicate<Throwable>() { | ||
@Override | ||
public boolean apply(Throwable input) { | ||
return input instanceof SSLHandshakeException; | ||
} | ||
}; | ||
|
||
static final Predicate<Throwable> isRetryableInternalError = new IsRetryableInternalError(); | ||
static final Predicate<Throwable> isSSLHandshakeException = new IsSslHandshakeException(); | ||
} | ||
} |
128 changes: 128 additions & 0 deletions
128
...le-cloud-spanner/src/test/java/com/google/cloud/spanner/IsRetryableInternalErrorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package com.google.cloud.spanner; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import com.google.api.gax.grpc.GrpcStatusCode; | ||
import com.google.api.gax.rpc.InternalException; | ||
import com.google.common.base.Predicate; | ||
import io.grpc.Status; | ||
import io.grpc.Status.Code; | ||
import io.grpc.StatusRuntimeException; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
@SuppressWarnings("unchecked") | ||
@RunWith(JUnit4.class) | ||
public class IsRetryableInternalErrorTest { | ||
|
||
private Predicate<Throwable> predicate; | ||
|
||
@Before | ||
public void setUp() { | ||
predicate = new IsRetryableInternalError(); | ||
} | ||
|
||
@Test | ||
public void http2ErrorStatusRuntimeExceptionIsRetryable() { | ||
final StatusRuntimeException e = new StatusRuntimeException( | ||
Status | ||
.fromCode(Code.INTERNAL) | ||
.withDescription("INTERNAL: HTTP/2 error code: INTERNAL_ERROR.") | ||
); | ||
|
||
assertThat(predicate.apply(e)).isTrue(); | ||
} | ||
|
||
@Test | ||
public void http2ErrorInternalExceptionIsRetryable() { | ||
final InternalException e = new InternalException( | ||
"INTERNAL: HTTP/2 error code: INTERNAL_ERROR.", | ||
null, | ||
GrpcStatusCode.of(Code.INTERNAL), | ||
false | ||
); | ||
|
||
assertThat(predicate.apply(e)).isTrue(); | ||
} | ||
|
||
@Test | ||
public void connectionClosedStatusRuntimeExceptionIsRetryable() { | ||
final StatusRuntimeException e = new StatusRuntimeException( | ||
Status | ||
.fromCode(Code.INTERNAL) | ||
.withDescription("INTERNAL: Connection closed with unknown cause.") | ||
); | ||
|
||
assertThat(predicate.apply(e)).isTrue(); | ||
} | ||
|
||
@Test | ||
public void connectionClosedInternalExceptionIsRetryable() { | ||
final InternalException e = new InternalException( | ||
"INTERNAL: Connection closed with unknown cause.", | ||
null, | ||
GrpcStatusCode.of(Code.INTERNAL), | ||
false | ||
); | ||
|
||
assertThat(predicate.apply(e)).isTrue(); | ||
} | ||
|
||
@Test | ||
public void eosStatusRuntimeExceptionIsRetryable() { | ||
final StatusRuntimeException e = new StatusRuntimeException( | ||
Status | ||
.fromCode(Code.INTERNAL) | ||
.withDescription("INTERNAL: Received unexpected EOS on DATA frame from server.") | ||
); | ||
|
||
assertThat(predicate.apply(e)).isTrue(); | ||
} | ||
|
||
@Test | ||
public void eosInternalExceptionIsRetryable() { | ||
final InternalException e = new InternalException( | ||
"INTERNAL: Received unexpected EOS on DATA frame from server.", | ||
null, | ||
GrpcStatusCode.of(Code.INTERNAL), | ||
false | ||
); | ||
|
||
assertThat(predicate.apply(e)).isTrue(); | ||
} | ||
|
||
@Test | ||
public void genericInternalStatusRuntimeExceptionIsRetryable() { | ||
final StatusRuntimeException e = new StatusRuntimeException( | ||
Status | ||
.fromCode(Code.INTERNAL) | ||
.withDescription("INTERNAL: Generic.") | ||
); | ||
|
||
assertThat(predicate.apply(e)).isFalse(); | ||
} | ||
|
||
@Test | ||
public void genericInternalExceptionIsNotRetryable() { | ||
final InternalException e = new InternalException( | ||
"INTERNAL: Generic.", | ||
null, | ||
GrpcStatusCode.of(Code.INTERNAL), | ||
false | ||
); | ||
|
||
assertThat(predicate.apply(e)).isFalse(); | ||
} | ||
|
||
@Test | ||
public void nullIsNotRetryable() { | ||
assertThat(predicate.apply(null)).isFalse(); | ||
} | ||
|
||
@Test | ||
public void genericExceptionIsNotRetryable() { | ||
assertThat(predicate.apply(new Exception())).isFalse(); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
google-cloud-spanner/src/test/java/com/google/cloud/spanner/IsSslHandshakeExceptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.google.cloud.spanner; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import com.google.api.gax.grpc.GrpcStatusCode; | ||
import com.google.api.gax.rpc.InternalException; | ||
import com.google.common.base.Predicate; | ||
import io.grpc.Status; | ||
import io.grpc.Status.Code; | ||
import io.grpc.StatusRuntimeException; | ||
import javax.net.ssl.SSLHandshakeException; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
@SuppressWarnings("unchecked") | ||
@RunWith(JUnit4.class) | ||
public class IsSslHandshakeExceptionTest { | ||
|
||
private Predicate<Throwable> predicate; | ||
|
||
@Before | ||
public void setUp() { | ||
predicate = new IsSslHandshakeException(); | ||
} | ||
|
||
@Test | ||
public void sslHandshakeExceptionIsTrue() { | ||
assertThat(predicate.apply(new SSLHandshakeException("test"))).isTrue(); | ||
} | ||
|
||
@Test | ||
public void genericExceptionIsNotSslHandshakeException() { | ||
assertThat(predicate.apply(new Exception("test"))).isFalse(); | ||
} | ||
|
||
@Test | ||
public void nullIsNotSslHandshakeException() { | ||
assertThat(predicate.apply(null)).isFalse(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and below, if we could remove the references to internal issues that would be great. I don't know why they were there before. Folks working on this repo are unlikely to have access to those so no point exposing them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, will tackle this in a following PR.