summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorNicholas Zolnierz <nicholas.zolnierz@mongodb.com>2020-01-08 17:16:49 +0000
committerevergreen <evergreen@mongodb.com>2020-01-08 17:16:49 +0000
commitda7de3e73ea35a7c56606ef53cd2069658d02f08 (patch)
tree86889d4f04a70cf04d058c238df97846a95be088 /src/mongo
parent03c5fd6b1f9cf3977d41ef072065f480742c0af7 (diff)
downloadmongo-da7de3e73ea35a7c56606ef53cd2069658d02f08.tar.gz
SERVER-44477 Use correct collection count in cluster MR when determining whether to drop and reshard target
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/s/commands/cluster_map_reduce_cmd.cpp20
1 files changed, 7 insertions, 13 deletions
diff --git a/src/mongo/s/commands/cluster_map_reduce_cmd.cpp b/src/mongo/s/commands/cluster_map_reduce_cmd.cpp
index 53432a49499..abd98902feb 100644
--- a/src/mongo/s/commands/cluster_map_reduce_cmd.cpp
+++ b/src/mongo/s/commands/cluster_map_reduce_cmd.cpp
@@ -483,19 +483,18 @@ public:
// We need to determine whether we need to drop and shard the output collection and
// send the UUID to the shards. We will always do this if we are using replace so we
// 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.
+ // if the output collection does not exist.
bool shouldDropAndShard = replaceOutput;
if (!replaceOutput && outputCollNss.isValid()) {
- const auto primaryShard =
- uassertStatusOK(shardRegistry->getShard(opCtx, outputDbInfo.primaryId()));
- ScopedDbConnection conn(primaryShard->getConnString());
-
if (!outputRoutingInfo.cm()) {
// The output collection either exists and is unsharded, or does not exist. If
// the output collection exists and is unsharded, fail because we should not go
// from unsharded to sharded.
+ const auto primaryShard =
+ uassertStatusOK(shardRegistry->getShard(opCtx, outputDbInfo.primaryId()));
+ ScopedDbConnection conn(primaryShard->getConnString());
BSONObj listCollsCmdResponse;
+
ok = conn->runCommand(outDB,
BSON("listCollections"
<< 1 << "filter"
@@ -511,15 +510,10 @@ public:
// If we reach here, the collection does not exist at all.
shouldDropAndShard = true;
+ conn.done();
} 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.
- shouldDropAndShard = (conn->count(outputCollNss.ns()) == 0);
+ // The output collection exists and is sharded. Do not drop and reshard it.
}
-
- conn.done();
}
// If we are using replace, the output collection exists and is sharded, or the output