summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/document_source.h
diff options
context:
space:
mode:
authorCharlie Swanson <charlie.swanson@mongodb.com>2018-07-02 18:23:25 -0400
committerCharlie Swanson <charlie.swanson@mongodb.com>2018-08-15 13:30:12 -0400
commitee06e6cbe5a75775f76836449558be2f6a98ddfd (patch)
treed4dbf37110d25f7f4876337a7b1e11abe251fac5 /src/mongo/db/pipeline/document_source.h
parenta5bde2f3e9afc3f72da01788b76829fb29c2f4e7 (diff)
downloadmongo-ee06e6cbe5a75775f76836449558be2f6a98ddfd.tar.gz
SERVER-33323 Refactor agg cursor merging on mongos
This commit makes it so that aggregations will always use a $mergeCursors as a wrapper around a AsyncResultsMerger, which is new behavior for mongos. As part of this refactor, we can delete the concept of a 'merging presorted' $sort stage (which is now handled by the AsyncResultsMerger) and delete the DocumentSourceRouterAdapter stage which talked to a RouterStageMerge, instead directly using a $mergeCursors stage.
Diffstat (limited to 'src/mongo/db/pipeline/document_source.h')
-rw-r--r--src/mongo/db/pipeline/document_source.h26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/mongo/db/pipeline/document_source.h b/src/mongo/db/pipeline/document_source.h
index 4aae392153d..682b03b76e1 100644
--- a/src/mongo/db/pipeline/document_source.h
+++ b/src/mongo/db/pipeline/document_source.h
@@ -698,6 +698,22 @@ private:
class NeedsMergerDocumentSource {
public:
/**
+ * A struct representing the information needed to merge the cursors for the shards half of this
+ * pipeline. If 'inputSortPattern' is set, each document is expected to have sort key metadata
+ * which will be serialized in the '$sortKey' field. 'inputSortPattern' will then be used to
+ * describe which fields are ascending and which fields are descending when merging the streams
+ * together.
+ */
+ struct MergingLogic {
+ MergingLogic(boost::intrusive_ptr<DocumentSource>&& mergingStage,
+ boost::optional<BSONObj> inputSortPattern = boost::none)
+ : mergingStage(std::move(mergingStage)), inputSortPattern(inputSortPattern) {}
+
+ boost::intrusive_ptr<DocumentSource> mergingStage;
+ boost::optional<BSONObj> inputSortPattern;
+ };
+
+ /**
* Returns a source to be run on the shards, or NULL if no work should be done on the shards for
* this stage. Must not mutate the existing source object; if different behaviour is required in
* the split-pipeline case, a new source should be created and configured appropriately. It is
@@ -708,12 +724,12 @@ public:
virtual boost::intrusive_ptr<DocumentSource> getShardSource() = 0;
/**
- * Returns a list of stages that combine results from the shards. Subclasses of this class
- * should not return an empty list. Must not mutate the existing source object; if different
- * behaviour is required, a new source should be created and configured appropriately. It is an
- * error for getMergeSources() to return a pointer to the same object as getShardSource().
+ * Returns a struct representing what needs to be done to merge each shard's pipeline into a
+ * single stream of results. Must not mutate the existing source object; if different behaviour
+ * is required, a new source should be created and configured appropriately. It is an error for
+ * mergingLogic() to return a pointer to the same object as getShardSource().
*/
- virtual std::list<boost::intrusive_ptr<DocumentSource>> getMergeSources() = 0;
+ virtual MergingLogic mergingLogic() = 0;
protected:
// It is invalid to delete through a NeedsMergerDocumentSource-typed pointer.