diff options
author | Jennifer Peshansky <jennifer.peshansky@mongodb.com> | 2022-02-18 16:36:26 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-03-01 20:07:25 +0000 |
commit | 129289774be78f67fc03bfcf2e358118263d5da1 (patch) | |
tree | ca010606587100da26d003188afb00a634d562ef | |
parent | 97d77fc98b26331b280966bbc9b3787dc26e64cb (diff) | |
download | mongo-129289774be78f67fc03bfcf2e358118263d5da1.tar.gz |
SERVER-61769 Remove inMultiDocumentTransaction from expCtx
(cherry picked from commit 9b4519e5436a970b90a966cdc16dd8129833a9ae)
-rw-r--r-- | jstests/core/update_with_pipeline.js | 6 | ||||
-rw-r--r-- | src/mongo/db/commands/run_aggregate.cpp | 1 | ||||
-rw-r--r-- | src/mongo/db/pipeline/document_source_merge.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/pipeline/document_source_out.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/pipeline/expression_context.cpp | 1 | ||||
-rw-r--r-- | src/mongo/db/pipeline/expression_context.h | 1 | ||||
-rw-r--r-- | src/mongo/db/pipeline/pipeline.cpp | 9 | ||||
-rw-r--r-- | src/mongo/db/pipeline/pipeline_test.cpp | 4 |
8 files changed, 14 insertions, 12 deletions
diff --git a/jstests/core/update_with_pipeline.js b/jstests/core/update_with_pipeline.js index 5e7179ae5b9..819f638e05d 100644 --- a/jstests/core/update_with_pipeline.js +++ b/jstests/core/update_with_pipeline.js @@ -180,7 +180,6 @@ assert.commandFailedWithCode(coll.update({x: 1}, [{$match: {x: 1}}]), ErrorCodes assert.commandFailedWithCode(coll.update({x: 1}, [{$sort: {x: 1}}]), ErrorCodes.InvalidOptions); assert.commandFailedWithCode(coll.update({x: 1}, [{$facet: {a: [{$match: {x: 1}}]}}]), ErrorCodes.InvalidOptions); -assert.commandFailedWithCode(coll.update({x: 1}, [{$indexStats: {}}]), ErrorCodes.InvalidOptions); assert.commandFailedWithCode( coll.update( {x: 1}, [{ @@ -198,6 +197,11 @@ assert.commandFailedWithCode( }]), ErrorCodes.InvalidOptions); +// $indexStats is not supported in a transaction passthrough and will fail with a different error. +assert.commandFailedWithCode( + coll.update({x: 1}, [{$indexStats: {}}]), + [ErrorCodes.InvalidOptions, ErrorCodes.OperationNotSupportedInTransaction]); + // Update fails when supported agg stage is specified outside of pipeline. assert.commandFailedWithCode(coll.update({_id: 1}, {$addFields: {x: 1}}), ErrorCodes.FailedToParse); diff --git a/src/mongo/db/commands/run_aggregate.cpp b/src/mongo/db/commands/run_aggregate.cpp index cc5744e7334..e20b3fb8087 100644 --- a/src/mongo/db/commands/run_aggregate.cpp +++ b/src/mongo/db/commands/run_aggregate.cpp @@ -448,7 +448,6 @@ boost::intrusive_ptr<ExpressionContext> makeExpressionContext( uuid, CurOp::get(opCtx)->dbProfileLevel() > 0); expCtx->tempDir = storageGlobalParams.dbpath + "/_tmp"; - expCtx->inMultiDocumentTransaction = opCtx->inMultiDocumentTransaction(); expCtx->collationMatchesDefault = collationMatchesDefault; return expCtx; diff --git a/src/mongo/db/pipeline/document_source_merge.cpp b/src/mongo/db/pipeline/document_source_merge.cpp index 80daf31c772..96a1dd55547 100644 --- a/src/mongo/db/pipeline/document_source_merge.cpp +++ b/src/mongo/db/pipeline/document_source_merge.cpp @@ -404,7 +404,7 @@ boost::intrusive_ptr<DocumentSource> DocumentSourceMerge::create( uassert(ErrorCodes::OperationNotSupportedInTransaction, "{} cannot be used in a transaction"_format(kStageName), - !expCtx->inMultiDocumentTransaction); + !expCtx->opCtx->inMultiDocumentTransaction()); uassert(31319, "Cannot {} to special collection: {}"_format(kStageName, outputNs.coll()), diff --git a/src/mongo/db/pipeline/document_source_out.cpp b/src/mongo/db/pipeline/document_source_out.cpp index 5f97cbb0555..9be7c7a24ba 100644 --- a/src/mongo/db/pipeline/document_source_out.cpp +++ b/src/mongo/db/pipeline/document_source_out.cpp @@ -182,7 +182,7 @@ boost::intrusive_ptr<DocumentSource> DocumentSourceOut::create( uassert(ErrorCodes::OperationNotSupportedInTransaction, "{} cannot be used in a transaction"_format(kStageName), - !expCtx->inMultiDocumentTransaction); + !expCtx->opCtx->inMultiDocumentTransaction()); uassert(ErrorCodes::InvalidNamespace, "Invalid {} target namespace, {}"_format(kStageName, outputNs.ns()), diff --git a/src/mongo/db/pipeline/expression_context.cpp b/src/mongo/db/pipeline/expression_context.cpp index 8e3a06d8a13..a76f14e4ee2 100644 --- a/src/mongo/db/pipeline/expression_context.cpp +++ b/src/mongo/db/pipeline/expression_context.cpp @@ -218,7 +218,6 @@ intrusive_ptr<ExpressionContext> ExpressionContext::copyWith( expCtx->initialPostBatchResumeToken = initialPostBatchResumeToken.getOwned(); expCtx->originalAggregateCommand = originalAggregateCommand.getOwned(); - expCtx->inMultiDocumentTransaction = inMultiDocumentTransaction; // Note that we intentionally skip copying the value of '_interruptCounter' because 'expCtx' is // intended to be used for executing a separate aggregation pipeline. diff --git a/src/mongo/db/pipeline/expression_context.h b/src/mongo/db/pipeline/expression_context.h index f6ba5812e86..20e68ac2ef7 100644 --- a/src/mongo/db/pipeline/expression_context.h +++ b/src/mongo/db/pipeline/expression_context.h @@ -379,7 +379,6 @@ public: bool inMongos = false; bool allowDiskUse = false; bool bypassDocumentValidation = false; - bool inMultiDocumentTransaction = false; bool hasWhereClause = false; NamespaceString ns; diff --git a/src/mongo/db/pipeline/pipeline.cpp b/src/mongo/db/pipeline/pipeline.cpp index 1b35c35f90f..74e58e1a167 100644 --- a/src/mongo/db/pipeline/pipeline.cpp +++ b/src/mongo/db/pipeline/pipeline.cpp @@ -236,10 +236,11 @@ void Pipeline::validateCommon(bool alreadyOptimized) const { str::stream() << stage->getSourceName() << " can only be run on mongoS", !(constraints.hostRequirement == HostTypeRequirement::kMongoS && !pCtx->inMongos)); - uassert(ErrorCodes::OperationNotSupportedInTransaction, - str::stream() << "Stage not supported inside of a multi-document transaction: " - << stage->getSourceName(), - !(pCtx->inMultiDocumentTransaction && !constraints.isAllowedInTransaction())); + uassert( + ErrorCodes::OperationNotSupportedInTransaction, + str::stream() << "Stage not supported inside of a multi-document transaction: " + << stage->getSourceName(), + !(pCtx->opCtx->inMultiDocumentTransaction() && !constraints.isAllowedInTransaction())); } } diff --git a/src/mongo/db/pipeline/pipeline_test.cpp b/src/mongo/db/pipeline/pipeline_test.cpp index 0af4b541df7..0dfd8d94b2f 100644 --- a/src/mongo/db/pipeline/pipeline_test.cpp +++ b/src/mongo/db/pipeline/pipeline_test.cpp @@ -4168,7 +4168,7 @@ public: TEST_F(PipelineValidateTest, TopLevelPipelineValidatedForStagesIllegalInTransactions) { auto ctx = getExpCtx(); - ctx->inMultiDocumentTransaction = true; + ctx->opCtx->setInMultiDocumentTransaction(); // Make a pipeline with a legal $match, and then an illegal mock stage, and verify that pipeline // creation fails with the expected error code. @@ -4181,7 +4181,7 @@ TEST_F(PipelineValidateTest, TopLevelPipelineValidatedForStagesIllegalInTransact TEST_F(PipelineValidateTest, FacetPipelineValidatedForStagesIllegalInTransactions) { auto ctx = getExpCtx(); - ctx->inMultiDocumentTransaction = true; + ctx->opCtx->setInMultiDocumentTransaction(); const std::vector<BSONObj> rawPipeline = { fromjson("{$facet: {subPipe: [{$match: {}}, {$out: 'outColl'}]}}")}; |