diff options
author | Allison Easton <allison.easton@mongodb.com> | 2023-04-03 08:01:28 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-04-03 09:12:56 +0000 |
commit | af10b407ed0ddcc50395e046a296551ef3ba8bb2 (patch) | |
tree | 248272accd9338e29604917a9fa4f490fd2fb69f /src | |
parent | 3845fac4c113bf576f07ae406043b58e5c47f81f (diff) | |
download | mongo-af10b407ed0ddcc50395e046a296551ef3ba8bb2.tar.gz |
SERVER-75368 Set cluster parameter during FCV upgrade
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/commands/set_feature_compatibility_version_command.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp index b7b4b8a38c9..c8c7a2a33ef 100644 --- a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp +++ b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp @@ -74,6 +74,7 @@ #include "mongo/db/s/resharding/resharding_coordinator_service.h" #include "mongo/db/s/resharding/resharding_donor_recipient_common.h" #include "mongo/db/s/shard_authoritative_catalog_gen.h" +#include "mongo/db/s/sharding_cluster_parameters_gen.h" #include "mongo/db/s/sharding_ddl_coordinator_service.h" #include "mongo/db/s/sharding_index_catalog_ddl_util.h" #include "mongo/db/s/sharding_state.h" @@ -91,6 +92,8 @@ #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/s/catalog/type_config_version.h" #include "mongo/s/catalog/type_index_catalog.h" +#include "mongo/s/grid.h" +#include "mongo/s/request_types/sharded_ddl_commands_gen.h" #include "mongo/s/sharding_feature_flags_gen.h" #include "mongo/stdx/unordered_set.h" #include "mongo/util/exit.h" @@ -690,6 +693,7 @@ private: // Depends on _setOnCurrentShardSinceFieldOnChunks() _initializePlacementHistory(opCtx, requestedVersion, actualVersion); _dropConfigMigrationsCollection(opCtx); + _setShardedClusterCardinalityParam(opCtx, requestedVersion); } _removeRecordPreImagesCollectionOption(opCtx); @@ -804,6 +808,47 @@ private: } } + void _setShardedClusterCardinalityParam( + OperationContext* opCtx, const multiversion::FeatureCompatibilityVersion requestedVersion) { + if (feature_flags::gCheckForDirectShardOperations.isEnabledOnVersion(requestedVersion)) { + // Get current cluster parameter value so that we don't run SetClusterParameter + // extraneously + auto* clusterParameters = ServerParameterSet::getClusterParameterSet(); + auto* clusterCardinalityParam = + clusterParameters->get<ClusterParameterWithStorage<ShardedClusterCardinalityParam>>( + "shardedClusterCardinalityForDirectConns"); + auto currentValue = + clusterCardinalityParam->getValue(boost::none).getHasTwoOrMoreShards(); + + // config.shards is stable during FCV changes, so query that to discover the current + // number of shards. + DBDirectClient client(opCtx); + FindCommandRequest findRequest{NamespaceString::kConfigsvrShardsNamespace}; + findRequest.setLimit(2); + auto numShards = client.find(std::move(findRequest))->itcount(); + bool expectedValue = numShards >= 2; + + if (expectedValue == currentValue) { + return; + } + + ConfigsvrSetClusterParameter configsvrSetClusterParameter( + BSON("shardedClusterCardinalityForDirectConns" + << BSON("hasTwoOrMoreShards" << expectedValue))); + configsvrSetClusterParameter.setDbName(DatabaseName(boost::none, "admin")); + + const auto shardRegistry = Grid::get(opCtx)->shardRegistry(); + const auto cmdResponse = + uassertStatusOK(shardRegistry->getConfigShard()->runCommandWithFixedRetryAttempts( + opCtx, + ReadPreferenceSetting(ReadPreference::PrimaryOnly), + DatabaseName::kAdmin.toString(), + configsvrSetClusterParameter.toBSON({}), + Shard::RetryPolicy::kIdempotent)); + uassertStatusOK(Shard::CommandResponse::getEffectiveStatus(std::move(cmdResponse))); + } + } + // TODO (SERVER-72791): Remove once FCV 7.0 becomes last-lts. void _setOnCurrentShardSinceFieldOnChunks( OperationContext* opCtx, |