diff options
author | William Schultz <william.schultz@mongodb.com> | 2018-05-01 16:23:24 -0400 |
---|---|---|
committer | William Schultz <william.schultz@mongodb.com> | 2018-05-01 16:27:45 -0400 |
commit | c9a70c9a28a0b2c9ddbd66b5dee2308405a6eb68 (patch) | |
tree | 615aa862d8b37a48e7312ce4c87490055b69404d /jstests/sharding | |
parent | 0c242bc59fd1db69a891c73dc82a29c69f13a400 (diff) | |
download | mongo-c9a70c9a28a0b2c9ddbd66b5dee2308405a6eb68.tar.gz |
SERVER-34520 Forbid multi-document transactions run through mongoS
Diffstat (limited to 'jstests/sharding')
-rw-r--r-- | jstests/sharding/transactions_prohibited_in_sharded_cluster.js | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/jstests/sharding/transactions_prohibited_in_sharded_cluster.js b/jstests/sharding/transactions_prohibited_in_sharded_cluster.js new file mode 100644 index 00000000000..6ad97243043 --- /dev/null +++ b/jstests/sharding/transactions_prohibited_in_sharded_cluster.js @@ -0,0 +1,57 @@ +/** + * Verify that multi-statement transactions are disallowed on mongos. + */ +(function() { + 'use strict'; + + const st = new ShardingTest({shards: 1, mongos: 1, config: 1, rsOptions: {nodes: 1}}); + const mongos = st.s0; + const dbName = "test"; + const collName = "coll"; + + // Start a session on the mongos. + const session = mongos.getDB(dbName).getMongo().startSession(); + const sessionDb = session.getDatabase(dbName); + let txnNumber = 0; + + // Unable to start a transaction via mongos with a read. + assert.commandFailedWithCode(sessionDb.runCommand({ + find: collName, + readConcern: {level: "snapshot"}, + txnNumber: NumberLong(txnNumber++), + startTransaction: true, + autocommit: false + }), + 50841); + + // Unable to start a transaction via mongos with a write. + assert.commandFailedWithCode(sessionDb.runCommand({ + insert: collName, + documents: [{_id: 1}], + readConcern: {level: "snapshot"}, + txnNumber: NumberLong(txnNumber++), + startTransaction: true, + autocommit: false + }), + 50841); + + // 'startTransaction' and 'autocommit' arguments are always rejected by mongos. + assert.commandFailedWithCode(sessionDb.runCommand({ + find: collName, + readConcern: {level: "snapshot"}, + txnNumber: NumberLong(txnNumber++), + autocommit: false + }), + 50841); + + assert.commandFailedWithCode(sessionDb.runCommand({ + find: collName, + readConcern: {level: "snapshot"}, + txnNumber: NumberLong(txnNumber++), + startTransaction: true + }), + 50841); + + st.stop(); + +})(); |