diff options
Diffstat (limited to 'src/mongo/s/commands/cluster_commands_helpers.cpp')
-rw-r--r-- | src/mongo/s/commands/cluster_commands_helpers.cpp | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/mongo/s/commands/cluster_commands_helpers.cpp b/src/mongo/s/commands/cluster_commands_helpers.cpp index 50e170fec57..6fe459226eb 100644 --- a/src/mongo/s/commands/cluster_commands_helpers.cpp +++ b/src/mongo/s/commands/cluster_commands_helpers.cpp @@ -70,6 +70,12 @@ void appendWriteConcernErrorToCmdResponse(const ShardId& shardId, namespace { +BSONObj appendDbVersion(BSONObj cmdObj, DatabaseVersion version) { + BSONObjBuilder cmdWithVersionBob(std::move(cmdObj)); + cmdWithVersionBob.append("databaseVersion", version.toBSON()); + return cmdWithVersionBob.obj(); +} + std::vector<AsyncRequestsSender::Request> buildUnversionedRequestsForAllShards( OperationContext* opCtx, const BSONObj& cmdObj) { std::vector<AsyncRequestsSender::Request> requests; @@ -98,11 +104,22 @@ std::vector<AsyncRequestsSender::Request> buildVersionedRequestsForTargetedShard } } else { // The collection is unsharded. Target only the primary shard for the database. - // Don't append shard version info when contacting the config servers. - requests.emplace_back(routingInfo.primaryId(), - !routingInfo.primary()->isConfig() - ? appendShardVersion(cmdObj, ChunkVersion::UNSHARDED()) - : cmdObj); + + // Attach shardVersion "UNSHARDED", unless targeting the config server. + const auto cmdObjWithShardVersion = (routingInfo.db().primaryId() != "config") + ? appendShardVersion(cmdObj, ChunkVersion::UNSHARDED()) + : cmdObj; + + // Attach the databaseVersion if we have one cached for the database. + // TODO: After 4.0 is released, require the routingInfo to have a databaseVersion for all + // databases besides "config" and "admin" (whose primary shard cannot be changed). + // (In v4.0, if the cluster is in fcv=3.6, we may not have a databaseVersion cached for any + // database). + const auto cmdObjWithShardVersionAndDbVersion = routingInfo.db().databaseVersion() + ? appendDbVersion(cmdObjWithShardVersion, *routingInfo.db().databaseVersion()) + : cmdObjWithShardVersion; + + requests.emplace_back(routingInfo.db().primaryId(), cmdObjWithShardVersionAndDbVersion); } return requests; } |