diff options
author | Maria van Keulen <maria@mongodb.com> | 2020-04-08 10:38:29 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-04-10 13:59:44 +0000 |
commit | 76d4548a751a56c8faf1887114685b540203a650 (patch) | |
tree | 589a4cddae9c0dbfcd17299922852dbac81cf4bf /jstests/core | |
parent | 3f2ae017eb48ca739e8f347e47ac0bd9936fc374 (diff) | |
download | mongo-76d4548a751a56c8faf1887114685b540203a650.tar.gz |
SERVER-47400 Disallow createCollection/Indexes on system colls in txns
Diffstat (limited to 'jstests/core')
-rw-r--r-- | jstests/core/txns/no_writes_to_system_collections_in_txn.js | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/jstests/core/txns/no_writes_to_system_collections_in_txn.js b/jstests/core/txns/no_writes_to_system_collections_in_txn.js index a5956723b1e..ab842be7cc1 100644 --- a/jstests/core/txns/no_writes_to_system_collections_in_txn.js +++ b/jstests/core/txns/no_writes_to_system_collections_in_txn.js @@ -3,14 +3,31 @@ (function() { "use strict"; -const session = db.getMongo().startSession({causalConsistency: false}); +const session = db.getMongo().startSession(); // Use a custom database, to avoid conflict with other tests that use the system.js collection. const testDB = session.getDatabase("no_writes_system_collections_in_txn"); assert.commandWorked(testDB.dropDatabase()); -const systemColl = testDB.getCollection("system.js"); +const systemCollName = "system.js"; +const systemColl = testDB.getCollection(systemCollName); const systemDotViews = testDB.getCollection("system.views"); +// createCollection is not presently allowed to run in transactions that have a non-local +// readConcern. +// TODO(SERVER-46971) Replace "local" with "snapshot". +session.startTransaction({readConcern: {level: "local"}}); +assert.commandFailedWithCode(testDB.createCollection(systemCollName), + ErrorCodes.OperationNotSupportedInTransaction); +assert.commandFailedWithCode(session.abortTransaction_forTesting(), ErrorCodes.NoSuchTransaction); + +// createIndexes is not presently allowed to run in transactions that have a non-local +// readConcern. +// TODO(SERVER-46971) Replace "local" with "snapshot". +session.startTransaction({readConcern: {level: "local"}}); +assert.commandFailedWithCode(systemColl.createIndex({name: 1}), + ErrorCodes.OperationNotSupportedInTransaction); +assert.commandFailedWithCode(session.abortTransaction_forTesting(), ErrorCodes.NoSuchTransaction); + // Ensure that a collection exists with at least one document. assert.commandWorked(systemColl.insert({name: 0}, {writeConcern: {w: "majority"}})); |