From fe788b0989dd6cbaa1c4ea95e01f1967bb94fdf7 Mon Sep 17 00:00:00 2001 From: James Wahlin Date: Thu, 21 Nov 2019 20:51:49 +0000 Subject: SERVER-44635 MR in Agg: Remove in-line mapReduce execution statistics --- src/mongo/db/commands/SConscript | 12 -- src/mongo/db/commands/map_reduce_agg.cpp | 20 +- src/mongo/db/commands/map_reduce_stats.cpp | 138 -------------- src/mongo/db/commands/map_reduce_stats.h | 95 ---------- src/mongo/db/commands/map_reduce_stats_test.cpp | 203 --------------------- src/mongo/db/query/SConscript | 1 - src/mongo/db/query/map_reduce_output_format.cpp | 9 +- src/mongo/db/query/map_reduce_output_format.h | 10 +- .../db/query/map_reduce_output_format_test.cpp | 46 +---- src/mongo/s/commands/cluster_map_reduce_agg.cpp | 4 +- 10 files changed, 14 insertions(+), 524 deletions(-) delete mode 100644 src/mongo/db/commands/map_reduce_stats.cpp delete mode 100644 src/mongo/db/commands/map_reduce_stats.h delete mode 100644 src/mongo/db/commands/map_reduce_stats_test.cpp diff --git a/src/mongo/db/commands/SConscript b/src/mongo/db/commands/SConscript index bbc0780edb6..f7e219f6a65 100644 --- a/src/mongo/db/commands/SConscript +++ b/src/mongo/db/commands/SConscript @@ -506,23 +506,12 @@ env.Library( ] ) -env.Library( - target='map_reduce_stats', - source=[ - 'map_reduce_stats.cpp', - ], - LIBDEPS=[ - '$BUILD_DIR/mongo/db/pipeline/pipeline', - ] -) - env.Library( target='map_reduce_agg', source=[ 'map_reduce_agg.cpp', ], LIBDEPS=[ - '$BUILD_DIR/mongo/db/commands/map_reduce_stats', '$BUILD_DIR/mongo/db/commands/servers', '$BUILD_DIR/mongo/db/db_raii', '$BUILD_DIR/mongo/db/index/index_access_methods', @@ -556,7 +545,6 @@ env.CppUnitTest( source=[ "map_reduce_agg_test.cpp", "map_reduce_parse_test.cpp", - "map_reduce_stats_test.cpp", ], LIBDEPS=[ '$BUILD_DIR/mongo/db/auth/authmocks', diff --git a/src/mongo/db/commands/map_reduce_agg.cpp b/src/mongo/db/commands/map_reduce_agg.cpp index fe066c6da0c..f4c61322c03 100644 --- a/src/mongo/db/commands/map_reduce_agg.cpp +++ b/src/mongo/db/commands/map_reduce_agg.cpp @@ -41,7 +41,6 @@ #include "mongo/db/commands.h" #include "mongo/db/commands/map_reduce_agg.h" #include "mongo/db/commands/map_reduce_javascript_code.h" -#include "mongo/db/commands/map_reduce_stats.h" #include "mongo/db/commands/mr_common.h" #include "mongo/db/curop.h" #include "mongo/db/db_raii.h" @@ -97,16 +96,6 @@ auto makeExpressionContext(OperationContext* opCtx, const MapReduce& parsedMr) { return expCtx; } -std::vector extractStats(const Pipeline& pipeline) { - std::vector pipelineStats; - - for (const auto& stage : pipeline.getSources()) { - pipelineStats.push_back(stage->getCommonStats()); - } - - return pipelineStats; -} - } // namespace bool runAggregationMapReduce(OperationContext* opCtx, @@ -146,14 +135,8 @@ bool runAggregationMapReduce(OperationContext* opCtx, 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); + map_reduce_output_format::appendInlineResponse(std::move(resultArray), &result); } else { // For output to collection, pipeline execution should not return any results. invariant(resultArray.isEmpty()); @@ -161,7 +144,6 @@ bool runAggregationMapReduce(OperationContext* opCtx, map_reduce_output_format::appendOutResponse( parsedMr.getOutOptions().getDatabaseName(), parsedMr.getOutOptions().getCollectionName(), - mapReduceStats, &result); } diff --git a/src/mongo/db/commands/map_reduce_stats.cpp b/src/mongo/db/commands/map_reduce_stats.cpp deleted file mode 100644 index bff4dfd8732..00000000000 --- a/src/mongo/db/commands/map_reduce_stats.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/** - * Copyright (C) 2019-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#include "mongo/platform/basic.h" - -#include "mongo/db/commands/map_reduce_stats.h" - -#include "mongo/db/pipeline/document_source.h" - -namespace mongo { - -MapReduceStats::MapReduceStats(const std::vector& pipelineStats, - ResponseType responseType, - bool verbose, - int executionTime) - : _responseType(responseType), _verbose(verbose), _executionTime(executionTime) { - - long long prevTime = 0; - bool projectSeen = false; - for (const auto& stageStats : pipelineStats) { - const auto stageName = stageStats.stageTypeStr; - - // While a mapReduce pipeline may include a $match, $sort and/or $limit stage they will be - // absorbed by the $cursor stage push down to the query sub-system. The exception to this is - // a $match with empty query predicate, which will not be pushed down. - if (stageName == "$cursor"_sd || stageName == "$match"_sd) { - _counts.input = stageStats.advanced; - } else if (stageName == "$project"_sd) { - if (!projectSeen) { - _timing.map = stageStats.executionTimeMillis - prevTime; - projectSeen = true; - } - } else if (stageName == "$unwind"_sd) { - _counts.emit = stageStats.advanced; - } else if (stageName == "$group"_sd) { - _timing.reduce = stageStats.executionTimeMillis - prevTime; - _counts.output = stageStats.advanced; - } else { - invariant(stageName == "$out"_sd || stageName == "$internalOutToDifferentDB"_sd || - stageName == "$merge"_sd, - stageName); - } - - prevTime = stageStats.executionTimeMillis; - } -} - -void MapReduceStats::appendStats(BSONObjBuilder* resultBuilder) const { - *resultBuilder << "timeMillis" << _executionTime; - - if (_verbose) { - appendTiming(resultBuilder); - } - - appendCounts(resultBuilder); - - if (_responseType == ResponseType::kSharded) { - appendShardCounts(resultBuilder); - appendPostProcessCounts(resultBuilder); - } -} - -void MapReduceStats::appendCounts(BSONObjBuilder* resultBuilder) const { - BSONObjBuilder countBuilder = resultBuilder->subobjStart("counts"); - countBuilder.appendNumber("input", _counts.input); - countBuilder.appendNumber("emit", _counts.emit); - countBuilder.appendNumber("output", _counts.output); - countBuilder.doneFast(); -} - -void MapReduceStats::appendTiming(BSONObjBuilder* resultBuilder) const { - BSONObjBuilder timingBuilder = resultBuilder->subobjStart("timing"); - if (_responseType == ResponseType::kUnsharded) { - timingBuilder.appendIntOrLL("mapTime", _timing.map); - timingBuilder.appendIntOrLL("reduceTime", _timing.reduce); - timingBuilder.appendIntOrLL("total", _executionTime); - } else { - invariant(_responseType == ResponseType::kSharded); - // TODO SERVER-43290: Add support for sharded collection statistics. - timingBuilder << "shardProcessing" << 0; - timingBuilder << "postProcessing" << 0; - } - timingBuilder.doneFast(); -} - -void MapReduceStats::appendShardCounts(BSONObjBuilder* resultBuilder) const { - BSONObjBuilder shardCountsBuilder = resultBuilder->subobjStart("shardCounts"); - - // TODO SERVER-43290: Add support for sharded collection statistics. - BSONObjBuilder dummyShardBuilder = shardCountsBuilder.subobjStart("shardName-rs0/host:port"); - dummyShardBuilder << "input" << 0; - dummyShardBuilder << "emit" << 0; - dummyShardBuilder << "output" << 0; - dummyShardBuilder.doneFast(); - - shardCountsBuilder.doneFast(); -} - -void MapReduceStats::appendPostProcessCounts(BSONObjBuilder* resultBuilder) const { - BSONObjBuilder countsBuilder = resultBuilder->subobjStart("postProcessCounts"); - - // TODO SERVER-43290: Add support for sharded collection statistics. - BSONObjBuilder dummyMergeBuilder = countsBuilder.subobjStart("shardName-rs0/host:port"); - dummyMergeBuilder << "input" << 0; - dummyMergeBuilder << "emit" << 0; - dummyMergeBuilder << "output" << 0; - dummyMergeBuilder.doneFast(); - - countsBuilder.doneFast(); -} - -} // namespace mongo diff --git a/src/mongo/db/commands/map_reduce_stats.h b/src/mongo/db/commands/map_reduce_stats.h deleted file mode 100644 index 0e9cf22468d..00000000000 --- a/src/mongo/db/commands/map_reduce_stats.h +++ /dev/null @@ -1,95 +0,0 @@ -/** - * Copyright (C) 2019-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#pragma once - -#include - -#include "mongo/bson/bsonobjbuilder.h" -#include "mongo/db/exec/plan_stats.h" - -namespace mongo { - -/** - * Responsible for building the set of statistics required for a MapReduce command response and - * appending to a response message. - */ -class MapReduceStats { -public: - /** - * The mapReduce command response format differs when run against a sharded vs unsharded - * collection. - */ - enum class ResponseType { - kUnsharded, - kSharded, - }; - - MapReduceStats(const std::vector& stageStatistics, - ResponseType responseType, - bool verbose, - int executionTime); - - void appendStats(BSONObjBuilder* resultBuilder) const; - - /** - * Creates a dummy MapReduceStats instance for use in unit testing. - */ - static MapReduceStats createForTest() { - return MapReduceStats(); - } - -private: - struct StageCounts { - size_t input = 0; - size_t emit = 0; - size_t output = 0; - } _counts; - - struct StageTiming { - long long map = 0; - long long reduce = 0; - } _timing; - - MapReduceStats() = default; - - void appendCounts(BSONObjBuilder* resultBuilder) const; - - void appendTiming(BSONObjBuilder* resultBuilder) const; - - void appendShardCounts(BSONObjBuilder* resultBuilder) const; - - void appendPostProcessCounts(BSONObjBuilder* resultBuilder) const; - - const ResponseType _responseType = ResponseType::kUnsharded; - const bool _verbose = false; - const int _executionTime = 0; -}; - -} // namespace mongo diff --git a/src/mongo/db/commands/map_reduce_stats_test.cpp b/src/mongo/db/commands/map_reduce_stats_test.cpp deleted file mode 100644 index a769e47b564..00000000000 --- a/src/mongo/db/commands/map_reduce_stats_test.cpp +++ /dev/null @@ -1,203 +0,0 @@ -/** - * Copyright (C) 2019-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#include "mongo/platform/basic.h" - -#include - -#include "mongo/bson/bsonobjbuilder.h" -#include "mongo/db/commands/map_reduce_stats.h" -#include "mongo/db/exec/plan_stats.h" -#include "mongo/db/json.h" -#include "mongo/unittest/death_test.h" -#include "mongo/unittest/unittest.h" - -using namespace std::literals::string_literals; - -namespace mongo { -namespace { - -class MapReduceStatsTest : public mongo::unittest::Test { -public: - MapReduceStatsTest() = default; - - std::vector buildMapReducePipelineStats() const { - std::vector pipelineStats; - - size_t docCount = 100; - long long execTimeMs = 0; - - pipelineStats.push_back(_buildStatsForStage("$cursor", docCount, execTimeMs)); - - execTimeMs += 5; - pipelineStats.push_back(_buildStatsForStage("$project", docCount, execTimeMs)); - - docCount *= 2; - execTimeMs += 5; - pipelineStats.push_back(_buildStatsForStage("$unwind", docCount, execTimeMs)); - - docCount -= 20; - execTimeMs += 5; - pipelineStats.push_back(_buildStatsForStage("$group", docCount, execTimeMs)); - - if (_addFinalize) { - execTimeMs += 5; - pipelineStats.push_back(_buildStatsForStage("$project", docCount, execTimeMs)); - } - - if (_addOut) { - execTimeMs += 5; - pipelineStats.push_back(_buildStatsForStage("$out", docCount, execTimeMs)); - } - - if (_addMerge) { - execTimeMs += 5; - pipelineStats.push_back(_buildStatsForStage("$merge", docCount, execTimeMs)); - } - - if (_addInvalidStageName) { - execTimeMs += 5; - pipelineStats.push_back(_buildStatsForStage("$changeStreams", docCount, execTimeMs)); - } - - return pipelineStats; - } - - void addFinalizeProject() { - _addFinalize = true; - } - void addOut() { - _addOut = true; - } - void addMerge() { - _addMerge = true; - } - void addInvalidStageForMapReduce() { - _addInvalidStageName = true; - } - -private: - CommonStats _buildStatsForStage(const char* name, size_t count, long long timeMillis) const { - CommonStats stageStats(name); - stageStats.advanced = count; - stageStats.executionTimeMillis = timeMillis; - return stageStats; - } - - bool _addFinalize = false; - bool _addOut = false; - bool _addMerge = false; - bool _addInvalidStageName = false; -}; - - -TEST_F(MapReduceStatsTest, ConfirmStatsUnsharded) { - MapReduceStats mapReduceStats(buildMapReducePipelineStats(), - MapReduceStats::ResponseType::kUnsharded, - false, // Not verbose - 99); // Total time - - BSONObjBuilder objBuilder; - mapReduceStats.appendStats(&objBuilder); - ASSERT_BSONOBJ_EQ(fromjson("{timeMillis: 99," - "counts: {input: 100, emit: 200, output: 180}}"), - objBuilder.obj()); -} - - -TEST_F(MapReduceStatsTest, ConfirmStatsUnshardedVerbose) { - MapReduceStats mapReduceStats(buildMapReducePipelineStats(), - MapReduceStats::ResponseType::kUnsharded, - true, // Verbose - 99); // Total time - - BSONObjBuilder objBuilder; - mapReduceStats.appendStats(&objBuilder); - ASSERT_BSONOBJ_EQ(fromjson("{timeMillis: 99," - "timing: { mapTime: 5, reduceTime: 5, total: 99 }," - "counts: {input: 100, emit: 200, output: 180}}"), - objBuilder.obj()); -} - -TEST_F(MapReduceStatsTest, ConfirmStatsUnshardedWithOutStage) { - addOut(); - - MapReduceStats mapReduceStats(buildMapReducePipelineStats(), - MapReduceStats::ResponseType::kUnsharded, - false, // Not verbose - 99); // Total time - - BSONObjBuilder objBuilder; - mapReduceStats.appendStats(&objBuilder); - ASSERT_BSONOBJ_EQ(fromjson("{timeMillis: 99," - "counts: {input: 100, emit: 200, output: 180}}"), - objBuilder.obj()); -} - -TEST_F(MapReduceStatsTest, ConfirmStatsUnshardedWithMergeStage) { - addMerge(); - MapReduceStats mapReduceStats(buildMapReducePipelineStats(), - MapReduceStats::ResponseType::kUnsharded, - false, // Not verbose - 99); // Total time - - BSONObjBuilder objBuilder; - mapReduceStats.appendStats(&objBuilder); - ASSERT_BSONOBJ_EQ(fromjson("{timeMillis: 99," - "counts: {input: 100, emit: 200, output: 180}}"), - objBuilder.obj()); -} - -TEST_F(MapReduceStatsTest, ConfirmStatsUnshardedWithFinalizeProjectStage) { - addFinalizeProject(); - MapReduceStats mapReduceStats(buildMapReducePipelineStats(), - MapReduceStats::ResponseType::kUnsharded, - false, // Not verbose - 99); // Total time - - BSONObjBuilder objBuilder; - mapReduceStats.appendStats(&objBuilder); - ASSERT_BSONOBJ_EQ(fromjson("{timeMillis: 99," - "counts: {input: 100, emit: 200, output: 180}}"), - objBuilder.obj()); -} - -DEATH_TEST_F(MapReduceStatsTest, - DeathByUnknownStage, - "Invariant failure stageName == \"$out\"_sd || stageName == " - "\"$internalOutToDifferentDB\"_sd || stageName == \"$merge\"_sd") { - addInvalidStageForMapReduce(); - MapReduceStats mapReduceStats(buildMapReducePipelineStats(), - MapReduceStats::ResponseType::kUnsharded, - false, // Not verbose - 99); // Total time -} - -} // namespace -} // namespace mongo diff --git a/src/mongo/db/query/SConscript b/src/mongo/db/query/SConscript index 950e4722834..ce94ea3a0c5 100644 --- a/src/mongo/db/query/SConscript +++ b/src/mongo/db/query/SConscript @@ -123,7 +123,6 @@ env.Library( ], LIBDEPS=[ '$BUILD_DIR/mongo/base', - '$BUILD_DIR/mongo/db/commands/map_reduce_stats', '$BUILD_DIR/mongo/db/namespace_string', ], ) diff --git a/src/mongo/db/query/map_reduce_output_format.cpp b/src/mongo/db/query/map_reduce_output_format.cpp index 23d8e9eee5a..cafbe483319 100644 --- a/src/mongo/db/query/map_reduce_output_format.cpp +++ b/src/mongo/db/query/map_reduce_output_format.cpp @@ -29,28 +29,21 @@ #include "mongo/platform/basic.h" -#include "mongo/db/commands/map_reduce_stats.h" #include "mongo/db/query/map_reduce_output_format.h" namespace mongo::map_reduce_output_format { -void appendInlineResponse(BSONArray&& documents, - const MapReduceStats& mapReduceStats, - BSONObjBuilder* resultBuilder) { +void appendInlineResponse(BSONArray&& documents, BSONObjBuilder* resultBuilder) { resultBuilder->appendArray("results", documents); - mapReduceStats.appendStats(resultBuilder); } void appendOutResponse(boost::optional outDb, std::string outColl, - const MapReduceStats& mapReduceStats, BSONObjBuilder* resultBuilder) { if (outDb) { resultBuilder->append("result", BSON("db" << *outDb << "collection" << outColl)); } else { resultBuilder->append("result", outColl); } - - mapReduceStats.appendStats(resultBuilder); } } // namespace mongo::map_reduce_output_format diff --git a/src/mongo/db/query/map_reduce_output_format.h b/src/mongo/db/query/map_reduce_output_format.h index b993d2c49ad..5189323d80e 100644 --- a/src/mongo/db/query/map_reduce_output_format.h +++ b/src/mongo/db/query/map_reduce_output_format.h @@ -30,27 +30,23 @@ #pragma once #include "mongo/bson/bsonobjbuilder.h" -#include "mongo/db/commands/map_reduce_stats.h" /** - * A collection of functions responsible for building a mapReduce command response from a result set - * and pipeline execution statistics. + * A collection of functions responsible for building a mapReduce command response from a result + * set. */ namespace mongo::map_reduce_output_format { /** * Appends an inline mapReduce command response to 'resultBuilder'. */ -void appendInlineResponse(BSONArray&& documents, - const MapReduceStats& mapReduceStats, - BSONObjBuilder* resultBuilder); +void appendInlineResponse(BSONArray&& documents, BSONObjBuilder* resultBuilder); /** * Appends an output-to-collection mapReduce command response to 'resultBuilder'. */ void appendOutResponse(boost::optional outDb, std::string outColl, - const MapReduceStats& mapReduceStats, BSONObjBuilder* resultBuilder); } // namespace mongo::map_reduce_output_format diff --git a/src/mongo/db/query/map_reduce_output_format_test.cpp b/src/mongo/db/query/map_reduce_output_format_test.cpp index f0d89dd3275..aabd28181b4 100644 --- a/src/mongo/db/query/map_reduce_output_format_test.cpp +++ b/src/mongo/db/query/map_reduce_output_format_test.cpp @@ -47,57 +47,27 @@ TEST(MapReduceOutputFormat, FormatInlineMapReduceResponse) { documents.append(BSON("b" << 1)); BSONObjBuilder builder; - map_reduce_output_format::appendInlineResponse( - documents.arr(), MapReduceStats::createForTest(), &builder); - ASSERT_BSONOBJ_EQ(fromjson("{results: [{a: 1}, {b: 1}]," - "timeMillis: 0," - "counts: {input: 0, emit: 0, output: 0}}"), - builder.obj()); -} - -TEST(MapReduceOutputFormat, FormatVerboseInlineMapReduceResponse) { - BSONArrayBuilder documents; - documents.append(BSON("a" << 1)); - documents.append(BSON("b" << 1)); - - BSONObjBuilder builder; - map_reduce_output_format::appendInlineResponse( - documents.arr(), MapReduceStats::createForTest(), &builder); - ASSERT_BSONOBJ_EQ(fromjson("{results: [{a: 1}, {b: 1}]," - "timeMillis: 0," - "counts: {input: 0, emit: 0, output: 0}}"), - builder.obj()); + map_reduce_output_format::appendInlineResponse(documents.arr(), &builder); + ASSERT_BSONOBJ_EQ(fromjson("{results: [{a: 1}, {b: 1}]}"), builder.obj()); } TEST(MapReduceOutputFormat, FormatEmptyInlineMapReduceResponse) { BSONArrayBuilder documents; BSONObjBuilder builder; - map_reduce_output_format::appendInlineResponse( - documents.arr(), MapReduceStats::createForTest(), &builder); - ASSERT_BSONOBJ_EQ(fromjson("{results: []," - "timeMillis: 0," - "counts: {input: 0, emit: 0, output: 0}}"), - builder.obj()); + map_reduce_output_format::appendInlineResponse(documents.arr(), &builder); + ASSERT_BSONOBJ_EQ(fromjson("{results: []}"), builder.obj()); } TEST(MapReduceOutputFormat, FormatNonInlineMapReduceResponseWithoutDb) { BSONObjBuilder builder; - map_reduce_output_format::appendOutResponse( - boost::none, "c", MapReduceStats::createForTest(), &builder); - ASSERT_BSONOBJ_EQ(fromjson("{result: \"c\"," - "timeMillis: 0," - "counts: {input: 0, emit: 0, output: 0}}"), - builder.obj()); + map_reduce_output_format::appendOutResponse(boost::none, "c", &builder); + ASSERT_BSONOBJ_EQ(fromjson("{result: \"c\"}"), builder.obj()); } TEST(MapReduceOutputFormat, FormatNonInlineMapReduceResponseWithDb) { BSONObjBuilder builder; - map_reduce_output_format::appendOutResponse( - "db"s, "c", MapReduceStats::createForTest(), &builder); - ASSERT_BSONOBJ_EQ(fromjson("{result: {db: \"db\", collection: \"c\"}," - "timeMillis: 0," - "counts: {input: 0, emit: 0, output: 0}}"), - builder.obj()); + map_reduce_output_format::appendOutResponse("db"s, "c", &builder); + ASSERT_BSONOBJ_EQ(fromjson("{result: {db: \"db\", collection: \"c\"}}"), builder.obj()); } } // namespace diff --git a/src/mongo/s/commands/cluster_map_reduce_agg.cpp b/src/mongo/s/commands/cluster_map_reduce_agg.cpp index 71f3deb8aa1..a7f12be3980 100644 --- a/src/mongo/s/commands/cluster_map_reduce_agg.cpp +++ b/src/mongo/s/commands/cluster_map_reduce_agg.cpp @@ -217,12 +217,10 @@ bool runAggregationMapReduce(OperationContext* opCtx, bab.append(elem.embeddedObject()); return bab.arr(); }(); - map_reduce_output_format::appendInlineResponse( - std::move(exhaustedResults), MapReduceStats::createForTest(), &result); + map_reduce_output_format::appendInlineResponse(std::move(exhaustedResults), &result); } else { map_reduce_output_format::appendOutResponse(parsedMr.getOutOptions().getDatabaseName(), parsedMr.getOutOptions().getCollectionName(), - MapReduceStats::createForTest(), &result); } -- cgit v1.2.1