diff options
| author | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-18 17:02:53 -0300 |
|---|---|---|
| committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-18 17:02:53 -0300 |
| commit | 959575a5ca598bf5f37fb5cebe7ed1d80d3d71f7 (patch) | |
| tree | acc8d60aedb12b70048e676e8a7349deb0010db8 /src/mongo/db/pipeline/process_interface | |
| parent | 76588293975fc059cf076779e4283e6ffaf8afff (diff) | |
New upstream version 6.0.20upstream
Diffstat (limited to 'src/mongo/db/pipeline/process_interface')
5 files changed, 31 insertions, 5 deletions
diff --git a/src/mongo/db/pipeline/process_interface/mongo_process_interface.h b/src/mongo/db/pipeline/process_interface/mongo_process_interface.h index f4fe2f54c4a..9a980594737 100644 --- a/src/mongo/db/pipeline/process_interface/mongo_process_interface.h +++ b/src/mongo/db/pipeline/process_interface/mongo_process_interface.h @@ -84,7 +84,7 @@ public: * 2. write_ops::UpdateModification - either the new document we want to upsert or insert into * the collection (i.e. a 'classic' replacement update), or the pipeline to run to compute * the new document. - * 3. boost::optional<BSONObj> - for pipeline-style updated, specifies variables that can be + * 3. boost::optional<BSONObj> - for pipeline-style updates, specifies variables that can be * referred to in the pipeline performing the custom update. */ using BatchObject = @@ -172,6 +172,20 @@ public: virtual bool isSharded(OperationContext* opCtx, const NamespaceString& ns) = 0; /** + * TODO SERVER-79508 validate callers of this function remain correct. + * + * Returns false if the current request only handles parsing and validating queries. In other + * words, we are not executing queries. Examples include query analysis for queryable + * encryption, executing pipeline-style operations in the Update system, and creating a Query + * Shape. This function only returns false when the process interface is of type + * 'StubMongoProcessInterface'. + * + */ + virtual bool isExpectedToExecuteQueries() { + return true; + } + + /** * Advances the proxied write time associated with the client in ReplClientInfo to * be at least as high as the one tracked by the OperationTimeTracker associated with the * given operation context. diff --git a/src/mongo/db/pipeline/process_interface/non_shardsvr_process_interface.cpp b/src/mongo/db/pipeline/process_interface/non_shardsvr_process_interface.cpp index 63fbfe7c7ec..2a1ce64792a 100644 --- a/src/mongo/db/pipeline/process_interface/non_shardsvr_process_interface.cpp +++ b/src/mongo/db/pipeline/process_interface/non_shardsvr_process_interface.cpp @@ -205,6 +205,7 @@ BSONObj NonShardServerProcessInterface::preparePipelineAndExplain( Pipeline* ownedPipeline, ExplainOptions::Verbosity verbosity) { std::vector<Value> pipelineVec; auto firstStage = ownedPipeline->peekFront(); + auto opts = SerializationOptions{verbosity}; // If the pipeline already has a cursor explain with that one, otherwise attach a new one like // we would for a normal execution and explain that. if (firstStage && typeid(*firstStage) == typeid(DocumentSourceCursor)) { @@ -212,7 +213,7 @@ BSONObj NonShardServerProcessInterface::preparePipelineAndExplain( // extracted the necessary information and won't need it again. std::unique_ptr<Pipeline, PipelineDeleter> managedPipeline( ownedPipeline, PipelineDeleter(ownedPipeline->getContext()->opCtx)); - pipelineVec = managedPipeline->writeExplainOps(verbosity); + pipelineVec = managedPipeline->writeExplainOps(opts); ownedPipeline = nullptr; } else { auto pipelineWithCursor = attachCursorSourceToPipelineForLocalRead(ownedPipeline); @@ -221,7 +222,7 @@ BSONObj NonShardServerProcessInterface::preparePipelineAndExplain( while (pipelineWithCursor->getNext()) { } } - pipelineVec = pipelineWithCursor->writeExplainOps(verbosity); + pipelineVec = pipelineWithCursor->writeExplainOps(opts); } BSONArrayBuilder bab; for (auto&& stage : pipelineVec) { diff --git a/src/mongo/db/pipeline/process_interface/shardsvr_process_interface.cpp b/src/mongo/db/pipeline/process_interface/shardsvr_process_interface.cpp index 9755fcc7dbd..aa6914f88c3 100644 --- a/src/mongo/db/pipeline/process_interface/shardsvr_process_interface.cpp +++ b/src/mongo/db/pipeline/process_interface/shardsvr_process_interface.cpp @@ -110,7 +110,9 @@ Status ShardServerProcessInterface::insert( BatchedCommandRequest batchInsertCommand(std::move(insertCommand)); - batchInsertCommand.setWriteConcern(wc.toBSON()); + const auto originalWC = expCtx->opCtx->getWriteConcern(); + ScopeGuard resetWCGuard([&] { expCtx->opCtx->setWriteConcern(originalWC); }); + expCtx->opCtx->setWriteConcern(wc); cluster::write(expCtx->opCtx, batchInsertCommand, &stats, &response, targetEpoch); @@ -129,7 +131,10 @@ StatusWith<MongoProcessInterface::UpdateResult> ShardServerProcessInterface::upd BatchWriteExecStats stats; BatchedCommandRequest batchUpdateCommand(std::move(updateCommand)); - batchUpdateCommand.setWriteConcern(wc.toBSON()); + + const auto originalWC = expCtx->opCtx->getWriteConcern(); + ScopeGuard resetWCGuard([&] { expCtx->opCtx->setWriteConcern(originalWC); }); + expCtx->opCtx->setWriteConcern(wc); cluster::write(expCtx->opCtx, batchUpdateCommand, &stats, &response, targetEpoch); diff --git a/src/mongo/db/pipeline/process_interface/shardsvr_process_interface_test.cpp b/src/mongo/db/pipeline/process_interface/shardsvr_process_interface_test.cpp index 5c3f7eebf97..d60af845ccc 100644 --- a/src/mongo/db/pipeline/process_interface/shardsvr_process_interface_test.cpp +++ b/src/mongo/db/pipeline/process_interface/shardsvr_process_interface_test.cpp @@ -28,9 +28,11 @@ */ #include "mongo/db/concurrency/lock_state.h" +#include "mongo/db/cursor_id.h" #include "mongo/db/pipeline/document_source_out.h" #include "mongo/db/pipeline/document_source_queue.h" #include "mongo/db/pipeline/process_interface/shardsvr_process_interface.h" +#include "mongo/db/query/cursor_response.h" #include "mongo/s/query/sharded_agg_test_fixture.h" #include "mongo/unittest/unittest.h" diff --git a/src/mongo/db/pipeline/process_interface/stub_mongo_process_interface.h b/src/mongo/db/pipeline/process_interface/stub_mongo_process_interface.h index 0e984abb1b7..d69d5af7809 100644 --- a/src/mongo/db/pipeline/process_interface/stub_mongo_process_interface.h +++ b/src/mongo/db/pipeline/process_interface/stub_mongo_process_interface.h @@ -79,6 +79,10 @@ public: return std::make_unique<StubWriteSizeEstimator>(); } + bool isExpectedToExecuteQueries() override { + return false; + } + bool isSharded(OperationContext* opCtx, const NamespaceString& ns) override { return false; } |
