summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlake Oler <blake.oler@mongodb.com>2019-03-26 13:25:21 -0400
committerBlake Oler <blake.oler@mongodb.com>2019-04-01 11:28:56 -0400
commit029336d07dd89eee17cfa090ca0b63f44883b485 (patch)
treeb0eadad9cd2858dda340d7b4af020d3d68a7111d
parent399db8ee6b738abbb69f4addac6f65542e18b234 (diff)
downloadmongo-029336d07dd89eee17cfa090ca0b63f44883b485.tar.gz
SERVER-40333 Only clone collection options once for each shard in shardsvrShardCollection
-rw-r--r--src/mongo/db/s/shardsvr_shard_collection.cpp23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/mongo/db/s/shardsvr_shard_collection.cpp b/src/mongo/db/s/shardsvr_shard_collection.cpp
index 6f9d335b67f..f7b8b55d7dd 100644
--- a/src/mongo/db/s/shardsvr_shard_collection.cpp
+++ b/src/mongo/db/s/shardsvr_shard_collection.cpp
@@ -472,9 +472,14 @@ void shardCollection(OperationContext* opCtx,
// want to do this for mapReduce.
if (!fromMapReduce) {
std::vector<AsyncRequestsSender::Request> requests;
+ std::set<ShardId> initializedShards;
for (const auto& chunk : initialChunks.chunks) {
- if (chunk.getShard() == dbPrimaryShardId)
+ const auto& chunkShardId = chunk.getShard();
+ if (chunkShardId == dbPrimaryShardId ||
+ initializedShards.find(chunkShardId) != initializedShards.end()) {
continue;
+ }
+
CloneCollectionOptionsFromPrimaryShard cloneCollectionOptionsFromPrimaryShardRequest(
nss);
@@ -483,9 +488,11 @@ void shardCollection(OperationContext* opCtx,
cloneCollectionOptionsFromPrimaryShardRequest.setDbName(nss.db());
requests.emplace_back(
- chunk.getShard(),
+ chunkShardId,
cloneCollectionOptionsFromPrimaryShardRequest.toBSON(
BSON("writeConcern" << ShardingCatalogClient::kMajorityWriteConcern.toBSON())));
+
+ initializedShards.emplace(chunkShardId);
}
if (!requests.empty()) {
@@ -532,15 +539,15 @@ void shardCollection(OperationContext* opCtx,
forceShardFilteringMetadataRefresh(opCtx, nss);
- std::vector<ShardId> shardsRefreshed;
+ std::set<ShardId> shardsRefreshed;
for (const auto& chunk : initialChunks.chunks) {
- if ((chunk.getShard() == dbPrimaryShardId) ||
- std::find(shardsRefreshed.begin(), shardsRefreshed.end(), chunk.getShard()) !=
- shardsRefreshed.end()) {
+ const auto& chunkShardId = chunk.getShard();
+ if (chunkShardId == dbPrimaryShardId ||
+ shardsRefreshed.find(chunkShardId) != shardsRefreshed.end()) {
continue;
}
- auto shard = uassertStatusOK(shardRegistry->getShard(opCtx, chunk.getShard()));
+ auto shard = uassertStatusOK(shardRegistry->getShard(opCtx, chunkShardId));
auto refreshCmdResponse = uassertStatusOK(shard->runCommandWithFixedRetryAttempts(
opCtx,
ReadPreferenceSetting{ReadPreference::PrimaryOnly},
@@ -550,7 +557,7 @@ void shardCollection(OperationContext* opCtx,
Shard::RetryPolicy::kIdempotent));
uassertStatusOK(refreshCmdResponse.commandStatus);
- shardsRefreshed.emplace_back(chunk.getShard());
+ shardsRefreshed.emplace(chunkShardId);
}
catalogClient