diff options
author | Ben Caimano <ben.caimano@10gen.com> | 2018-07-05 10:28:40 -0400 |
---|---|---|
committer | Ben Caimano <ben.caimano@10gen.com> | 2018-07-05 17:30:06 -0400 |
commit | 173ac70346990e4cf9b2720f86697785b8795967 (patch) | |
tree | 5c8e3ec1e4034fc5cc5dcd345e59a6ba810336d5 | |
parent | c305d79efaffeeda60079b0f4b4207841c3c0c77 (diff) | |
download | mongo-173ac70346990e4cf9b2720f86697785b8795967.tar.gz |
SERVER-35961 Remove unitialized count variable in MapReduce command
-rw-r--r-- | src/mongo/s/commands/cluster_map_reduce_cmd.cpp | 10 |
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 d89c80e7295..11de9f74faa 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() |