diff options
author | Janna Golden <janna.golden@mongodb.com> | 2019-09-12 19:36:21 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-09-12 19:36:21 +0000 |
commit | b40e542972c082e85098c09298eb56436bf57abb (patch) | |
tree | 0fffe6ec4c2be2569e53af7dff158b521af2d1f2 /src | |
parent | 28749087a971171f1bb068c5a9515866e3050613 (diff) | |
download | mongo-b40e542972c082e85098c09298eb56436bf57abb.tar.gz |
SERVER-42827 Allow sessions collection to return OK for creating indexes if at least one shard returns OK and others return CannotImplicitlyCreateCollection
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/sessions_collection_config_server.cpp | 10 | ||||
-rw-r--r-- | src/mongo/s/cluster_commands_helpers.cpp | 23 | ||||
-rw-r--r-- | src/mongo/s/cluster_commands_helpers.h | 8 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_create_indexes_cmd.cpp | 19 |
4 files changed, 38 insertions, 22 deletions
diff --git a/src/mongo/db/sessions_collection_config_server.cpp b/src/mongo/db/sessions_collection_config_server.cpp index b9b339a5606..63e16f14321 100644 --- a/src/mongo/db/sessions_collection_config_server.cpp +++ b/src/mongo/db/sessions_collection_config_server.cpp @@ -79,11 +79,11 @@ Status SessionsCollectionConfigServer::_shardCollectionIfNeeded(OperationContext Status SessionsCollectionConfigServer::_generateIndexesIfNeeded(OperationContext* opCtx) { try { - scatterGatherOnlyVersionIfUnsharded(opCtx, - NamespaceString::kLogicalSessionsNamespace, - SessionsCollection::generateCreateIndexesCmd(), - ReadPreferenceSetting::get(opCtx), - Shard::RetryPolicy::kNoRetry); + dispatchCommandAssertCollectionExistsOnAtLeastOneShard( + opCtx, + NamespaceString::kLogicalSessionsNamespace, + SessionsCollection::generateCreateIndexesCmd()); + return Status::OK(); } catch (const DBException& ex) { return ex.toStatus(); diff --git a/src/mongo/s/cluster_commands_helpers.cpp b/src/mongo/s/cluster_commands_helpers.cpp index 7eead10ebfa..a2fd9e350b2 100644 --- a/src/mongo/s/cluster_commands_helpers.cpp +++ b/src/mongo/s/cluster_commands_helpers.cpp @@ -570,4 +570,27 @@ StatusWith<CachedCollectionRoutingInfo> getCollectionRoutingInfoForTxnCmd( return catalogCache->getCollectionRoutingInfoAt(opCtx, nss, atClusterTime.asTimestamp()); } +std::vector<AsyncRequestsSender::Response> dispatchCommandAssertCollectionExistsOnAtLeastOneShard( + OperationContext* opCtx, const NamespaceString& nss, const BSONObj& cmdObj) { + auto shardResponses = scatterGatherOnlyVersionIfUnsharded( + opCtx, + nss, + CommandHelpers::filterCommandRequestForPassthrough(cmdObj), + ReadPreferenceSetting::get(opCtx), + Shard::RetryPolicy::kNoRetry, + {ErrorCodes::CannotImplicitlyCreateCollection}); + + if (std::all_of(shardResponses.begin(), shardResponses.end(), [](const auto& response) { + return response.swResponse.getStatus().isOK() && + getStatusFromCommandResult(response.swResponse.getValue().data) == + ErrorCodes::CannotImplicitlyCreateCollection; + })) { + // Propagate the ExtraErrorInfo from the first response. + uassertStatusOK( + getStatusFromCommandResult(shardResponses.front().swResponse.getValue().data)); + } + + return shardResponses; +} + } // namespace mongo diff --git a/src/mongo/s/cluster_commands_helpers.h b/src/mongo/s/cluster_commands_helpers.h index 1e5ee9685fc..2a50e01d2a3 100644 --- a/src/mongo/s/cluster_commands_helpers.h +++ b/src/mongo/s/cluster_commands_helpers.h @@ -233,4 +233,12 @@ std::set<ShardId> getTargetedShardsForQuery(OperationContext* opCtx, StatusWith<CachedCollectionRoutingInfo> getCollectionRoutingInfoForTxnCmd( OperationContext* opCtx, const NamespaceString& nss); +/** + * Utility for dispatching a command on a namespace that is sent to all shards. If all shards return + * CannotImplicitlyCreateCollection, will throw. If at least one shard succeeds, will ignore + * CannotImplicitlyCreateCollection errors. + */ +std::vector<AsyncRequestsSender::Response> dispatchCommandAssertCollectionExistsOnAtLeastOneShard( + OperationContext* opCtx, const NamespaceString& nss, const BSONObj& cmdObj); + } // namespace mongo diff --git a/src/mongo/s/commands/cluster_create_indexes_cmd.cpp b/src/mongo/s/commands/cluster_create_indexes_cmd.cpp index 31e0d36625a..7ec58e26000 100644 --- a/src/mongo/s/commands/cluster_create_indexes_cmd.cpp +++ b/src/mongo/s/commands/cluster_create_indexes_cmd.cpp @@ -73,23 +73,8 @@ public: createShardDatabase(opCtx, dbName); - auto shardResponses = scatterGatherOnlyVersionIfUnsharded( - opCtx, - nss, - CommandHelpers::filterCommandRequestForPassthrough(cmdObj), - ReadPreferenceSetting::get(opCtx), - Shard::RetryPolicy::kNoRetry, - {ErrorCodes::CannotImplicitlyCreateCollection}); - - if (std::all_of(shardResponses.begin(), shardResponses.end(), [](const auto& response) { - return response.swResponse.getStatus().isOK() && - getStatusFromCommandResult(response.swResponse.getValue().data) == - ErrorCodes::CannotImplicitlyCreateCollection; - })) { - // Propagate the ExtraErrorInfo from the first response. - uassertStatusOK( - getStatusFromCommandResult(shardResponses.front().swResponse.getValue().data)); - } + auto shardResponses = + dispatchCommandAssertCollectionExistsOnAtLeastOneShard(opCtx, nss, cmdObj); return appendRawResponses(opCtx, &errmsg, |