From bd7dac53bbae3910b31ef7fb02dbcb75f70abcb0 Mon Sep 17 00:00:00 2001 From: Paolo Polato Date: Tue, 20 Dec 2022 20:30:11 +0000 Subject: SERVER-71120 Fix serialisation of collection created within aggregations --- src/mongo/s/cluster_commands_helpers.cpp | 14 +++++------ src/mongo/s/commands/cluster_create_cmd.cpp | 38 +++++++++-------------------- 2 files changed, 19 insertions(+), 33 deletions(-) diff --git a/src/mongo/s/cluster_commands_helpers.cpp b/src/mongo/s/cluster_commands_helpers.cpp index 0cb2660e032..25b0a1feeab 100644 --- a/src/mongo/s/cluster_commands_helpers.cpp +++ b/src/mongo/s/cluster_commands_helpers.cpp @@ -463,13 +463,13 @@ AsyncRequestsSender::Response executeCommandAgainstDatabasePrimary( ? appendShardVersion(cmdObj, ShardVersion::UNSHARDED()) : cmdObj; - auto responses = - gatherResponses(opCtx, - dbName, - readPref, - retryPolicy, - std::vector{AsyncRequestsSender::Request( - dbInfo->getPrimary(), appendDbVersionIfPresent(cmdObj, dbInfo))}); + auto responses = gatherResponses( + opCtx, + dbName, + readPref, + retryPolicy, + std::vector{AsyncRequestsSender::Request( + dbInfo->getPrimary(), appendDbVersionIfPresent(cmdObjWithShardVersion, dbInfo))}); return std::move(responses.front()); } diff --git a/src/mongo/s/commands/cluster_create_cmd.cpp b/src/mongo/s/commands/cluster_create_cmd.cpp index f73ce1356a0..a65bc19ab5a 100644 --- a/src/mongo/s/commands/cluster_create_cmd.cpp +++ b/src/mongo/s/commands/cluster_create_cmd.cpp @@ -130,32 +130,18 @@ public: // Manually forward the create collection command to the primary shard. const auto dbInfo = uassertStatusOK(Grid::get(opCtx)->catalogCache()->getDatabase( opCtx, dbName.toStringWithTenantId())); - auto response = [&] { - auto cmdToSend = cmd.toBSON({}); - cmdToSend = CommandHelpers::filterCommandRequestForPassthrough(cmd.toBSON({})); - cmdToSend = applyReadWriteConcern(opCtx, this, cmdToSend); - // If the DB primary resides on a shard, forward the create command applying the - // metadata that characterise an unsharded CRUD request according to the versioning - // protocol (the received DB version + an "UNSHARDED" shard version): this will - // guarantee that sharded DDL ops targeting the same namespace won't be executed in - // parallel. - // If the DB primary is hosted by the config server, apply the original metadata. - if (dbInfo->getPrimary() != ShardId::kConfigServerId) { - cmdToSend = appendShardVersion(cmdToSend, ShardVersion::UNSHARDED()); - } - cmdToSend = appendDbVersionIfPresent(cmdToSend, dbInfo); - - std::vector arsRequests{ - AsyncRequestsSender::Request(dbInfo->getPrimary(), cmdToSend)}; - - auto arsResponses = - gatherResponses(opCtx, - dbName.db(), - ReadPreferenceSetting(ReadPreference::PrimaryOnly), - Shard::RetryPolicy::kIdempotent, - arsRequests); - return uassertStatusOK(arsResponses.front().swResponse); - }(); + auto response = uassertStatusOK( + executeCommandAgainstDatabasePrimary( + opCtx, + dbName.db(), + dbInfo, + applyReadWriteConcern( + opCtx, + this, + CommandHelpers::filterCommandRequestForPassthrough(cmd.toBSON({}))), + ReadPreferenceSetting(ReadPreference::PrimaryOnly), + Shard::RetryPolicy::kIdempotent) + .swResponse); const auto createStatus = mongo::getStatusFromCommandResult(response.data); if (createStatus == ErrorCodes::NamespaceExists && -- cgit v1.2.1