summaryrefslogtreecommitdiff
path: root/src/mongo/db/s
diff options
context:
space:
mode:
authorjannaerin <golden.janna@gmail.com>2018-10-22 16:06:07 -0400
committerjannaerin <golden.janna@gmail.com>2018-10-25 13:40:14 -0400
commite720f0b57c8ce2ecf73926b542eb2c29ab7c1bc3 (patch)
treef68a233fd0bf6da89c927fda4fdf0616c6bf99b2 /src/mongo/db/s
parent7d8df4c73934ef757e4007743ab6b69e3e80b7c2 (diff)
downloadmongo-e720f0b57c8ce2ecf73926b542eb2c29ab7c1bc3.tar.gz
SERVER-37578 Assert that a zone is associated with a shard during shard collection
Diffstat (limited to 'src/mongo/db/s')
-rw-r--r--src/mongo/db/s/config/initial_split_policy.cpp15
-rw-r--r--src/mongo/db/s/config/initial_split_policy_test.cpp14
2 files changed, 27 insertions, 2 deletions
diff --git a/src/mongo/db/s/config/initial_split_policy.cpp b/src/mongo/db/s/config/initial_split_policy.cpp
index 67db0084bcc..5b0af255a05 100644
--- a/src/mongo/db/s/config/initial_split_policy.cpp
+++ b/src/mongo/db/s/config/initial_split_policy.cpp
@@ -232,13 +232,24 @@ InitialSplitPolicy::generateShardCollectionInitialZonedChunks(
const ShardId shardId = allShardIds[indx++ % allShardIds.size()];
appendChunk(nss, lastChunkMax, tag.getMinKey(), &version, validAfter, shardId, &chunks);
}
- // create a chunk for the zone
+
+ // check that this tag is associated with a shard and if so create a chunk for the zone.
+ const auto& shardIdsForChunk = tagToShards.find(tag.getTag())->second;
+ uassert(50973,
+ str::stream()
+ << "cannot shard collection "
+ << tag.getNS().ns()
+ << " because it is associated with zone: "
+ << tag.getTag()
+ << " which is not associated with a shard. please add this zone to a shard.",
+ !shardIdsForChunk.empty());
+
appendChunk(nss,
tag.getMinKey(),
tag.getMaxKey(),
&version,
validAfter,
- tagToShards.find(tag.getTag())->second[0],
+ shardIdsForChunk[0],
&chunks);
lastChunkMax = tag.getMaxKey();
}
diff --git a/src/mongo/db/s/config/initial_split_policy_test.cpp b/src/mongo/db/s/config/initial_split_policy_test.cpp
index a7a039f58b0..837d690900b 100644
--- a/src/mongo/db/s/config/initial_split_policy_test.cpp
+++ b/src/mongo/db/s/config/initial_split_policy_test.cpp
@@ -430,5 +430,19 @@ TEST_F(GenerateShardCollectionInitialZonedChunksTest, EmptyTagsShouldFail) {
ErrorCodes::InvalidOptions);
}
+TEST_F(GenerateShardCollectionInitialZonedChunksTest, ZoneNotAssociatedWithAnyShardShouldFail) {
+ const std::vector<TagsType> tags = {
+ makeTag(ChunkRange(keyPattern().globalMin(), BSON(shardKey() << 0)), zoneName("0")),
+ makeTag(ChunkRange(BSON(shardKey() << 0), keyPattern().globalMax()), zoneName("1"))};
+ StringMap<std::vector<ShardId>> tagToShards = {{zoneName("0"), {shardId("Shard0")}},
+ {zoneName("1"), {}}};
+
+ ASSERT_THROWS_CODE(
+ InitialSplitPolicy::generateShardCollectionInitialZonedChunks(
+ nss(), shardKeyPattern(), timeStamp(), tags, tagToShards, makeShardIds(1)),
+ AssertionException,
+ 50973);
+}
+
} // namespace
} // namespace mongo