Skip to content

Commit 193cce8

Browse files
committed
JAVA-2815: Add UnknownTransactionCommitResult error label
Update UnknownTransactionCommitResult error labelling to reflect the specification
1 parent 9ad83aa commit 193cce8

File tree

4 files changed

+576
-10
lines changed

4 files changed

+576
-10
lines changed

driver-core/src/main/com/mongodb/operation/CommitTransactionOperation.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,20 @@
1717
package com.mongodb.operation;
1818

1919
import com.mongodb.MongoException;
20+
import com.mongodb.MongoNodeIsRecoveringException;
21+
import com.mongodb.MongoNotPrimaryException;
22+
import com.mongodb.MongoSocketException;
2023
import com.mongodb.MongoTimeoutException;
24+
import com.mongodb.MongoWriteConcernException;
2125
import com.mongodb.WriteConcern;
2226
import com.mongodb.async.SingleResultCallback;
2327
import com.mongodb.binding.AsyncWriteBinding;
2428
import com.mongodb.binding.WriteBinding;
2529

30+
import java.util.List;
31+
2632
import static com.mongodb.MongoException.UNKNOWN_TRANSACTION_COMMIT_RESULT_LABEL;
27-
import static com.mongodb.operation.CommandOperationHelper.isRetryableException;
33+
import static java.util.Arrays.asList;
2834

2935
/**
3036
* An operation that commits a transaction.
@@ -66,11 +72,33 @@ public void onResult(final Void result, final Throwable t) {
6672
}
6773

6874
private void addErrorLabels(final MongoException e) {
69-
if (isRetryableException(e) || e instanceof MongoTimeoutException) {
75+
if (shouldAddUnknownTransactionCommitResultLabel(e)) {
7076
e.addLabel(UNKNOWN_TRANSACTION_COMMIT_RESULT_LABEL);
7177
}
7278
}
7379

80+
private static final List<Integer> NON_RETRYABLE_WRITE_CONCERN_ERROR_CODES = asList(79, 100);
81+
82+
static boolean shouldAddUnknownTransactionCommitResultLabel(final Throwable t) {
83+
if (!(t instanceof MongoException)) {
84+
return false;
85+
}
86+
87+
MongoException e = (MongoException) t;
88+
89+
if (e instanceof MongoSocketException || e instanceof MongoTimeoutException
90+
|| e instanceof MongoNotPrimaryException || e instanceof MongoNodeIsRecoveringException) {
91+
return true;
92+
}
93+
94+
if (e instanceof MongoWriteConcernException) {
95+
return !NON_RETRYABLE_WRITE_CONCERN_ERROR_CODES.contains(e.getCode());
96+
}
97+
98+
return false;
99+
}
100+
101+
74102
@Override
75103
protected String getCommandName() {
76104
return "commitTransaction";

driver-core/src/test/resources/transactions/README.rst

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ Use as integration tests
140140
========================
141141

142142
Run a MongoDB replica set with a primary, a secondary, and an arbiter,
143-
server version 4.0 or later. (Including a secondary ensures that server
144-
selection in a transaction works properly. Including an arbiter helps ensure
145-
that no new bugs have been introduced related to arbiters.)
143+
**server version 4.0.0-rc4 or later**. (Including a secondary ensures that
144+
server selection in a transaction works properly. Including an arbiter helps
145+
ensure that no new bugs have been introduced related to arbiters.)
146146

147147
Load each YAML (or JSON) file using a Canonical Extended JSON parser.
148148

@@ -232,11 +232,6 @@ Then for each element in ``tests``:
232232
Primary read preference even when the MongoClient is configured with
233233
another read preference.
234234

235-
TODO:
236-
237-
- drivers MUST retry commit/abort, needs to use failpoint.
238-
- test writeConcernErrors
239-
240235
Command-Started Events
241236
``````````````````````
242237

0 commit comments

Comments
 (0)