Skip to content

retry datastore transactions (#1242)#1932

Merged
neozwu merged 4 commits intogoogleapis:masterfrom
neozwu:retry-runintransaction
Apr 18, 2017
Merged

retry datastore transactions (#1242)#1932
neozwu merged 4 commits intogoogleapis:masterfrom
neozwu:retry-runintransaction

Conversation

@neozwu
Copy link
Copy Markdown
Contributor

@neozwu neozwu commented Apr 17, 2017

enable retry for datastore transactions.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Apr 17, 2017
public RetryResult beforeEval(Exception exception) {
if (exception instanceof DatastoreException) {
DatastoreException e = getInnerException((DatastoreException) exception);
if (e.getCode() == 10 || e.getReason() == "ABORTED") {

This comment was marked as spam.

This comment was marked as spam.

return RetryResult.RETRY;
}
}
return Interceptor.RetryResult.CONTINUE_EVALUATION;

This comment was marked as spam.

This comment was marked as spam.

DatastoreImpl.EXCEPTION_HANDLER_INTERCEPTOR, TRANSACTION_EXCEPTION_HANDLER_INTERCEPTOR)
.build();
}
} No newline at end of file

This comment was marked as spam.

This comment was marked as spam.

transaction.get(KEY1);
if (attempts < 1) {
++attempts;
throw new DatastoreException(10,"","ABORTED",false,null);

This comment was marked as spam.

This comment was marked as spam.

}
};
int result = DATASTORE.runInTransaction(callable);
assertTrue(result == 1);

This comment was marked as spam.

This comment was marked as spam.

}

@Test
public void testRunInTransaction() {

This comment was marked as spam.

This comment was marked as spam.

@coveralls
Copy link
Copy Markdown

Coverage Status

Changes Unknown when pulling 8c4b537 on neozwu:retry-runintransaction into ** on GoogleCloudPlatform:master**.

@neozwu
Copy link
Copy Markdown
Contributor Author

neozwu commented Apr 17, 2017

@garrettjonesgoogle PTAL

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.007%) to 80.934% when pulling 0625f80 on neozwu:retry-runintransaction into b6a87b0 on GoogleCloudPlatform:master.

Copy link
Copy Markdown
Contributor

@garrettjonesgoogle garrettjonesgoogle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after the suggestions below are addressed, and after @vam-google has also given approval.

import com.google.cloud.ExceptionHandler;
import com.google.cloud.ExceptionHandler.Interceptor;

public class TransactionExceptionHandler {

This comment was marked as spam.

public class TransactionExceptionHandler {
public static final Interceptor TRANSACTION_EXCEPTION_HANDLER_INTERCEPTOR =
new Interceptor() {
private final int ABORTED_CODE = 10;

This comment was marked as spam.

public RetryResult beforeEval(Exception exception) {
if (exception instanceof DatastoreException) {
DatastoreException e = getInnerException((DatastoreException) exception);
if (e.getCode() == ABORTED_CODE || e.getReason() == "ABORTED") {

This comment was marked as spam.

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.01%) to 80.928% when pulling 47e086d on neozwu:retry-runintransaction into b6a87b0 on GoogleCloudPlatform:master.

Copy link
Copy Markdown
Contributor

@vam-google vam-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after the review comments are addressed.

public <T> T runInTransaction(TransactionCallable<T> callable) {
return DatastoreHelper.runInTransaction(this, callable);
public <T> T runInTransaction(final TransactionCallable<T> callable) {
ExceptionHandler TRANSACTION_EXCEPTION_HANDLER = TransactionExceptionHandler.build();

This comment was marked as spam.

This comment was marked as spam.


public class TransactionExceptionHandler {
public static final Interceptor TRANSACTION_EXCEPTION_HANDLER_INTERCEPTOR =
new Interceptor() {

This comment was marked as spam.

This comment was marked as spam.


public Integer run(DatastoreReaderWriter transaction) {
transaction.get(KEY1);
if (attempts < 1) {

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@garrettjonesgoogle
Copy link
Copy Markdown
Contributor

LGTM after tests pass

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.002%) to 80.939% when pulling e0aa253 on neozwu:retry-runintransaction into b6a87b0 on GoogleCloudPlatform:master.

@neozwu neozwu merged commit b355f4d into googleapis:master Apr 18, 2017
chingor13 pushed a commit that referenced this pull request Jan 22, 2026
chingor13 pushed a commit that referenced this pull request Feb 20, 2026
🤖 I have created a release *beep* *boop*
---


## [2.28.2](https://togithub.com/googleapis/java-bigquerystorage/compare/v2.28.1...v2.28.2) (2023-01-18)


### Bug Fixes

* Add a timeout on retry for retryable errors ([#1930](https://togithub.com/googleapis/java-bigquerystorage/issues/1930)) ([2d648cf](https://togithub.com/googleapis/java-bigquerystorage/commit/2d648cf9706a6e7bc155e8769ba7dda2a6bc3061))
* Add precision overwritten to 9 digit if the passed in JSON type is FLOAT or DOUBLE ([#1932](https://togithub.com/googleapis/java-bigquerystorage/issues/1932)) ([417bc6c](https://togithub.com/googleapis/java-bigquerystorage/commit/417bc6c76f7b9fa602721c3c183c487c5aab2e09))


### Dependencies

* Update dependency com.google.cloud:google-cloud-bigquery to v2.20.2 ([#1929](https://togithub.com/googleapis/java-bigquerystorage/issues/1929)) ([a95ae9d](https://togithub.com/googleapis/java-bigquerystorage/commit/a95ae9d708bd3e2d8f55297a6004a0d937c8d83f))

---
This PR was generated with [Release Please](https://togithub.com/googleapis/release-please). See [documentation](https://togithub.com/googleapis/release-please#release-please).
lqiu96 pushed a commit that referenced this pull request Mar 20, 2026
suztomo pushed a commit to suztomo/google-cloud-java that referenced this pull request Mar 23, 2026
meltsufin pushed a commit that referenced this pull request Apr 29, 2026
meltsufin pushed a commit that referenced this pull request May 1, 2026
meltsufin pushed a commit that referenced this pull request May 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants