summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/accumulator_js_reduce.cpp
diff options
context:
space:
mode:
authorArun Banala <arun.banala@mongodb.com>2020-08-10 10:17:51 +0100
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-08-10 11:17:49 +0000
commitbf48331b0343b191c0d94aef888cdec471a6508b (patch)
treeb109f9eeafd3f32f9ada4ef535b19498da7a21c9 /src/mongo/db/pipeline/accumulator_js_reduce.cpp
parentbefc561c8c06e2666dfcfd3b6bcadd5ef43bab88 (diff)
downloadmongo-bf48331b0343b191c0d94aef888cdec471a6508b.tar.gz
SERVER-48390 Exhaust pending calls when $group with $accumulator runs out of memory
Diffstat (limited to 'src/mongo/db/pipeline/accumulator_js_reduce.cpp')
-rw-r--r--src/mongo/db/pipeline/accumulator_js_reduce.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/mongo/db/pipeline/accumulator_js_reduce.cpp b/src/mongo/db/pipeline/accumulator_js_reduce.cpp
index af34132130f..fcc01b061bd 100644
--- a/src/mongo/db/pipeline/accumulator_js_reduce.cpp
+++ b/src/mongo/db/pipeline/accumulator_js_reduce.cpp
@@ -324,7 +324,7 @@ Value AccumulatorJs::getValue(bool toBeMerged) {
invariant(_state);
// Ensure we've actually called accumulate/merge for every input document.
- reducePendingCalls();
+ reduceMemoryConsumptionIfAble();
invariant(_pendingCalls.empty());
// If toBeMerged then we return the current state, to be fed back in to accumulate / merge /
@@ -412,13 +412,13 @@ void AccumulatorJs::processInternal(const Value& input, bool merging) {
sizeof(std::pair<Value, bool>));
}
-void AccumulatorJs::reducePendingCalls() {
+void AccumulatorJs::reduceMemoryConsumptionIfAble() {
// _state should be nonempty because we populate it in startNewGroup.
invariant(_state);
- // $group and $bucketAuto never create empty groups. The only time an accumulator is asked to
- // accumulate an empty set is in ExpressionFromArray, but $accumulator is never used that way
- // ($accumulator is not registered as an expression the way $sum and $avg and others are).
- invariant(!_pendingCalls.empty());
+
+ if (_pendingCalls.empty()) {
+ return;
+ }
auto expCtx = getExpressionContext();
auto jsExec = expCtx->getJsExecWithScope();