diff options
author | Tess Avitabile <tess.avitabile@mongodb.com> | 2018-03-27 13:49:52 -0400 |
---|---|---|
committer | Tess Avitabile <tess.avitabile@mongodb.com> | 2018-03-28 13:19:56 -0400 |
commit | 2c801c33889a8ac524d7fbf5f2f7f208e071603b (patch) | |
tree | 7bf7f2a3b9c44ddd560448b4d3d49df81eb59654 /src/mongo/db/ops | |
parent | fe88a7402503f76b43c7ee71ef45b4ac0b9e3db7 (diff) | |
download | mongo-2c801c33889a8ac524d7fbf5f2f7f208e071603b.tar.gz |
SERVER-33263 Fail inserts/upserts in txns that would require implicitly creating the collection
Diffstat (limited to 'src/mongo/db/ops')
-rw-r--r-- | src/mongo/db/ops/write_ops_exec.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/mongo/db/ops/write_ops_exec.cpp b/src/mongo/db/ops/write_ops_exec.cpp index 142c02b2996..29efba88194 100644 --- a/src/mongo/db/ops/write_ops_exec.cpp +++ b/src/mongo/db/ops/write_ops_exec.cpp @@ -182,6 +182,13 @@ void assertCanWrite_inlock(OperationContext* opCtx, const NamespaceString& ns) { } void makeCollection(OperationContext* opCtx, const NamespaceString& ns) { + auto session = OperationContextSession::get(opCtx); + auto inTransaction = session && session->inSnapshotReadOrMultiDocumentTransaction(); + uassert(ErrorCodes::NamespaceNotFound, + str::stream() << "Cannot create namespace " << ns.ns() + << " in multi-document transaction.", + !inTransaction); + writeConflictRetry(opCtx, "implicit collection creation", ns.ns(), [&opCtx, &ns] { AutoGetOrCreateDb db(opCtx, ns.db(), MODE_X); assertCanWrite_inlock(opCtx, ns); |