diff options
author | Jack Mulrow <jack.mulrow@mongodb.com> | 2019-01-29 16:02:42 -0500 |
---|---|---|
committer | Jack Mulrow <jack.mulrow@mongodb.com> | 2019-02-08 09:52:12 -0500 |
commit | 315b7197505795f21fb62e69c122833def6cf75a (patch) | |
tree | 6ca8e78862d2bed2a2f386673810d18e89bfa09a /jstests/core/txns/concurrent_drops_and_creates.js | |
parent | b2ab47954087c481722607483cc9868a6cc713e8 (diff) | |
download | mongo-315b7197505795f21fb62e69c122833def6cf75a.tar.gz |
SERVER-39274 Mongos shouldn't upconvert txn read concern level to snapshot if none is provided
Diffstat (limited to 'jstests/core/txns/concurrent_drops_and_creates.js')
-rw-r--r-- | jstests/core/txns/concurrent_drops_and_creates.js | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/jstests/core/txns/concurrent_drops_and_creates.js b/jstests/core/txns/concurrent_drops_and_creates.js index 8db02f1ae98..b458fbd41e5 100644 --- a/jstests/core/txns/concurrent_drops_and_creates.js +++ b/jstests/core/txns/concurrent_drops_and_creates.js @@ -8,8 +8,10 @@ const dbName2 = "test2"; const collNameA = "coll_A"; const collNameB = "coll_B"; - const testDB1 = db.getSiblingDB(dbName1); - const testDB2 = db.getSiblingDB(dbName2); + + const sessionOutsideTxn = db.getMongo().startSession({causalConsistency: true}); + const testDB1 = sessionOutsideTxn.getDatabase(dbName1); + const testDB2 = sessionOutsideTxn.getDatabase(dbName2); testDB1.runCommand({drop: collNameA, writeConcern: {w: "majority"}}); testDB2.runCommand({drop: collNameB, writeConcern: {w: "majority"}}); @@ -20,8 +22,8 @@ const sessionCollB = sessionDB2[collNameB]; // - // A transaction cannot write to a collection that has been dropped since the transaction - // started. + // A transaction with snapshot read concern cannot write to a collection that has been dropped + // since the transaction started. // // Ensure collection A and collection B exist. @@ -29,10 +31,12 @@ assert.commandWorked(sessionCollB.insert({})); // Start the transaction with a write to collection A. - session.startTransaction(); + session.startTransaction({readConcern: {level: "snapshot"}}); assert.commandWorked(sessionCollA.insert({})); - // Drop collection B outside of the transaction. + // Drop collection B outside of the transaction. Advance the cluster time of the session + // performing the drop to ensure it happens at a later cluster time than the transaction began. + sessionOutsideTxn.advanceClusterTime(session.getClusterTime()); assert.commandWorked(testDB2.runCommand({drop: collNameB, writeConcern: {w: "majority"}})); // We cannot write to collection B in the transaction, since it is illegal to implicitly create @@ -45,8 +49,8 @@ ErrorCodes.NoSuchTransaction); // - // A transaction cannot write to a collection that has been created since the transaction - // started. + // A transaction with snapshot read concern cannot write to a collection that has been created + // since the transaction started. // // Ensure collection A exists and collection B does not exist. @@ -54,10 +58,12 @@ testDB2.runCommand({drop: collNameB, writeConcern: {w: "majority"}}); // Start the transaction with a write to collection A. - session.startTransaction(); + session.startTransaction({readConcern: {level: "snapshot"}}); assert.commandWorked(sessionCollA.insert({})); - // Create collection B outside of the transaction. + // Create collection B outside of the transaction. Advance the cluster time of the session + // performing the drop to ensure it happens at a later cluster time than the transaction began. + sessionOutsideTxn.advanceClusterTime(session.getClusterTime()); assert.commandWorked(testDB2.runCommand({create: collNameB})); // We cannot write to collection B in the transaction, since it experienced catalog changes |