diff options
author | Nicholas Zolnierz <nicholas.zolnierz@mongodb.com> | 2019-10-11 18:49:51 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-10-11 18:49:51 +0000 |
commit | 6b345cce214efb1b3f9dcffc2f25a833d1caa100 (patch) | |
tree | cbd6bb664d8ae1079ad909960066390804870eec /src/mongo/s/commands/cluster_map_reduce_agg.cpp | |
parent | a3e787c2a1051c0787af09a700a872a1271b491e (diff) | |
download | mongo-6b345cce214efb1b3f9dcffc2f25a833d1caa100.tar.gz |
SERVER-43626 MR Agg: Fail and cleanup cursors when a sharded mapReduce cannot fit in a single batch response
Diffstat (limited to 'src/mongo/s/commands/cluster_map_reduce_agg.cpp')
-rw-r--r-- | src/mongo/s/commands/cluster_map_reduce_agg.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/mongo/s/commands/cluster_map_reduce_agg.cpp b/src/mongo/s/commands/cluster_map_reduce_agg.cpp index 2c2012c3af5..aad791e8357 100644 --- a/src/mongo/s/commands/cluster_map_reduce_agg.cpp +++ b/src/mongo/s/commands/cluster_map_reduce_agg.cpp @@ -47,6 +47,7 @@ #include "mongo/db/query/map_reduce_output_format.h" #include "mongo/s/catalog_cache.h" #include "mongo/s/commands/cluster_map_reduce_agg.h" +#include "mongo/s/query/cluster_cursor_manager.h" namespace mongo { namespace { @@ -151,6 +152,7 @@ bool runAggregationMapReduce(OperationContext* opCtx, involvedNamespaces, false, // hasChangeStream true)); // allowedToPassthrough + switch (targeter.policy) { case sharded_agg_helpers::AggregationTargeter::TargetingPolicy::kPassthrough: { // For the passthrough case, the targeter will not build a pipeline since its not needed @@ -192,6 +194,15 @@ bool runAggregationMapReduce(OperationContext* opCtx, auto aggResults = tempResults.done(); if (parsedMr.getOutOptions().getOutputType() == OutputType::InMemory) { + // If the inline results could not fit into a single batch, then kill the remote + // operation(s) and return an error since mapReduce does not support a cursor-style + // response. + if (aggResults["cursor"]["id"].Long() != 0) { + uassertStatusOK(Grid::get(opCtx)->getCursorManager()->killCursor( + opCtx, parsedMr.getNamespace(), aggResults["cursor"]["id"].Long())); + uasserted(31301, "MapReduce inline results are greater than the allowed 16MB limit"); + } + auto exhaustedResults = [&]() { BSONArrayBuilder bab; for (auto&& elem : aggResults["cursor"]["firstBatch"].Obj()) |