Skip to content

Commit 2a1b018

Browse files
committed
Retry ABORTED Datastore commit only when NON_TRANSACTIONAL
1 parent b8a33ae commit 2a1b018

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreException.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,18 @@ public final class DatastoreException extends BaseServiceException {
3838
private static final long serialVersionUID = 2663750991205874435L;
3939

4040
public DatastoreException(int code, String message, String reason) {
41-
this(code, message, reason, null);
41+
this(code, message, reason, true, null);
4242
}
4343

4444
public DatastoreException(int code, String message, String reason, Throwable cause) {
4545
super(code, message, reason, true, cause);
4646
}
4747

48+
public DatastoreException(int code, String message, String reason, boolean idempotent,
49+
Throwable cause) {
50+
super(code, message, reason, idempotent, cause);
51+
}
52+
4853
public DatastoreException(IOException exception) {
4954
super(exception, true);
5055
}

google-cloud-datastore/src/main/java/com/google/cloud/datastore/spi/DefaultDatastoreRpc.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ private static String removeScheme(String url) {
9393

9494
private static DatastoreException translate(
9595
com.google.datastore.v1.client.DatastoreException exception) {
96+
return translate(exception, true);
97+
}
98+
99+
private static DatastoreException translate(
100+
com.google.datastore.v1.client.DatastoreException exception, boolean idempotent) {
96101
String reason = "";
97102
if (exception.getCode() != null) {
98103
reason = exception.getCode().name();
@@ -103,15 +108,14 @@ private static DatastoreException translate(
103108
}
104109
}
105110
return new DatastoreException(
106-
exception.getCode().getNumber(), exception.getMessage(), reason, exception);
111+
exception.getCode().getNumber(), exception.getMessage(), reason, idempotent, exception);
107112
}
108113

109114
@Override
110115
public AllocateIdsResponse allocateIds(AllocateIdsRequest request) {
111116
try {
112117
return client.allocateIds(request);
113118
} catch (com.google.datastore.v1.client.DatastoreException ex) {
114-
115119
throw translate(ex);
116120
}
117121
}
@@ -130,7 +134,7 @@ public CommitResponse commit(CommitRequest request) {
130134
try {
131135
return client.commit(request);
132136
} catch (com.google.datastore.v1.client.DatastoreException ex) {
133-
throw translate(ex);
137+
throw translate(ex, request.getMode() == CommitRequest.Mode.NON_TRANSACTIONAL);
134138
}
135139
}
136140

0 commit comments

Comments
 (0)