summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/document_source_out.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/pipeline/document_source_out.h')
-rw-r--r--src/mongo/db/pipeline/document_source_out.h25
1 files changed, 8 insertions, 17 deletions
diff --git a/src/mongo/db/pipeline/document_source_out.h b/src/mongo/db/pipeline/document_source_out.h
index cfd9249146b..906a30f10ee 100644
--- a/src/mongo/db/pipeline/document_source_out.h
+++ b/src/mongo/db/pipeline/document_source_out.h
@@ -65,7 +65,7 @@ public:
/**
* Abstract class for the $out aggregation stage.
*/
-class DocumentSourceOut : public DocumentSource {
+class DocumentSourceOut : public DocumentSource, public NeedsMergerDocumentSource {
public:
/**
* A "lite parsed" $out stage is similar to other stages involving foreign collections except in
@@ -125,12 +125,8 @@ public:
PositionRequirement::kLast,
// A $out to an unsharded collection should merge on the primary shard to perform
// local writes. A $out to a sharded collection has no requirement, since each shard
- // can perform its own portion of the write. We use 'kAnyShard' to direct it to
- // execute on one of the shards in case some of the writes happen to end up being
- // local.
- pExpCtx->mongoProcessInterface->isSharded(pExpCtx->opCtx, _outputNs)
- ? HostTypeRequirement::kAnyShard
- : HostTypeRequirement::kPrimaryShard,
+ // can perform its own portion of the write.
+ HostTypeRequirement::kPrimaryShard,
DiskUseRequirement::kWritesPersistentData,
FacetRequirement::kNotAllowed,
TransactionRequirement::kNotAllowed};
@@ -144,17 +140,12 @@ public:
return _mode;
}
- boost::optional<MergingLogic> mergingLogic() final {
- // It should always be faster to avoid splitting the pipeline if the output collection is
- // sharded. If we avoid splitting the pipeline then each shard can perform the writes to the
- // target collection in parallel.
- if (pExpCtx->mongoProcessInterface->isSharded(pExpCtx->opCtx, _outputNs)) {
- return boost::none;
- }
- // {shardsStage, mergingStage, sortPattern}
- return MergingLogic{nullptr, this, boost::none};
+ boost::intrusive_ptr<DocumentSource> getShardSource() final {
+ return nullptr;
+ }
+ MergingLogic mergingLogic() final {
+ return {this};
}
-
virtual bool canRunInParallelBeforeOut(
const std::set<std::string>& nameOfShardKeyFieldsUponEntryToStage) const final {
// If someone is asking the question, this must be the $out stage in question, so yes!