diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2021-01-15 14:53:40 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-01-15 23:30:31 +0000 |
commit | bc942ef3f9e7bb0c92147abe9bd680b62ee837c1 (patch) | |
tree | ce90dd141cfc630c8386d62e0a0d268655c20334 | |
parent | 4c9d8a724f85f9bee154397e2ba93e8fee2cd5d5 (diff) | |
download | mongo-bc942ef3f9e7bb0c92147abe9bd680b62ee837c1.tar.gz |
SERVER-53499 Handle UMC commands with requireApiVersion and standalone mongod
-rw-r--r-- | jstests/noPassthrough/require_api_version.js | 125 | ||||
-rw-r--r-- | src/mongo/db/commands/user_management_commands.cpp | 2 |
2 files changed, 70 insertions, 57 deletions
diff --git a/jstests/noPassthrough/require_api_version.js b/jstests/noPassthrough/require_api_version.js index d616d84c406..a6dc59ce70e 100644 --- a/jstests/noPassthrough/require_api_version.js +++ b/jstests/noPassthrough/require_api_version.js @@ -10,7 +10,7 @@ (function() { "use strict"; -function runTest(db, isMongos) { +function runTest(db, supportsTransctions, isMongos) { assert.commandWorked(db.runCommand({setParameter: 1, requireApiVersion: true})); assert.commandFailedWithCode(db.runCommand({ping: 1}), 498870, "command without apiVersion"); assert.commandWorked(db.runCommand({ping: 1, apiVersion: "1"})); @@ -31,73 +31,86 @@ function runTest(db, isMongos) { assert.commandWorked(reply); assert.commandWorked(db.runCommand({getMore: reply.cursor.id, collection: "collection"})); - /* - * Transaction-starting commands must have apiVersion, transaction-continuing commands must not. - */ - const session = db.getMongo().startSession({causalConsistency: false}); - const sessionDb = session.getDatabase(db.getName()); - reply = sessionDb.runCommand({ - find: "collection", - batchSize: 1, - apiVersion: "1", - txnNumber: NumberLong(0), - stmtId: NumberInt(0), - startTransaction: true, - autocommit: false - }); - assert.commandWorked(reply); - assert.commandWorked(sessionDb.runCommand({ - getMore: reply.cursor.id, - collection: "collection", - txnNumber: NumberLong(0), - stmtId: NumberInt(1), - autocommit: false - })); - assert.commandWorked(sessionDb.runCommand({ - find: "collection", - batchSize: 1, - txnNumber: NumberLong(0), - stmtId: NumberInt(2), - autocommit: false - })); - const commitTxnWithApiVersionErrorCode = isMongos ? 4937702 : 4937700; - assert.commandFailedWithCode( - sessionDb.runCommand( - {commitTransaction: 1, apiVersion: "1", txnNumber: NumberLong(0), autocommit: false}), - commitTxnWithApiVersionErrorCode); - assert.commandWorked( - sessionDb.runCommand({commitTransaction: 1, txnNumber: NumberLong(0), autocommit: false})); + if (supportsTransctions) { + /* + * Transaction-starting commands must have apiVersion, transaction-continuing commands must + * not. + */ + const session = db.getMongo().startSession({causalConsistency: false}); + const sessionDb = session.getDatabase(db.getName()); + reply = sessionDb.runCommand({ + find: "collection", + batchSize: 1, + apiVersion: "1", + txnNumber: NumberLong(0), + stmtId: NumberInt(0), + startTransaction: true, + autocommit: false + }); + assert.commandWorked(reply); + assert.commandWorked(sessionDb.runCommand({ + getMore: reply.cursor.id, + collection: "collection", + txnNumber: NumberLong(0), + stmtId: NumberInt(1), + autocommit: false + })); + assert.commandWorked(sessionDb.runCommand({ + find: "collection", + batchSize: 1, + txnNumber: NumberLong(0), + stmtId: NumberInt(2), + autocommit: false + })); + const commitTxnWithApiVersionErrorCode = isMongos ? 4937702 : 4937700; + assert.commandFailedWithCode(sessionDb.runCommand({ + commitTransaction: 1, + apiVersion: "1", + txnNumber: NumberLong(0), + autocommit: false + }), + commitTxnWithApiVersionErrorCode); + assert.commandWorked(sessionDb.runCommand( + {commitTransaction: 1, txnNumber: NumberLong(0), autocommit: false})); - // Start a new txn so we can test abortTransaction. - reply = sessionDb.runCommand({ - find: "collection", - apiVersion: "1", - txnNumber: NumberLong(1), - stmtId: NumberInt(0), - startTransaction: true, - autocommit: false - }); - assert.commandWorked(reply); - const abortTxnWithApiVersionErrorCode = isMongos ? 4937701 : 4937700; - assert.commandFailedWithCode( - sessionDb.runCommand( - {abortTransaction: 1, apiVersion: "1", txnNumber: NumberLong(1), autocommit: false}), - abortTxnWithApiVersionErrorCode); - assert.commandWorked( - sessionDb.runCommand({abortTransaction: 1, txnNumber: NumberLong(1), autocommit: false})); + // Start a new txn so we can test abortTransaction. + reply = sessionDb.runCommand({ + find: "collection", + apiVersion: "1", + txnNumber: NumberLong(1), + stmtId: NumberInt(0), + startTransaction: true, + autocommit: false + }); + assert.commandWorked(reply); + const abortTxnWithApiVersionErrorCode = isMongos ? 4937701 : 4937700; + assert.commandFailedWithCode(sessionDb.runCommand({ + abortTransaction: 1, + apiVersion: "1", + txnNumber: NumberLong(1), + autocommit: false + }), + abortTxnWithApiVersionErrorCode); + assert.commandWorked(sessionDb.runCommand( + {abortTransaction: 1, txnNumber: NumberLong(1), autocommit: false})); + } assert.commandWorked( db.runCommand({setParameter: 1, requireApiVersion: false, apiVersion: "1"})); assert.commandWorked(db.runCommand({ping: 1})); } +const mongod = MongoRunner.runMongod(); +runTest(mongod.getDB("admin"), false /* supportsTransactions */, false /* isMongos */); +MongoRunner.stopMongod(mongod); + const rst = new ReplSetTest({nodes: 1}); rst.startSet(); rst.initiate(); -runTest(rst.getPrimary().getDB("admin"), false /* isMongos */); +runTest(rst.getPrimary().getDB("admin"), true /* supportsTransactions */, false /* isMongos */); rst.stopSet(); const st = new ShardingTest({}); -runTest(st.s0.getDB("admin"), true /* isMongos */); +runTest(st.s0.getDB("admin"), true /* supportsTransactions */, true /* isMongos */); st.stop(); }()); diff --git a/src/mongo/db/commands/user_management_commands.cpp b/src/mongo/db/commands/user_management_commands.cpp index 0d3387048fb..bdbf0d89c2c 100644 --- a/src/mongo/db/commands/user_management_commands.cpp +++ b/src/mongo/db/commands/user_management_commands.cpp @@ -883,7 +883,7 @@ private: _sessionInfo.serialize(cmdBuilder); } - if (_state == TransactionState::kInit) { + if (_state == TransactionState::kInit || !_isReplSet) { // Set a default apiVersion for all UMC commands cmdBuilder->append("apiVersion", kOne); } |