summaryrefslogtreecommitdiff
path: root/jstests/core/txns/repeatable_reads_in_transaction.js
diff options
context:
space:
mode:
authorMarcos José Grillo Ramírez <marcos.grillo@mongodb.com>2020-03-02 13:20:40 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-03-04 20:32:41 +0000
commit246ed94e7fc900e034775c2d60bedde2bf92bce2 (patch)
tree6fdf189d27321b04cc554f61a3d05009103d58e5 /jstests/core/txns/repeatable_reads_in_transaction.js
parentc752f2b20efee7de94123787950415723c38b91f (diff)
downloadmongo-246ed94e7fc900e034775c2d60bedde2bf92bce2.tar.gz
SERVER-45779 Throw Stale Shard Version when collection is unknown on getOwnershipFilter
Diffstat (limited to 'jstests/core/txns/repeatable_reads_in_transaction.js')
-rw-r--r--jstests/core/txns/repeatable_reads_in_transaction.js18
1 files changed, 16 insertions, 2 deletions
diff --git a/jstests/core/txns/repeatable_reads_in_transaction.js b/jstests/core/txns/repeatable_reads_in_transaction.js
index 870a1d58e6f..fbfb34ed1de 100644
--- a/jstests/core/txns/repeatable_reads_in_transaction.js
+++ b/jstests/core/txns/repeatable_reads_in_transaction.js
@@ -4,6 +4,10 @@
(function() {
"use strict";
+// TODO (SERVER-39704): Remove the following load after SERVER-397074 is completed
+// For retryOnceOnTransientAndRestartTxnOnMongos.
+load('jstests/libs/auto_retry_transaction_in_sharding.js');
+
const dbName = "test";
const collName = "repeatable_reads_in_transaction";
const testDB = db.getSiblingDB(dbName);
@@ -24,6 +28,9 @@ const sessionColl = sessionDb.getCollection(collName);
const session2 = testDB.getMongo().startSession(sessionOptions);
const session2Db = session2.getDatabase(dbName);
const session2Coll = session2Db.getCollection(collName);
+const txnOptions = {
+ writeConcern: {w: "majority"}
+};
jsTest.log("Prepopulate the collection.");
assert.commandWorked(
@@ -35,14 +42,21 @@ assert.commandWorked(
const expectedDocs = [{_id: 0}, {_id: 1}, {_id: 2}];
jsTestLog("Start a read-only transaction on the first session.");
-session.startTransaction({writeConcern: {w: "majority"}});
+session.startTransaction(txnOptions);
assert.sameMembers(expectedDocs, sessionColl.find().toArray());
jsTestLog("Start a transaction on the second session that modifies the same collection.");
session2.startTransaction({readConcern: {level: "snapshot"}, writeConcern: {w: "majority"}});
-assert.commandWorked(session2Coll.insert({_id: 3}));
+// TODO (SERVER-39704): We use the retryOnceOnTransientAndRestartTxnOnMongos
+// function to handle how MongoS will propagate a StaleShardVersion error as a
+// TransientTransactionError. After SERVER-39704 is completed the
+// retryOnceOnTransientAndRestartTxnOnMongos can be removed
+retryOnceOnTransientAndRestartTxnOnMongos(session2, () => {
+ assert.commandWorked(session2Coll.insert({_id: 3}));
+}, txnOptions);
+
assert.commandWorked(session2Coll.update({_id: 1}, {$set: {a: 1}}));
assert.commandWorked(session2Coll.deleteOne({_id: 2}));