diff options
author | Mihai Andrei <mihai.andrei@mongodb.com> | 2019-11-06 14:19:41 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-11-06 14:19:41 +0000 |
commit | 92fea5be74359277835147762535c642e4cf2461 (patch) | |
tree | 2dd744ad2b9f8dfe6fe9e03448b1a6d7d71decbe /src/mongo/db/commands/map_reduce_agg.cpp | |
parent | 0b9da1296178806507ebab9b9c6c958f3968eca9 (diff) | |
download | mongo-92fea5be74359277835147762535c642e4cf2461.tar.gz |
SERVER-43354 Translate Error Messages For MapReduce
Diffstat (limited to 'src/mongo/db/commands/map_reduce_agg.cpp')
-rw-r--r-- | src/mongo/db/commands/map_reduce_agg.cpp | 74 |
1 files changed, 41 insertions, 33 deletions
diff --git a/src/mongo/db/commands/map_reduce_agg.cpp b/src/mongo/db/commands/map_reduce_agg.cpp index 8ca42eec7b0..03c86894cf8 100644 --- a/src/mongo/db/commands/map_reduce_agg.cpp +++ b/src/mongo/db/commands/map_reduce_agg.cpp @@ -138,40 +138,48 @@ bool runAggregationMapReduce(OperationContext* opCtx, CurOp::get(opCtx)->setPlanSummary_inlock(std::move(planSummaryStr)); } - auto resultArray = exhaustPipelineIntoBSONArray(runnablePipeline); - - PlanSummaryStats planSummaryStats; - PipelineD::getPlanSummaryStats(runnablePipeline.get(), &planSummaryStats); - CurOp::get(opCtx)->debug().setPlanSummaryMetrics(planSummaryStats); - - MapReduceStats mapReduceStats(extractStats(*runnablePipeline), - MapReduceStats::ResponseType::kUnsharded, - boost::get_optional_value_or(parsedMr.getVerbose(), false), - cmdTimer.millis()); - - if (parsedMr.getOutOptions().getOutputType() == OutputType::InMemory) { - map_reduce_output_format::appendInlineResponse( - std::move(resultArray), mapReduceStats, &result); - } else { - // For output to collection, pipeline execution should not return any results. - invariant(resultArray.isEmpty()); - - map_reduce_output_format::appendOutResponse(parsedMr.getOutOptions().getDatabaseName(), - parsedMr.getOutOptions().getCollectionName(), - mapReduceStats, - &result); + try { + auto resultArray = exhaustPipelineIntoBSONArray(runnablePipeline); + + PlanSummaryStats planSummaryStats; + PipelineD::getPlanSummaryStats(runnablePipeline.get(), &planSummaryStats); + CurOp::get(opCtx)->debug().setPlanSummaryMetrics(planSummaryStats); + + + MapReduceStats mapReduceStats(extractStats(*runnablePipeline), + MapReduceStats::ResponseType::kUnsharded, + boost::get_optional_value_or(parsedMr.getVerbose(), false), + cmdTimer.millis()); + + if (parsedMr.getOutOptions().getOutputType() == OutputType::InMemory) { + map_reduce_output_format::appendInlineResponse( + std::move(resultArray), mapReduceStats, &result); + } else { + // For output to collection, pipeline execution should not return any results. + invariant(resultArray.isEmpty()); + + map_reduce_output_format::appendOutResponse( + parsedMr.getOutOptions().getDatabaseName(), + parsedMr.getOutOptions().getCollectionName(), + mapReduceStats, + &result); + } + + // The aggregation pipeline may change the namespace of the curop and we need to set it back + // to the original namespace to correctly report command stats. One example when the + // namespace can be changed is when the pipeline contains an $out stage, which executes an + // internal command to create a temp collection, changing the curop namespace to the name of + // this temp collection. + { + stdx::lock_guard<Client> lk(*opCtx->getClient()); + CurOp::get(opCtx)->setNS_inlock(parsedMr.getNamespace().ns()); + } + + return true; + } catch (DBException& e) { + e.addContext("MapReduce internal error"); + throw; } - - // The aggregation pipeline may change the namespace of the curop and we need to set it back to - // the original namespace to correctly report command stats. One example when the namespace can - // be changed is when the pipeline contains an $out stage, which executes an internal command to - // create a temp collection, changing the curop namespace to the name of this temp collection. - { - stdx::lock_guard<Client> lk(*opCtx->getClient()); - CurOp::get(opCtx)->setNS_inlock(parsedMr.getNamespace().ns()); - } - - return true; } } // namespace mongo::map_reduce_agg |