summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMickey. J Winters <mickey.winters@mongodb.com>2021-10-15 20:59:36 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-10-15 21:34:43 +0000
commit07b8851825836911265e909d6842d4586832f9bb (patch)
tree0dcb42b78539f9b9b42b4f576b6bcab8db973dca
parent5bafc36d26421b80101a45aab2ce6bf3ec30b1f5 (diff)
downloadmongo-07b8851825836911265e909d6842d4586832f9bb.tar.gz
SERVER-60218-44: SERVER-60218 add initialize helper function for document_source_group (cherry picked from commit 867f52afbb79bc00e35c70f8e0681b7d602f97b2)
-rw-r--r--src/mongo/db/pipeline/document_source_group.cpp11
-rw-r--r--src/mongo/db/pipeline/document_source_group.h6
2 files changed, 14 insertions, 3 deletions
diff --git a/src/mongo/db/pipeline/document_source_group.cpp b/src/mongo/db/pipeline/document_source_group.cpp
index a82d90b9be3..4a7b48d6cd2 100644
--- a/src/mongo/db/pipeline/document_source_group.cpp
+++ b/src/mongo/db/pipeline/document_source_group.cpp
@@ -502,11 +502,16 @@ private:
} // namespace
DocumentSource::GetNextResult DocumentSourceGroup::initialize() {
- const size_t numAccumulators = _accumulatedFields.size();
-
- // Barring any pausing, this loop exhausts 'pSource' and populates '_groups'.
GetNextResult input = pSource->getNext();
+ return initializeSelf(input);
+}
+// This separate NOINLINE function is used here to decrease stack utilization of initialize() and
+// prevent stack overflows.
+MONGO_COMPILER_NOINLINE DocumentSource::GetNextResult DocumentSourceGroup::initializeSelf(
+ GetNextResult input) {
+ const size_t numAccumulators = _accumulatedFields.size();
+ // Barring any pausing, this loop exhausts 'pSource' and populates '_groups'.
for (; input.isAdvanced(); input = pSource->getNext()) {
if (_memoryTracker.shouldSpillWithAttemptToSaveMemory([this]() { return freeMemory(); })) {
_sortedFiles.push_back(spill());
diff --git a/src/mongo/db/pipeline/document_source_group.h b/src/mongo/db/pipeline/document_source_group.h
index ee8ad1f2f14..16cb45b85b9 100644
--- a/src/mongo/db/pipeline/document_source_group.h
+++ b/src/mongo/db/pipeline/document_source_group.h
@@ -221,6 +221,12 @@ private:
GetNextResult initialize();
/**
+ * Initializes this $group after any children are potentially initialized see initialize() for
+ * more details.
+ */
+ GetNextResult initializeSelf(GetNextResult input);
+
+ /**
* Spill groups map to disk and returns an iterator to the file. Note: Since a sorted $group
* does not exhaust the previous stage before returning, and thus does not maintain as large a
* store of documents at any one time, only an unsorted group can spill to disk.