summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Hirschhorn <max.hirschhorn@mongodb.com>2021-06-10 01:02:28 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-06-10 01:25:28 +0000
commit0c046b785bd8d48114f627e105c7215e4734c6db (patch)
tree2d1896a57f671835311034f16ff28a78a2d24b63
parentf78438d7f2ebf71491720fa1789bbf2a536a7d66 (diff)
downloadmongo-0c046b785bd8d48114f627e105c7215e4734c6db.tar.gz
SERVER-57483 Fix caching $lookup results for config.cache.chunks.
-rw-r--r--src/mongo/db/pipeline/sharded_agg_helpers.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/mongo/db/pipeline/sharded_agg_helpers.cpp b/src/mongo/db/pipeline/sharded_agg_helpers.cpp
index cd5d35f9925..0db983a12d3 100644
--- a/src/mongo/db/pipeline/sharded_agg_helpers.cpp
+++ b/src/mongo/db/pipeline/sharded_agg_helpers.cpp
@@ -1261,16 +1261,26 @@ std::unique_ptr<Pipeline, PipelineDeleter> attachCursorToPipeline(Pipeline* owne
invariant(pipeline->getSources().empty() ||
!dynamic_cast<DocumentSourceMergeCursors*>(pipeline->getSources().front().get()));
+ if (expCtx->ns.isConfigDotCacheDotChunks()) {
+ // We take special care to attach the local cursor stage to 'ownedPipeline' here rather than
+ // attaching it to a serialized and re-parsed copy of the pipeline to avoid optimizations
+ // such as the $sequentialCache stage from being lost. This is safe because each shard has
+ // its own complete copy of any "config.cache.chunks.*" namespace.
+ return expCtx->mongoProcessInterface->attachCursorSourceToPipelineForLocalRead(
+ pipeline.release());
+ }
+
auto catalogCache = Grid::get(expCtx->opCtx)->catalogCache();
return shardVersionRetry(
expCtx->opCtx, catalogCache, expCtx->ns, "targeting pipeline to attach cursors"_sd, [&]() {
auto pipelineToTarget = pipeline->clone();
- if (allowTargetingShards && !expCtx->ns.isConfigDotCacheDotChunks() &&
- expCtx->ns.db() != "local") {
- return targetShardsAndAddMergeCursors(expCtx, std::move(pipelineToTarget));
+ if (!allowTargetingShards || expCtx->ns.db() == "local") {
+ // If the db is local, this may be a change stream examining the oplog. We know the
+ // oplog (and any other local collections) will not be sharded.
+ return expCtx->mongoProcessInterface->attachCursorSourceToPipelineForLocalRead(
+ pipelineToTarget.release());
}
- return expCtx->mongoProcessInterface->attachCursorSourceToPipelineForLocalRead(
- pipelineToTarget.release());
+ return targetShardsAndAddMergeCursors(expCtx, std::move(pipelineToTarget));
});
}