summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorMaria van Keulen <maria@mongodb.com>2020-04-28 17:23:52 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-05-08 19:55:54 +0000
commitab533026f3c32a4305a641a9b9a389ce5f769890 (patch)
treebb5edb91e00352faf1f0cb0e7792d1323d360016 /jstests
parent104f59d61c0f314769a41671c9f68094810831e2 (diff)
downloadmongo-ab533026f3c32a4305a641a9b9a389ce5f769890.tar.gz
SERVER-46900 Prohibit transaction operations on system.profile
(cherry picked from commit e4821bc15a083d1d156fa1ff7330ad5a1f985f9c)
Diffstat (limited to 'jstests')
-rw-r--r--jstests/core/txns/banned_collection_reads_in_txn.js (renamed from jstests/core/txns/no_reads_from_system_dot_views_in_txn.js)15
-rw-r--r--jstests/core/txns/no_writes_to_system_collections_in_txn.js7
-rw-r--r--jstests/libs/override_methods/network_error_and_txn_override.js21
-rw-r--r--jstests/libs/txns/txn_passthrough_runner_selftest.js12
4 files changed, 42 insertions, 13 deletions
diff --git a/jstests/core/txns/no_reads_from_system_dot_views_in_txn.js b/jstests/core/txns/banned_collection_reads_in_txn.js
index 808bc8dbb72..5c3dbe070b0 100644
--- a/jstests/core/txns/no_reads_from_system_dot_views_in_txn.js
+++ b/jstests/core/txns/banned_collection_reads_in_txn.js
@@ -1,14 +1,14 @@
-// Tests that it is illegal to read from system.views within a transaction.
-// @tags: [uses_transactions, uses_snapshot_read_concern]
+// Tests that it is illegal to read from system.views and system.profile within a transaction.
+// @tags: [requires_fcv_44, uses_transactions, uses_snapshot_read_concern]
(function() {
"use strict";
load("jstests/libs/fixture_helpers.js"); // For 'FixtureHelpers'.
-const session = db.getMongo().startSession({causalConsistency: false});
+const session = db.getMongo().startSession();
-// Use a custom database to avoid conflict with other tests that use system.views.
-const testDB = session.getDatabase("no_reads_from_system_dot_views_in_txn");
+// Use a custom database to avoid conflict with other tests.
+const testDB = session.getDatabase("no_reads_from_system_colls_in_txn");
assert.commandWorked(testDB.dropDatabase());
testDB.runCommand({create: "foo", viewOn: "bar", pipeline: []});
@@ -17,6 +17,11 @@ session.startTransaction({readConcern: {level: "snapshot"}});
assert.commandFailedWithCode(testDB.runCommand({find: "system.views", filter: {}}), 51071);
assert.commandFailedWithCode(session.abortTransaction_forTesting(), ErrorCodes.NoSuchTransaction);
+session.startTransaction({readConcern: {level: "snapshot"}});
+assert.commandFailedWithCode(testDB.runCommand({find: "system.profile", filter: {}}),
+ ErrorCodes.OperationNotSupportedInTransaction);
+assert.commandFailedWithCode(session.abortTransaction_forTesting(), ErrorCodes.NoSuchTransaction);
+
if (FixtureHelpers.isMongos(testDB)) {
// The rest of the test is concerned with a find by UUID which is not supported against
// mongos.
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 ab842be7cc1..29882a07499 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
@@ -1,5 +1,5 @@
// Tests that it is illegal to write to system collections within a transaction.
-// @tags: [uses_transactions, uses_snapshot_read_concern]
+// @tags: [requires_fcv_44, uses_transactions, uses_snapshot_read_concern]
(function() {
"use strict";
@@ -46,6 +46,11 @@ assert.commandFailedWithCode(systemColl.insert({name: "new"}), 50791);
assert.commandFailedWithCode(session.abortTransaction_forTesting(), ErrorCodes.NoSuchTransaction);
session.startTransaction({readConcern: {level: "snapshot"}});
+assert.commandFailedWithCode(testDB.getCollection("system.profile").insert({name: "new"}),
+ ErrorCodes.OperationNotSupportedInTransaction);
+assert.commandFailedWithCode(session.abortTransaction_forTesting(), ErrorCodes.NoSuchTransaction);
+
+session.startTransaction({readConcern: {level: "snapshot"}});
assert.commandFailedWithCode(systemDotViews.insert({_id: "new.view", viewOn: "bar", pipeline: []}),
50791);
assert.commandFailedWithCode(session.abortTransaction_forTesting(), ErrorCodes.NoSuchTransaction);
diff --git a/jstests/libs/override_methods/network_error_and_txn_override.js b/jstests/libs/override_methods/network_error_and_txn_override.js
index de7c9d24a92..798d9bf7fda 100644
--- a/jstests/libs/override_methods/network_error_and_txn_override.js
+++ b/jstests/libs/override_methods/network_error_and_txn_override.js
@@ -587,6 +587,16 @@ function isCommandNonTxnGetMore(cmdName, cmdObj) {
return cmdName === "getMore" && nonTxnAggCursorSet[cmdObj.getMore];
}
+function isNamespaceSystemDotProfile(cmdObj) {
+ // No operations on system.profile are permitted inside transactions (see SERVER-46900).
+ for (let val of Object.values(cmdObj)) {
+ if (typeof val === 'string' && val.endsWith('system.profile')) {
+ return true;
+ }
+ }
+ return false;
+}
+
function setupTransactionCommand(conn, dbName, cmdName, cmdObj, lsid) {
// We want to overwrite whatever read and write concern is already set.
delete cmdObj.readConcern;
@@ -596,8 +606,10 @@ function setupTransactionCommand(conn, dbName, cmdName, cmdObj, lsid) {
// use transactions.
const driverSession = conn.getDB(dbName).getSession();
const commandSupportsTransaction = TransactionsUtil.commandSupportsTxn(dbName, cmdName, cmdObj);
- if (commandSupportsTransaction && driverSession.getSessionId() !== null &&
- !isCommandNonTxnGetMore(cmdName, cmdObj)) {
+ const isSystemDotProfile = isNamespaceSystemDotProfile(cmdObj);
+
+ if (commandSupportsTransaction && !isSystemDotProfile &&
+ driverSession.getSessionId() !== null && !isCommandNonTxnGetMore(cmdName, cmdObj)) {
if (isNested()) {
// Nested commands should never start a new transaction.
} else if (ops.length === 0) {
@@ -616,7 +628,10 @@ function setupTransactionCommand(conn, dbName, cmdName, cmdObj, lsid) {
continueTransaction(conn, dbName, cmdName, cmdObj);
} else {
- if (ops.length > 0 && !isNested()) {
+ if (ops.length > 0 && !isNested() && !isSystemDotProfile) {
+ // Operations on system.profile must be allowed to execute in parallel with open
+ // transactions, so operations on system.profile should not commit the current open
+ // transaction.
logMsgFull('setupTransactionCommand',
`Committing transaction ${txnOptions.txnNumber} on session` +
` ${tojsononeline(lsid)} to run a command that does not support` +
diff --git a/jstests/libs/txns/txn_passthrough_runner_selftest.js b/jstests/libs/txns/txn_passthrough_runner_selftest.js
index e7a6b0db552..86a95565f87 100644
--- a/jstests/libs/txns/txn_passthrough_runner_selftest.js
+++ b/jstests/libs/txns/txn_passthrough_runner_selftest.js
@@ -15,16 +15,20 @@ db.setProfilingLevel(2);
const coll = db[testName];
assert.commandWorked(coll.insert({x: 1}));
+/* TODO(SERVER-47835) unblacklist
let commands = db.system.profile.find().toArray();
// Check that the insert is not visible because the txn has not committed.
assert.eq(commands.length, 0);
-
+*/
// Use a dummy, unrelated operation to signal the txn runner to commit the transaction.
assert.commandWorked(db.runCommand({ping: 1}));
-commands = db.system.profile.find().toArray();
+let commands = db.system.profile.find().toArray();
// Assert the insert is now visible.
-assert.eq(commands.length, 2);
+assert.eq(commands.length, 1);
+/* TODO(SERVER-47835) replace above assertion with below assertion.
+assert.eq(commands.length, 2);*/
+/* TODO(SERVER-47835) uncomment
+assert.eq(commands[1].command.find, 'system.profile');*/
assert.eq(commands[0].command.insert, testName);
-assert.eq(commands[1].command.find, 'system.profile');
})();