summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands.cpp
diff options
context:
space:
mode:
authorAndrew Chen <andrew.chen@10gen.com>2020-03-09 10:34:30 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-03-09 19:57:46 +0000
commita3915ffe09112029bd195959345f2dcdb4b71ab5 (patch)
treeb8eb353fa1dfad0f10a3a92766d60e5ca8836312 /src/mongo/db/commands.cpp
parentc646b5413e57e97a6cdee224d76c00a21912b23d (diff)
downloadmongo-a3915ffe09112029bd195959345f2dcdb4b71ab5.tar.gz
SERVER-46119: Added runtime server parameter to disable collection and index creation in multi document transactions.
create mode 100644 src/mongo/db/commands_in_multi_doc_txn_params.idl
Diffstat (limited to 'src/mongo/db/commands.cpp')
-rw-r--r--src/mongo/db/commands.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/mongo/db/commands.cpp b/src/mongo/db/commands.cpp
index 142037458bb..b2187a0e697 100644
--- a/src/mongo/db/commands.cpp
+++ b/src/mongo/db/commands.cpp
@@ -49,6 +49,7 @@
#include "mongo/db/client.h"
#include "mongo/db/command_generic_argument.h"
#include "mongo/db/commands/test_commands_enabled.h"
+#include "mongo/db/commands_in_multi_doc_txn_params_gen.h"
#include "mongo/db/curop.h"
#include "mongo/db/error_labels.h"
#include "mongo/db/jsobj.h"
@@ -110,8 +111,7 @@ bool checkAuthorizationImplPreParse(OperationContext* opCtx,
}
// The command names that are allowed in a multi-document transaction.
-const StringMap<int> txnCmdWhitelistFCV44 = {
- {"create", 1}, {"createIndexes", 1}, {"_configsvrCreateCollection", 1}};
+const StringMap<int> txnCmdWhitelistFCV44 = {{"create", 1}, {"createIndexes", 1}};
const StringMap<int> txnCmdWhitelist = {{"abortTransaction", 1},
{"aggregate", 1},
{"commitTransaction", 1},
@@ -496,6 +496,15 @@ void CommandHelpers::canUseTransactions(const NamespaceString& nss,
str::stream() << "Cannot run '" << cmdName << "' in a multi-document transaction.",
inTxnWhitelist || inTxnWhitelistFCV44);
+ if (cmdName == "createCollection"_sd || cmdName == "createIndexes"_sd) {
+ uassert(ErrorCodes::OperationNotSupportedInTransaction,
+ str::stream() << "Cannot run '" << cmdName
+ << "' in a multi-document transaction "
+ "because creation of collections and "
+ "indexes inside multi-document transactions is disabled.",
+ gShouldMultiDocTxnCreateCollectionAndIndexes.load());
+ }
+
const auto dbName = nss.db();
uassert(ErrorCodes::OperationNotSupportedInTransaction,