diff options
author | Paolo Polato <paolo.polato@mongodb.com> | 2022-12-20 20:30:11 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-12-20 21:01:31 +0000 |
commit | bd7dac53bbae3910b31ef7fb02dbcb75f70abcb0 (patch) | |
tree | ed1d74e761cbb700bf57b0a60b64f06b0d28b839 | |
parent | 07118e1f61dddb68170b7aa095166028b284d687 (diff) | |
download | mongo-bd7dac53bbae3910b31ef7fb02dbcb75f70abcb0.tar.gz |
SERVER-71120 Fix serialisation of collection created within aggregations
-rw-r--r-- | src/mongo/s/cluster_commands_helpers.cpp | 14 | ||||
-rw-r--r-- | 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>{AsyncRequestsSender::Request( - dbInfo->getPrimary(), appendDbVersionIfPresent(cmdObj, dbInfo))}); + auto responses = gatherResponses( + opCtx, + dbName, + readPref, + retryPolicy, + std::vector<AsyncRequestsSender::Request>{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<AsyncRequestsSender::Request> 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 && |