summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRomans Kasperovics <romans.kasperovics@mongodb.com>2022-05-23 15:41:13 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-05-23 16:06:46 +0000
commitaaa27a3f0fd75994584b7e5e4c08fcd86bb8af38 (patch)
tree4a83d9157ea83d714dc0855cb8ac830443bb42e9
parenta8f474bb0428b37efc4e48f74a7b881f5ef49213 (diff)
downloadmongo-aaa27a3f0fd75994584b7e5e4c08fcd86bb8af38.tar.gz
SERVER-66215 Create Sorter::File instances only when actually needed
(cherry picked from commit dd2874d1fc652344154233fa1dbb5fd313a99463)
-rw-r--r--src/mongo/db/pipeline/document_source_group.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/mongo/db/pipeline/document_source_group.cpp b/src/mongo/db/pipeline/document_source_group.cpp
index c561c1102b8..3f718360838 100644
--- a/src/mongo/db/pipeline/document_source_group.cpp
+++ b/src/mongo/db/pipeline/document_source_group.cpp
@@ -414,11 +414,6 @@ DocumentSourceGroup::DocumentSourceGroup(const intrusive_ptr<ExpressionContext>&
maxMemoryUsageBytes
? *maxMemoryUsageBytes
: static_cast<size_t>(internalDocumentSourceGroupMaxMemoryBytes.load())},
- // We spill to disk in debug mode, regardless of allowDiskUse, to stress the system.
- _file(
- !expCtx->inMongos && (expCtx->allowDiskUse || kDebugBuild)
- ? std::make_shared<Sorter<Value, Value>::File>(expCtx->tempDir + "/" + nextFileName())
- : nullptr),
_initialized(false),
_groups(expCtx->getValueComparator().makeUnorderedValueMap<Accumulators>()),
_spilled(false),
@@ -695,6 +690,11 @@ shared_ptr<Sorter<Value, Value>::Iterator> DocumentSourceGroup::spill() {
stable_sort(ptrs.begin(), ptrs.end(), SpillSTLComparator(pExpCtx->getValueComparator()));
+ // Initialize '_file' in a lazy manner only when it is needed.
+ if (!_file) {
+ _file =
+ std::make_shared<Sorter<Value, Value>::File>(pExpCtx->tempDir + "/" + nextFileName());
+ }
SortedFileWriter<Value, Value> writer(SortOptions().TempDir(pExpCtx->tempDir), _file);
switch (_accumulatedFields.size()) { // same as ptrs[i]->second.size() for all i.
case 0: // no values, essentially a distinct