From 246ed94e7fc900e034775c2d60bedde2bf92bce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Jos=C3=A9=20Grillo=20Ram=C3=ADrez?= Date: Mon, 2 Mar 2020 13:20:40 -0500 Subject: SERVER-45779 Throw Stale Shard Version when collection is unknown on getOwnershipFilter --- jstests/core/txns/repeatable_reads_in_transaction.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'jstests/core/txns/repeatable_reads_in_transaction.js') 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})); -- cgit v1.2.1