summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Witten <andrew.witten@mongodb.com>2022-04-25 20:41:20 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-05-05 18:18:54 +0000
commitbc1ac35debfc926c3d12f11f5ca7230010aacd55 (patch)
tree711a71fe60c584b07d2d83ea8bfc745b8c626892
parentd03ca3eebefaca35c6d6f1238034f9a964679e79 (diff)
downloadmongo-bc1ac35debfc926c3d12f11f5ca7230010aacd55.tar.gz
SERVER-65633 retry commitTransaction on FailedToSatisfyReadPreference
(cherry picked from commit e90e25cc5ad352d0c8b074f0ad49945b483d7131)
-rw-r--r--jstests/concurrency/fsm_workload_helpers/auto_retry_transaction.js26
1 files changed, 13 insertions, 13 deletions
diff --git a/jstests/concurrency/fsm_workload_helpers/auto_retry_transaction.js b/jstests/concurrency/fsm_workload_helpers/auto_retry_transaction.js
index 30fdaa89e5f..3d6fc856624 100644
--- a/jstests/concurrency/fsm_workload_helpers/auto_retry_transaction.js
+++ b/jstests/concurrency/fsm_workload_helpers/auto_retry_transaction.js
@@ -35,7 +35,7 @@ var {withTxnAndAutoRetry, isKilledSessionCode} = (function() {
// Don't retry the entire transaction on commit errors that aren't labeled as transient
// transaction errors because it's unknown if the commit succeeded. commitTransaction is
// individually retryable and should be retried at a lower level (e.g.
- // network_error_and_txn_override.js or commitTransactionWithKilledSessionRetries()), so any
+ // network_error_and_txn_override.js or commitTransactionWithRetries()), so any
// error that reached here must not be transient.
if (hasCommitTxnError) {
print("-=-=-=- Cannot retry entire transaction on commit transaction error without" +
@@ -60,8 +60,9 @@ var {withTxnAndAutoRetry, isKilledSessionCode} = (function() {
}
// Commits the transaction active on the given session, retrying on killed session errors if
- // configured to do so. Throws if the commit fails and cannot be retried.
- function commitTransactionWithKilledSessionRetries(session, retryOnKilledSession) {
+ // configured to do so. Also retries commitTransaction on FailedToSatisfyReadPreference error.
+ // Throws if the commit fails and cannot be retried.
+ function commitTransactionWithRetries(session, retryOnKilledSession) {
while (true) {
const commitRes = session.commitTransaction_forTesting();
@@ -76,6 +77,14 @@ var {withTxnAndAutoRetry, isKilledSessionCode} = (function() {
continue;
}
+ if (commitRes.code === ErrorCodes.FailedToSatisfyReadPreference) {
+ print("-=-=-=- Retrying commit due to FailedToSatisfyReadPreference, sessionId: " +
+ tojsononeline(session.getSessionId()) +
+ ", txnNumber: " + tojsononeline(session.getTxnNumber_forTesting()) +
+ ", res: " + tojsononeline(commitRes));
+ continue;
+ }
+
// Use assert.commandWorked() because it throws an exception in the format expected by
// the caller of this function if the commit failed. Committing may fail with a
// transient error that can be retried on at a higher level, so suppress unnecessary
@@ -139,7 +148,7 @@ var {withTxnAndAutoRetry, isKilledSessionCode} = (function() {
const prepareTimestamp = PrepareHelpers.prepareTransaction(session);
PrepareHelpers.commitTransaction(session, prepareTimestamp);
} else {
- commitTransactionWithKilledSessionRetries(session, retryOnKilledSession);
+ commitTransactionWithRetries(session, retryOnKilledSession);
}
} catch (e) {
hasCommitTxnError = true;
@@ -165,15 +174,6 @@ var {withTxnAndAutoRetry, isKilledSessionCode} = (function() {
continue;
}
- // FailedToSatisfyReadPreference errors are not retryable.
- // However, they should be because if there is no primary, there should be one soon.
- // TODO SERVER-60706: Make FailedToSatisfyReadPreference a transient error
- if (e.code == ErrorCodes.FailedToSatisfyReadPreference) {
- print("Retrying transaction due to a FailedToSatisfyReadPreference error.");
- hasTransientError = true;
- continue;
- }
-
throw e;
}
} while (hasTransientError);