|
17 | 17 | package com.mongodb.operation;
|
18 | 18 |
|
19 | 19 | import com.mongodb.MongoException;
|
| 20 | +import com.mongodb.MongoNodeIsRecoveringException; |
| 21 | +import com.mongodb.MongoNotPrimaryException; |
| 22 | +import com.mongodb.MongoSocketException; |
20 | 23 | import com.mongodb.MongoTimeoutException;
|
| 24 | +import com.mongodb.MongoWriteConcernException; |
21 | 25 | import com.mongodb.WriteConcern;
|
22 | 26 | import com.mongodb.async.SingleResultCallback;
|
23 | 27 | import com.mongodb.binding.AsyncWriteBinding;
|
24 | 28 | import com.mongodb.binding.WriteBinding;
|
25 | 29 |
|
| 30 | +import java.util.List; |
| 31 | + |
26 | 32 | 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; |
28 | 34 |
|
29 | 35 | /**
|
30 | 36 | * An operation that commits a transaction.
|
@@ -66,11 +72,33 @@ public void onResult(final Void result, final Throwable t) {
|
66 | 72 | }
|
67 | 73 |
|
68 | 74 | private void addErrorLabels(final MongoException e) {
|
69 |
| - if (isRetryableException(e) || e instanceof MongoTimeoutException) { |
| 75 | + if (shouldAddUnknownTransactionCommitResultLabel(e)) { |
70 | 76 | e.addLabel(UNKNOWN_TRANSACTION_COMMIT_RESULT_LABEL);
|
71 | 77 | }
|
72 | 78 | }
|
73 | 79 |
|
| 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 | + |
74 | 102 | @Override
|
75 | 103 | protected String getCommandName() {
|
76 | 104 | return "commitTransaction";
|
|
0 commit comments