Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: retry pdml transaction on EOS internal error (#360)
* fix: retries PDML transactions on EOS errors It is possible to have the stream closed with an EOS internal error. This should be retried by the client.
- Loading branch information
1 parent
6125c7d
commit a53d736
Showing
7 changed files
with
357 additions
and
43 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
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,53 @@ | ||
/* | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
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; | ||
|
||
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(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); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
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,28 @@ | ||
/* | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.cloud.spanner; | ||
|
||
import com.google.common.base.Predicate; | ||
import javax.net.ssl.SSLHandshakeException; | ||
|
||
public class IsSslHandshakeException implements Predicate<Throwable> { | ||
|
||
@Override | ||
public boolean apply(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
135 changes: 135 additions & 0 deletions
135
...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,135 @@ | ||
/* | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
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(); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
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,53 @@ | ||
/* | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.cloud.spanner; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import com.google.common.base.Predicate; | ||
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.