From 242deee7c584613d0cd8f5bc9e10eea73bd18aad Mon Sep 17 00:00:00 2001 From: Esha Maharishi Date: Fri, 10 May 2019 14:02:09 -0400 Subject: SERVER-38367 Descriptive error message for the inability to create unique indexes on arbitrary fields in sharded collections --- src/mongo/s/cluster_commands_helpers.cpp | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) (limited to 'src/mongo/s/cluster_commands_helpers.cpp') diff --git a/src/mongo/s/cluster_commands_helpers.cpp b/src/mongo/s/cluster_commands_helpers.cpp index 981f33669ef..3d6cf6ed18b 100644 --- a/src/mongo/s/cluster_commands_helpers.cpp +++ b/src/mongo/s/cluster_commands_helpers.cpp @@ -187,7 +187,8 @@ std::vector gatherResponses( StringData dbName, const ReadPreferenceSetting& readPref, Shard::RetryPolicy retryPolicy, - const std::vector& requests) { + const std::vector& requests, + const std::set& ignorableErrors) { // Send the requests. MultiStatementTransactionRequestsSender ars( @@ -201,8 +202,6 @@ std::vector gatherResponses( // Get the responses. std::vector responses; // Stores results by ShardId - bool atLeastOneSucceeded = false; - boost::optional implicitCreateErrorStatus; while (!ars.done()) { auto response = ars.next(); @@ -215,10 +214,6 @@ std::vector gatherResponses( auto& responseObj = response.swResponse.getValue().data; status = getStatusFromCommandResult(responseObj); - if (status.isOK()) { - atLeastOneSucceeded = true; - } - // Failing to establish a consistent shardVersion means no results should be examined. if (ErrorCodes::isStaleShardVersionError(status.code())) { uassertStatusOK(status.withContext(str::stream() @@ -244,20 +239,18 @@ std::vector gatherResponses( uassertStatusOK(status); } - if (ErrorCodes::CannotImplicitlyCreateCollection == status) { - implicitCreateErrorStatus = status; + // TODO: This should not be needed once we get better targetting with SERVER-32723. + // Some commands are sent with allowImplicit: false to all shards and expect only some + // of them to succeed. + if (ignorableErrors.find(ErrorCodes::CannotImplicitlyCreateCollection) == + ignorableErrors.end() && + ErrorCodes::CannotImplicitlyCreateCollection == status) { + uassertStatusOK(status); } } responses.push_back(std::move(response)); } - // TODO: This should not be needed once we get better targetting with SERVER-32723. - // Some commands are sent with allowImplicit: false to all shards and expect only some of - // them to succeed. - if (implicitCreateErrorStatus && !atLeastOneSucceeded) { - uassertStatusOK(*implicitCreateErrorStatus); - } - return responses; } @@ -304,7 +297,8 @@ std::vector scatterGatherOnlyVersionIfUnsharded( const NamespaceString& nss, const BSONObj& cmdObj, const ReadPreferenceSetting& readPref, - Shard::RetryPolicy retryPolicy) { + Shard::RetryPolicy retryPolicy, + const std::set& ignorableErrors) { auto routingInfo = uassertStatusOK(Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfo(opCtx, nss)); @@ -319,7 +313,7 @@ std::vector scatterGatherOnlyVersionIfUnsharded( opCtx, nss, routingInfo, cmdObj, BSONObj(), BSONObj()); } - return gatherResponses(opCtx, nss.db(), readPref, retryPolicy, requests); + return gatherResponses(opCtx, nss.db(), readPref, retryPolicy, requests, ignorableErrors); } AsyncRequestsSender::Response executeCommandAgainstDatabasePrimary( -- cgit v1.2.1