diff options
author | Cheahuychou Mao <cheahuychou.mao@mongodb.com> | 2019-12-13 17:58:58 +0000 |
---|---|---|
committer | A. Jesse Jiryu Davis <jesse@mongodb.com> | 2020-01-27 15:37:08 -0500 |
commit | 2732490d2473e8c326cf92bbf80c592b43b88cfd (patch) | |
tree | 6b930b90b286a4e7e2c82d1008613e51f412f510 /src/mongo/s | |
parent | 4c8afbd6e98287062db02cccf6899c5e8737feb9 (diff) | |
download | mongo-2732490d2473e8c326cf92bbf80c592b43b88cfd.tar.gz |
SERVER-45103 Sharded index commands shouldn't target primary shard if it doesn't own chunks
Diffstat (limited to 'src/mongo/s')
-rw-r--r-- | src/mongo/s/cluster_commands_helpers.cpp | 33 | ||||
-rw-r--r-- | src/mongo/s/cluster_commands_helpers.h | 16 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_collection_mod_cmd.cpp | 2 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_create_indexes_cmd.cpp | 2 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_drop_indexes_cmd.cpp | 2 |
5 files changed, 4 insertions, 51 deletions
diff --git a/src/mongo/s/cluster_commands_helpers.cpp b/src/mongo/s/cluster_commands_helpers.cpp index 5c6e8348cee..5386b54f153 100644 --- a/src/mongo/s/cluster_commands_helpers.cpp +++ b/src/mongo/s/cluster_commands_helpers.cpp @@ -135,8 +135,7 @@ std::vector<AsyncRequestsSender::Request> buildVersionedRequestsForTargetedShard const CachedCollectionRoutingInfo& routingInfo, const BSONObj& cmdObj, const BSONObj& query, - const BSONObj& collation, - const bool alwaysIncludePrimaryShard = false) { + const BSONObj& collation) { auto cmdToSend = cmdObj; if (!cmdToSend.hasField(kAllowImplicitCollectionCreation)) { @@ -164,19 +163,6 @@ std::vector<AsyncRequestsSender::Request> buildVersionedRequestsForTargetedShard std::set<ShardId> shardIds; routingInfo.cm()->getShardIdsForQuery(opCtx, query, collation, &shardIds); - if (alwaysIncludePrimaryShard && routingInfo.db().primaryId() != "config") { - // TODO (SERVER-44949): The only sharded collection which has the config server as - // the primary shard is config.system.sessions. Unfortunately, the config server - // calls this code path to create indexes on the sessions collection, and the code - // it uses to create the indexes would currently invariant if one of the targeted - // shards was the config server itself. To get around this, we skip targeting the - // config shard here, but as a result, listIndexes on config.system.sessions will - // not return the correct indexes. This bug existed prior to 4.4 as well, since - // the old code to create indexes on the sessions collection also did not build - // the index on the config server. - shardIds.insert(routingInfo.db().primaryId()); - } - for (const ShardId& shardId : shardIds) { requests.emplace_back(shardId, appendShardVersion(cmdToSend, routingInfo.cm()->getVersion(shardId))); @@ -395,23 +381,6 @@ std::vector<AsyncRequestsSender::Response> scatterGatherVersionedTargetByRouting return gatherResponses(opCtx, dbName, readPref, retryPolicy, requests); } -std::vector<AsyncRequestsSender::Response> -scatterGatherVersionedTargetPrimaryShardAndByRoutingTable( - OperationContext* opCtx, - StringData dbName, - const NamespaceString& nss, - const CachedCollectionRoutingInfo& routingInfo, - const BSONObj& cmdObj, - const ReadPreferenceSetting& readPref, - Shard::RetryPolicy retryPolicy, - const BSONObj& query, - const BSONObj& collation) { - const auto requests = buildVersionedRequestsForTargetedShards( - opCtx, nss, routingInfo, cmdObj, query, collation, true); - - return gatherResponses(opCtx, dbName, readPref, retryPolicy, requests); -} - std::vector<AsyncRequestsSender::Response> scatterGatherOnlyVersionIfUnsharded( OperationContext* opCtx, const NamespaceString& nss, diff --git a/src/mongo/s/cluster_commands_helpers.h b/src/mongo/s/cluster_commands_helpers.h index 8cb2aa0b77a..7c5d3224a56 100644 --- a/src/mongo/s/cluster_commands_helpers.h +++ b/src/mongo/s/cluster_commands_helpers.h @@ -154,22 +154,6 @@ std::vector<AsyncRequestsSender::Response> scatterGatherVersionedTargetByRouting const BSONObj& collation); /** - * Similar to scatterGatherVersionedTargetByRoutingTable but always targets the primary - * shard for the namespace. - */ -std::vector<AsyncRequestsSender::Response> -scatterGatherVersionedTargetPrimaryShardAndByRoutingTable( - OperationContext* opCtx, - StringData dbName, - const NamespaceString& nss, - const CachedCollectionRoutingInfo& routingInfo, - const BSONObj& cmdObj, - const ReadPreferenceSetting& readPref, - Shard::RetryPolicy retryPolicy, - const BSONObj& query, - const BSONObj& collation); - -/** * Utility for dispatching commands on a namespace, but with special hybrid versioning: * - If the namespace is unsharded, a version is attached (so this node can find out if its routing * table was stale, and the namespace is actually sharded), and only the primary shard is targeted. diff --git a/src/mongo/s/commands/cluster_collection_mod_cmd.cpp b/src/mongo/s/commands/cluster_collection_mod_cmd.cpp index 6166d09c832..21c8dc7a141 100644 --- a/src/mongo/s/commands/cluster_collection_mod_cmd.cpp +++ b/src/mongo/s/commands/cluster_collection_mod_cmd.cpp @@ -73,7 +73,7 @@ public: auto routingInfo = uassertStatusOK(Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfo(opCtx, nss)); - auto shardResponses = scatterGatherVersionedTargetPrimaryShardAndByRoutingTable( + auto shardResponses = scatterGatherVersionedTargetByRoutingTable( opCtx, nss.db(), nss, diff --git a/src/mongo/s/commands/cluster_create_indexes_cmd.cpp b/src/mongo/s/commands/cluster_create_indexes_cmd.cpp index 806670bb4da..cffbd636e71 100644 --- a/src/mongo/s/commands/cluster_create_indexes_cmd.cpp +++ b/src/mongo/s/commands/cluster_create_indexes_cmd.cpp @@ -76,7 +76,7 @@ public: auto routingInfo = uassertStatusOK(Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfo(opCtx, nss)); - auto shardResponses = scatterGatherVersionedTargetPrimaryShardAndByRoutingTable( + auto shardResponses = scatterGatherVersionedTargetByRoutingTable( opCtx, nss.db(), nss, diff --git a/src/mongo/s/commands/cluster_drop_indexes_cmd.cpp b/src/mongo/s/commands/cluster_drop_indexes_cmd.cpp index 64f89928c58..2b45943c3b8 100644 --- a/src/mongo/s/commands/cluster_drop_indexes_cmd.cpp +++ b/src/mongo/s/commands/cluster_drop_indexes_cmd.cpp @@ -76,7 +76,7 @@ public: // been dropped on an earlier attempt. auto routingInfo = uassertStatusOK(Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfo(opCtx, nss)); - auto shardResponses = scatterGatherVersionedTargetPrimaryShardAndByRoutingTable( + auto shardResponses = scatterGatherVersionedTargetByRoutingTable( opCtx, nss.db(), nss, |