summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandolph Tan <randolph@10gen.com>2017-10-27 16:01:07 -0400
committerRandolph Tan <randolph@10gen.com>2017-11-06 11:55:10 -0500
commit3432a9283ff1f12ef941b44d00cdb990495752f4 (patch)
tree88d9abd6bf8abe91c7ed0c55cf33bb9a3c03a91f
parentd2fce7077c22f9fe1f8fbb8659d032938686cf62 (diff)
downloadmongo-3432a9283ff1f12ef941b44d00cdb990495752f4.tar.gz
SERVER-30632 Always check that there are shards when sharding collection
-rw-r--r--src/mongo/db/s/config/configsvr_shard_collection_command.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/mongo/db/s/config/configsvr_shard_collection_command.cpp b/src/mongo/db/s/config/configsvr_shard_collection_command.cpp
index 53d0f5a2042..65fee2ae792 100644
--- a/src/mongo/db/s/config/configsvr_shard_collection_command.cpp
+++ b/src/mongo/db/s/config/configsvr_shard_collection_command.cpp
@@ -792,6 +792,10 @@ public:
Grid::get(opCtx)->shardRegistry()->getAllShardIds(&shardIds);
const int numShards = shardIds.size();
+ uassert(ErrorCodes::IllegalOperation,
+ "cannot shard collections before there are shards",
+ numShards > 0);
+
// Handle collections in the config db separately.
if (nss.db() == NamespaceString::kConfigDb) {
// Only whitelisted collections in config may be sharded
@@ -817,9 +821,6 @@ public:
// make a connection to the real primary shard for this database.
auto primaryShardId = [&]() {
if (nss.db() == NamespaceString::kConfigDb) {
- uassert(ErrorCodes::IllegalOperation,
- "cannot shard collections in config before there are shards",
- numShards > 0);
return shardIds[0];
} else {
return dbType.getPrimary();