summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Caimano <ben.caimano@10gen.com>2018-07-05 10:28:40 -0400
committerBen Caimano <ben.caimano@10gen.com>2018-07-19 15:11:12 -0400
commit762e505dd993aae5163f89104055cf72a406a3f8 (patch)
tree24c245c27fc919b20a13f1a1b51af79b6bbd6339
parentad166a6d50e0d03ac3cb3d4babcffc4cf887cb1b (diff)
downloadmongo-762e505dd993aae5163f89104055cf72a406a3f8.tar.gz
SERVER-35961 Remove unitialized count variable in MapReduce command
(cherry picked from commit 173ac70346990e4cf9b2720f86697785b8795967)
-rw-r--r--src/mongo/s/commands/cluster_map_reduce_cmd.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/mongo/s/commands/cluster_map_reduce_cmd.cpp b/src/mongo/s/commands/cluster_map_reduce_cmd.cpp
index 321ced17d92..f7667fb8607 100644
--- a/src/mongo/s/commands/cluster_map_reduce_cmd.cpp
+++ b/src/mongo/s/commands/cluster_map_reduce_cmd.cpp
@@ -476,7 +476,7 @@ public:
// can skip this check in that case. If using merge or reduce, we only want to do this
// if the output collection does not exist or if it exists and is an empty sharded
// collection.
- int count;
+ bool shouldDropAndShard = replaceOutput;
if (!replaceOutput && outputCollNss.isValid()) {
const auto primaryShard =
uassertStatusOK(shardRegistry->getShard(opCtx, outputDbInfo.primaryId()));
@@ -499,12 +499,15 @@ public:
"Cannot output to a sharded collection because "
"non-sharded collection exists already",
collections.isEmpty());
+
+ // If we reach here, the collection does not exist at all.
+ shouldDropAndShard = true;
} else {
// The output collection exists and is sharded. We need to determine whether the
// collection is empty in order to decide whether we should drop and re-shard
// it.
// We don't want to do this if the collection is not empty.
- count = conn->count(outputCollNss.ns());
+ shouldDropAndShard = (conn->count(outputCollNss.ns()) == 0);
}
conn.done();
@@ -515,8 +518,7 @@ public:
// UUID generated during shardCollection to the shards to be used to create the temp
// collections.
boost::optional<UUID> shardedOutputCollUUID;
- if (replaceOutput ||
- (outputCollNss.isValid() && (count == 0 || !outputRoutingInfo.cm()))) {
+ if (shouldDropAndShard) {
auto dropCmdResponse = uassertStatusOK(
Grid::get(opCtx)
->shardRegistry()