diff options
author | Jordi Serra Torrens <jordi.serra-torrens@mongodb.com> | 2021-02-11 11:53:40 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-02-18 11:36:47 +0000 |
commit | aac35501ac8d4cea15e69ad6230d99761682ef65 (patch) | |
tree | 697a8c5fdd8059758d66b5dc7033ab6c05618c14 /src/mongo | |
parent | 0e6950610ce228b302770fecd06c6159659d614a (diff) | |
download | mongo-aac35501ac8d4cea15e69ad6230d99761682ef65.tar.gz |
SERVER-53092: Ensure FCV stability while executing DDL critical paths
Diffstat (limited to 'src/mongo')
8 files changed, 57 insertions, 28 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 37a930a5304..7225380ba6f 100644 --- a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp +++ b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp @@ -313,14 +313,7 @@ public: ShardingCatalogManager::get(opCtx)->removePre49LegacyMetadata(opCtx); } - // Upgrade shards before config finishes its upgrade. - uassertStatusOK( - ShardingCatalogManager::get(opCtx)->setFeatureCompatibilityVersionOnShards( - opCtx, CommandHelpers::appendMajorityWriteConcern(request.toBSON({})))); - - // Amend metadata created before FCV 4.9. This must be done after all shards have - // been upgraded to 4.9 in order to guarantee that when the metadata is amended, no - // new databases or collections with the old version of the metadata will be added. + // Upgrade metadata created before FCV 4.9. // TODO SERVER-53283: Remove once 5.0 has been released. if (requestedVersion >= FeatureCompatibilityParams::Version::kVersion49) { try { @@ -332,6 +325,11 @@ public: throw; } } + + // Upgrade shards after config finishes its upgrade. + uassertStatusOK( + ShardingCatalogManager::get(opCtx)->setFeatureCompatibilityVersionOnShards( + opCtx, CommandHelpers::appendMajorityWriteConcern(request.toBSON({})))); } hangWhileUpgrading.pauseWhileSet(opCtx); @@ -424,15 +422,7 @@ public: return false; if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer) { - // Downgrade shards before config finishes its downgrade. - uassertStatusOK( - ShardingCatalogManager::get(opCtx)->setFeatureCompatibilityVersionOnShards( - opCtx, CommandHelpers::appendMajorityWriteConcern(request.toBSON({})))); - - // Amend metadata created in FCV 4.9. This must be done after all shards have - // been downgraded to prior 4.9 in order to guarantee that when the metadata is - // amended, no new databases or collections with the new version of the metadata - // will be added. + // Downgrade metadata created in FCV 4.9. // TODO SERVER-53283: Remove once 5.0 has been released. if (requestedVersion < FeatureCompatibilityParams::Version::kVersion49) { try { @@ -444,6 +434,11 @@ public: throw; } } + + // Downgrade shards after config finishes its downgrade. + uassertStatusOK( + ShardingCatalogManager::get(opCtx)->setFeatureCompatibilityVersionOnShards( + opCtx, CommandHelpers::appendMajorityWriteConcern(request.toBSON({})))); } hangWhileDowngrading.pauseWhileSet(opCtx); diff --git a/src/mongo/db/s/config/sharding_catalog_manager.cpp b/src/mongo/db/s/config/sharding_catalog_manager.cpp index ff00b91fbeb..ac993136494 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager.cpp @@ -42,6 +42,7 @@ #include "mongo/db/ops/write_ops.h" #include "mongo/db/query/query_request_helper.h" #include "mongo/db/s/balancer/type_migration.h" +#include "mongo/db/s/dist_lock_manager.h" #include "mongo/db/s/type_lockpings.h" #include "mongo/db/s/type_locks.h" #include "mongo/db/vector_clock.h" @@ -687,6 +688,12 @@ void ShardingCatalogManager::_upgradeCollectionsAndChunksMetadataFor49(Operation auto const catalogCache = Grid::get(opCtx)->catalogCache(); auto const configShard = Grid::get(opCtx)->shardRegistry()->getConfigShard(); + DistLockManager::ScopedDistLock dbDistLock(uassertStatusOK(DistLockManager::get(opCtx)->lock( + opCtx, + DistLockManager::kShardingRoutingInfoFormatStabilityLockName, + "fcvUpgrade", + DistLockManager::kDefaultLockTimeout))); + auto collectionDocs = uassertStatusOK( configShard->exhaustiveFindOnConfig( @@ -795,6 +802,13 @@ void ShardingCatalogManager::_downgradeCollectionsAndChunksMetadataToPre49( auto const catalogCache = Grid::get(opCtx)->catalogCache(); auto const configShard = Grid::get(opCtx)->shardRegistry()->getConfigShard(); + + DistLockManager::ScopedDistLock dbDistLock(uassertStatusOK(DistLockManager::get(opCtx)->lock( + opCtx, + DistLockManager::kShardingRoutingInfoFormatStabilityLockName, + "fcvDowngrade", + DistLockManager::kDefaultLockTimeout))); + auto collectionDocs = uassertStatusOK( configShard->exhaustiveFindOnConfig( diff --git a/src/mongo/db/s/dist_lock_manager.h b/src/mongo/db/s/dist_lock_manager.h index 120aea7a55e..953cc76d9b9 100644 --- a/src/mongo/db/s/dist_lock_manager.h +++ b/src/mongo/db/s/dist_lock_manager.h @@ -63,6 +63,10 @@ public: // should be made to wait for it to become free. static const Milliseconds kSingleLockAttemptTimeout; + // DistLock to ensure DDL operations see an stable sharding routing info format. + static constexpr StringData kShardingRoutingInfoFormatStabilityLockName = + "ShardingRoutingInfoFormatStability"_sd; + /** * RAII type for the local lock. */ diff --git a/src/mongo/db/s/shard_collection_legacy.cpp b/src/mongo/db/s/shard_collection_legacy.cpp index 766f1bb39ef..388c921f8b2 100644 --- a/src/mongo/db/s/shard_collection_legacy.cpp +++ b/src/mongo/db/s/shard_collection_legacy.cpp @@ -548,7 +548,6 @@ CreateCollectionResponse shardCollection(OperationContext* opCtx, shouldUseUUIDForChunkIndexing = feature_flags::gShardingFullDDLSupportTimestampedVersion.isEnabled( serverGlobalParams.featureCompatibility); - // TODO SERVER-53092: persist FCV placeholder } { @@ -663,8 +662,6 @@ CreateCollectionResponse shardCollection(OperationContext* opCtx, writeChunkDocumentsAndRefreshShards(*targetState, initialChunks); } - // TODO SERVER-53092: delete FCV placeholder - LOGV2(22101, "Created {numInitialChunks} chunk(s) for: {namespace}, producing collection version " "{initialCollectionVersion}", diff --git a/src/mongo/db/s/shardsvr_create_collection_command.cpp b/src/mongo/db/s/shardsvr_create_collection_command.cpp index 54ab4742d5c..d36b9f06587 100644 --- a/src/mongo/db/s/shardsvr_create_collection_command.cpp +++ b/src/mongo/db/s/shardsvr_create_collection_command.cpp @@ -215,9 +215,13 @@ public: "Create Collection path has not been implemented", request().getShardKey()); + DistLockManager::ScopedDistLock dbDistLock( + uassertStatusOK(DistLockManager::get(opCtx)->lock( + opCtx, + DistLockManager::kShardingRoutingInfoFormatStabilityLockName, + "createCollection", + DistLockManager::kDefaultLockTimeout))); bool useNewPath = [&] { - // TODO (SERVER-53092): Use the FCV lock in order to "reserve" operation as running - // in new or legacy mode return feature_flags::gShardingFullDDLSupport.isEnabled( serverGlobalParams.featureCompatibility) && !feature_flags::gDisableIncompleteShardingDDLSupport.isEnabled( diff --git a/src/mongo/db/s/shardsvr_drop_collection_command.cpp b/src/mongo/db/s/shardsvr_drop_collection_command.cpp index 537286b9b73..51fc7c21c82 100644 --- a/src/mongo/db/s/shardsvr_drop_collection_command.cpp +++ b/src/mongo/db/s/shardsvr_drop_collection_command.cpp @@ -34,6 +34,7 @@ #include "mongo/db/auth/authorization_session.h" #include "mongo/db/commands.h" #include "mongo/db/curop.h" +#include "mongo/db/s/dist_lock_manager.h" #include "mongo/db/s/drop_collection_coordinator.h" #include "mongo/db/s/drop_collection_legacy.h" #include "mongo/db/s/sharding_state.h" @@ -75,9 +76,13 @@ public: << opCtx->getWriteConcern().wMode, opCtx->getWriteConcern().wMode == WriteConcernOptions::kMajority); + DistLockManager::ScopedDistLock dbDistLock( + uassertStatusOK(DistLockManager::get(opCtx)->lock( + opCtx, + DistLockManager::kShardingRoutingInfoFormatStabilityLockName, + "dropCollection", + DistLockManager::kDefaultLockTimeout))); bool useNewPath = [&] { - // TODO (SERVER-53092): Use the FCV lock in order to "reserve" operation as running - // in new or legacy mode return feature_flags::gShardingFullDDLSupport.isEnabled( serverGlobalParams.featureCompatibility) && !feature_flags::gDisableIncompleteShardingDDLSupport.isEnabled( diff --git a/src/mongo/db/s/shardsvr_drop_database_command.cpp b/src/mongo/db/s/shardsvr_drop_database_command.cpp index 90548c530df..fc0b0499b6a 100644 --- a/src/mongo/db/s/shardsvr_drop_database_command.cpp +++ b/src/mongo/db/s/shardsvr_drop_database_command.cpp @@ -35,6 +35,7 @@ #include "mongo/db/catalog/collection_catalog.h" #include "mongo/db/commands.h" #include "mongo/db/curop.h" +#include "mongo/db/s/dist_lock_manager.h" #include "mongo/db/s/drop_database_coordinator.h" #include "mongo/db/s/drop_database_legacy.h" #include "mongo/db/s/sharding_state.h" @@ -79,9 +80,13 @@ public: const auto dbName = request().getDbName(); + DistLockManager::ScopedDistLock dbDistLock( + uassertStatusOK(DistLockManager::get(opCtx)->lock( + opCtx, + DistLockManager::kShardingRoutingInfoFormatStabilityLockName, + "dropDatabase", + DistLockManager::kDefaultLockTimeout))); bool useNewPath = [&] { - // TODO (SERVER-53092): Use the FCV lock in order to "reserve" operation as running - // in new or legacy mode return feature_flags::gShardingFullDDLSupport.isEnabled( serverGlobalParams.featureCompatibility) && !feature_flags::gDisableIncompleteShardingDDLSupport.isEnabled( diff --git a/src/mongo/db/s/shardsvr_rename_collection_command.cpp b/src/mongo/db/s/shardsvr_rename_collection_command.cpp index 352ac2414af..3eb11ab03c1 100644 --- a/src/mongo/db/s/shardsvr_rename_collection_command.cpp +++ b/src/mongo/db/s/shardsvr_rename_collection_command.cpp @@ -36,6 +36,7 @@ #include "mongo/db/commands.h" #include "mongo/db/db_raii.h" #include "mongo/db/s/collection_sharding_state.h" +#include "mongo/db/s/dist_lock_manager.h" #include "mongo/db/s/rename_collection_coordinator.h" #include "mongo/db/s/sharding_state.h" #include "mongo/logv2/log.h" @@ -110,9 +111,13 @@ public: auto const shardingState = ShardingState::get(opCtx); uassertStatusOK(shardingState->canAcceptShardedCommands()); + DistLockManager::ScopedDistLock dbDistLock( + uassertStatusOK(DistLockManager::get(opCtx)->lock( + opCtx, + DistLockManager::kShardingRoutingInfoFormatStabilityLockName, + "renameCollection", + DistLockManager::kDefaultLockTimeout))); bool useNewPath = [&] { - // TODO (SERVER-53092): Use the FCV lock in order to "reserve" operation as running - // in new or legacy mode return feature_flags::gShardingFullDDLSupport.isEnabled( serverGlobalParams.featureCompatibility) && !feature_flags::gDisableIncompleteShardingDDLSupport.isEnabled( |