diff options
author | Xiangyu Yao <xiangyu.yao@mongodb.com> | 2019-04-11 17:49:57 -0400 |
---|---|---|
committer | Xiangyu Yao <xiangyu.yao@mongodb.com> | 2019-04-18 14:51:28 -0400 |
commit | 5ad20825e2c02b14f1aeb5bfb4dcc0b4dce927b2 (patch) | |
tree | 2f9e7c1d16b7c0fb03b57d88f2aceefc00bd4c16 /jstests/core/txns | |
parent | b53170282d1e314549350d7124830a2457bad5d6 (diff) | |
download | mongo-5ad20825e2c02b14f1aeb5bfb4dcc0b4dce927b2.tar.gz |
SERVER-39516 Use database MODE_IX lock for creating collection
Diffstat (limited to 'jstests/core/txns')
-rw-r--r-- | jstests/core/txns/create_collection_not_blocked_by_txn.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/jstests/core/txns/create_collection_not_blocked_by_txn.js b/jstests/core/txns/create_collection_not_blocked_by_txn.js new file mode 100644 index 00000000000..730584aeae0 --- /dev/null +++ b/jstests/core/txns/create_collection_not_blocked_by_txn.js @@ -0,0 +1,33 @@ +/** + * Test that create collection only takes database IX lock and will not be blocked by transactions. + * + * @tags: [uses_transactions, requires_db_locking, assumes_unsharded_collection] + */ + +(function() { + "use strict"; + + let rst = new ReplSetTest({nodes: 1}); + rst.startSet(); + rst.initiate(); + + let db = rst.getPrimary().getDB("test"); + + assert.commandWorked(db.runCommand({insert: "a", documents: [{x: 1}]})); + + const session = db.getMongo().startSession(); + const sessionDb = session.getDatabase("test"); + + session.startTransaction(); + // This holds a database IX lock and a collection IX lock on "a". + sessionDb.a.insert({y: 1}); + + // This only requires database IX lock. + assert.commandWorked(db.createCollection("b")); + // Implicit creation. + assert.commandWorked(db.runCommand({insert: "c", documents: [{x: 2}]})); + + session.commitTransaction(); + + rst.stopSet(); +})(); |