summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/db/pipeline/document_source.h4
-rw-r--r--src/mongo/db/pipeline/document_source_group.cpp10
-rw-r--r--src/mongo/db/pipeline/expression_context.cpp4
-rw-r--r--src/mongo/db/pipeline/expression_context.h42
4 files changed, 13 insertions, 47 deletions
diff --git a/src/mongo/db/pipeline/document_source.h b/src/mongo/db/pipeline/document_source.h
index 72b5b8edf3d..1b5d4110bfa 100644
--- a/src/mongo/db/pipeline/document_source.h
+++ b/src/mongo/db/pipeline/document_source.h
@@ -636,6 +636,9 @@ namespace mongo {
intrusive_ptr<Accumulator> (*pAccumulatorFactory)(),
const intrusive_ptr<Expression> &pExpression);
+ /// Tell this source if it is doing a merge from shards. Defaults to false.
+ void setDoingMerge(bool doingMerge) { _doingMerge = doingMerge; }
+
/**
Create a grouping DocumentSource from BSON.
@@ -704,6 +707,7 @@ namespace mongo {
Document makeDocument(const Value& id, const Accumulators& accums, bool mergeableOutput);
+ bool _doingMerge;
bool _spilled;
const bool _extSortAllowed;
const int _maxMemoryUsageBytes;
diff --git a/src/mongo/db/pipeline/document_source_group.cpp b/src/mongo/db/pipeline/document_source_group.cpp
index 7b777534616..515087f321f 100644
--- a/src/mongo/db/pipeline/document_source_group.cpp
+++ b/src/mongo/db/pipeline/document_source_group.cpp
@@ -177,6 +177,7 @@ namespace mongo {
DocumentSourceGroup::DocumentSourceGroup(const intrusive_ptr<ExpressionContext>& pExpCtx)
: SplittableDocumentSource(pExpCtx)
, populated(false)
+ , _doingMerge(false)
, _spilled(false)
, _extSortAllowed(pExpCtx->getExtSortAllowed() && !pExpCtx->getInRouter())
, _maxMemoryUsageBytes(100*1024*1024)
@@ -352,8 +353,6 @@ namespace mongo {
const size_t numAccumulators = vpAccumulatorFactory.size();
dassert(numAccumulators == vpExpression.size());
- const bool mergeInputs = pExpCtx->getDoingMerge();
-
// pushed to on spill()
vector<shared_ptr<Sorter<Value, Value>::Iterator> > sortedFiles;
int memoryUsageBytes = 0;
@@ -403,7 +402,7 @@ namespace mongo {
/* tickle all the accumulators for the group we found */
dassert(numAccumulators == group.size());
for (size_t i = 0; i < numAccumulators; i++) {
- group[i]->process(vpExpression[i]->evaluate(vars), mergeInputs);
+ group[i]->process(vpExpression[i]->evaluate(vars), _doingMerge);
memoryUsageBytes += group[i]->memUsageForSorter();
}
@@ -528,9 +527,8 @@ namespace mongo {
}
intrusive_ptr<DocumentSource> DocumentSourceGroup::getRouterSource() {
- intrusive_ptr<ExpressionContext> pMergerExpCtx = pExpCtx->clone();
- pMergerExpCtx->setDoingMerge(true);
- intrusive_ptr<DocumentSourceGroup> pMerger(DocumentSourceGroup::create(pMergerExpCtx));
+ intrusive_ptr<DocumentSourceGroup> pMerger(DocumentSourceGroup::create(pExpCtx));
+ pMerger->setDoingMerge(true);
/* the merger will use the same grouping key */
pMerger->setIdExpression(ExpressionFieldPath::parse("$$ROOT._id"));
diff --git a/src/mongo/db/pipeline/expression_context.cpp b/src/mongo/db/pipeline/expression_context.cpp
index 2868db1936e..3b5009cc2d5 100644
--- a/src/mongo/db/pipeline/expression_context.cpp
+++ b/src/mongo/db/pipeline/expression_context.cpp
@@ -26,8 +26,7 @@ namespace mongo {
}
inline ExpressionContext::ExpressionContext(InterruptStatus *pS, const NamespaceString& ns)
- : doingMerge(false)
- , inShard(false)
+ : inShard(false)
, inRouter(false)
, extSortAllowed(false)
, intCheckCounter(1)
@@ -47,7 +46,6 @@ namespace mongo {
ExpressionContext* ExpressionContext::clone() {
ExpressionContext* newContext = create(pStatus, getNs());
- newContext->setDoingMerge(getDoingMerge());
newContext->setInShard(getInShard());
newContext->setInRouter(getInRouter());
newContext->setExtSortAllowed(getExtSortAllowed());
diff --git a/src/mongo/db/pipeline/expression_context.h b/src/mongo/db/pipeline/expression_context.h
index d355b1f725c..207d6e62348 100644
--- a/src/mongo/db/pipeline/expression_context.h
+++ b/src/mongo/db/pipeline/expression_context.h
@@ -30,15 +30,13 @@ namespace mongo {
public:
virtual ~ExpressionContext();
- void setDoingMerge(bool b);
- void setInShard(bool b);
- void setInRouter(bool b);
+ void setInShard(bool b) { inShard = b; }
+ void setInRouter(bool b) { inRouter = b; }
void setExtSortAllowed(bool b) { extSortAllowed = b; }
void setNs(NamespaceString ns) { _ns = ns; }
- bool getDoingMerge() const;
- bool getInShard() const;
- bool getInRouter() const;
+ bool getInShard() const { return inShard; }
+ bool getInRouter() const { return inRouter; }
bool getExtSortAllowed() const { return extSortAllowed; }
const NamespaceString& getNs() const { return _ns; }
@@ -56,7 +54,6 @@ namespace mongo {
private:
ExpressionContext(InterruptStatus *pStatus, const NamespaceString& ns);
- bool doingMerge;
bool inShard;
bool inRouter;
bool extSortAllowed;
@@ -65,34 +62,3 @@ namespace mongo {
NamespaceString _ns;
};
}
-
-
-/* ======================= INLINED IMPLEMENTATIONS ========================== */
-
-namespace mongo {
-
- inline void ExpressionContext::setDoingMerge(bool b) {
- doingMerge = b;
- }
-
- inline void ExpressionContext::setInShard(bool b) {
- inShard = b;
- }
-
- inline void ExpressionContext::setInRouter(bool b) {
- inRouter = b;
- }
-
- inline bool ExpressionContext::getDoingMerge() const {
- return doingMerge;
- }
-
- inline bool ExpressionContext::getInShard() const {
- return inShard;
- }
-
- inline bool ExpressionContext::getInRouter() const {
- return inRouter;
- }
-
-};