From c70bc17083cc73c2b2d32b4fc693fe22c58a863d Mon Sep 17 00:00:00 2001 From: Alberto Massari Date: Tue, 13 Sep 2022 08:43:13 +0000 Subject: SERVER-63851 Derive ExecutionContext flags from OperationContext --- src/mongo/db/commands/find_cmd.cpp | 4 ---- src/mongo/db/commands/map_reduce_agg.cpp | 4 ---- src/mongo/db/commands/run_aggregate.cpp | 9 ++------- src/mongo/db/pipeline/expression_context.cpp | 9 ++++++--- src/mongo/db/pipeline/expression_context.h | 3 ++- 5 files changed, 10 insertions(+), 19 deletions(-) (limited to 'src/mongo/db') diff --git a/src/mongo/db/commands/find_cmd.cpp b/src/mongo/db/commands/find_cmd.cpp index bf40647a9cf..ba45ad6b615 100644 --- a/src/mongo/db/commands/find_cmd.cpp +++ b/src/mongo/db/commands/find_cmd.cpp @@ -142,10 +142,6 @@ boost::intrusive_ptr makeExpressionContext( findCommand.getLet(), // let CurOp::get(opCtx)->dbProfileLevel() > 0 // mayDbProfile ); - if (opCtx->readOnly()) { - // Disallow disk use if in read-only mode. - expCtx->allowDiskUse = false; - } expCtx->tempDir = storageGlobalParams.dbpath + "/_tmp"; expCtx->startExpressionCounters(); diff --git a/src/mongo/db/commands/map_reduce_agg.cpp b/src/mongo/db/commands/map_reduce_agg.cpp index 073e655dcb3..1f31ec3c78f 100644 --- a/src/mongo/db/commands/map_reduce_agg.cpp +++ b/src/mongo/db/commands/map_reduce_agg.cpp @@ -107,10 +107,6 @@ auto makeExpressionContext(OperationContext* opCtx, boost::none, // let CurOp::get(opCtx)->dbProfileLevel() > 0 // mayDbProfile ); - if (opCtx->readOnly()) { - // Disallow disk use if in read-only mode. - expCtx->allowDiskUse = false; - } expCtx->tempDir = storageGlobalParams.dbpath + "/_tmp"; return expCtx; } diff --git a/src/mongo/db/commands/run_aggregate.cpp b/src/mongo/db/commands/run_aggregate.cpp index e61f799620c..4fe8a736ad7 100644 --- a/src/mongo/db/commands/run_aggregate.cpp +++ b/src/mongo/db/commands/run_aggregate.cpp @@ -443,15 +443,10 @@ boost::intrusive_ptr makeExpressionContext( MongoProcessInterface::create(opCtx), uassertStatusOK(resolveInvolvedNamespaces(opCtx, request)), uuid, - CurOp::get(opCtx)->dbProfileLevel() > 0); + CurOp::get(opCtx)->dbProfileLevel() > 0, + allowDiskUseByDefault.load()); expCtx->tempDir = storageGlobalParams.dbpath + "/_tmp"; expCtx->collationMatchesDefault = collationMatchesDefault; - expCtx->forPerShardCursor = request.getPassthroughToShard().has_value(); - expCtx->allowDiskUse = request.getAllowDiskUse().value_or(allowDiskUseByDefault.load()); - if (opCtx->readOnly()) { - // Disallow disk use if in read-only mode. - expCtx->allowDiskUse = false; - } // If the request explicitly specified NOT to use v2 resume tokens for change streams, set this // on the expCtx. This can happen if a the request originated from 6.0 mongos, or in test mode. diff --git a/src/mongo/db/pipeline/expression_context.cpp b/src/mongo/db/pipeline/expression_context.cpp index b3b433a8c45..9d36a21b888 100644 --- a/src/mongo/db/pipeline/expression_context.cpp +++ b/src/mongo/db/pipeline/expression_context.cpp @@ -49,12 +49,13 @@ ExpressionContext::ExpressionContext(OperationContext* opCtx, std::shared_ptr processInterface, StringMap resolvedNamespaces, boost::optional collUUID, - bool mayDbProfile) + bool mayDbProfile, + bool allowDiskUseByDefault) : ExpressionContext(opCtx, request.getExplain(), request.getFromMongos(), request.getNeedsMerge(), - request.getAllowDiskUse(), + request.getAllowDiskUse().value_or(allowDiskUseByDefault), request.getBypassDocumentValidation().value_or(false), request.getIsMapReduceCommand(), request.getNamespace(), @@ -71,6 +72,7 @@ ExpressionContext::ExpressionContext(OperationContext* opCtx, // 'jsHeapLimitMB' limit. jsHeapLimitMB = boost::none; } + forPerShardCursor = request.getPassthroughToShard().has_value(); } ExpressionContext::ExpressionContext( @@ -92,7 +94,8 @@ ExpressionContext::ExpressionContext( : explain(explain), fromMongos(fromMongos), needsMerge(needsMerge), - allowDiskUse(allowDiskUse), + allowDiskUse(allowDiskUse && + !(opCtx && opCtx->readOnly())), // Disallow disk use if in read-only mode. bypassDocumentValidation(bypassDocumentValidation), ns(ns), uuid(std::move(collUUID)), diff --git a/src/mongo/db/pipeline/expression_context.h b/src/mongo/db/pipeline/expression_context.h index 0d2d87fd361..8629311709a 100644 --- a/src/mongo/db/pipeline/expression_context.h +++ b/src/mongo/db/pipeline/expression_context.h @@ -123,7 +123,8 @@ public: std::shared_ptr mongoProcessInterface, StringMap resolvedNamespaces, boost::optional collUUID, - bool mayDbProfile = true); + bool mayDbProfile = true, + bool allowDiskUseByDefault = false); /** * Constructs an ExpressionContext to be used for Pipeline parsing and evaluation. This version -- cgit v1.2.1