diff options
author | Randolph Tan <randolph@10gen.com> | 2017-10-27 16:01:07 -0400 |
---|---|---|
committer | Randolph Tan <randolph@10gen.com> | 2017-11-06 11:55:10 -0500 |
commit | 3432a9283ff1f12ef941b44d00cdb990495752f4 (patch) | |
tree | 88d9abd6bf8abe91c7ed0c55cf33bb9a3c03a91f | |
parent | d2fce7077c22f9fe1f8fbb8659d032938686cf62 (diff) | |
download | mongo-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.cpp | 7 |
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(); |