diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2021-02-05 10:25:59 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-02-06 09:23:10 +0000 |
commit | 7664a855f33bbe7e0f77cee78cb07e564a4f0c4c (patch) | |
tree | d954b52885ee0c0b69f63593a02d3678f3b4e487 /src/mongo/db | |
parent | 0d804a26399c41e62a2d0a282120af0cc22b8959 (diff) | |
download | mongo-7664a855f33bbe7e0f77cee78cb07e564a4f0c4c.tar.gz |
SERVER-54283 Make the checks for new sharded DDL code path be uniform
Diffstat (limited to 'src/mongo/db')
9 files changed, 72 insertions, 89 deletions
diff --git a/src/mongo/db/s/config/configsvr_remove_shard_command.cpp b/src/mongo/db/s/config/configsvr_remove_shard_command.cpp index e1294d4540a..68d44a9435f 100644 --- a/src/mongo/db/s/config/configsvr_remove_shard_command.cpp +++ b/src/mongo/db/s/config/configsvr_remove_shard_command.cpp @@ -110,6 +110,7 @@ public: return shard->getId(); }(); + const auto catalogClient = Grid::get(opCtx)->catalogClient(); const auto shardingCatalogManager = ShardingCatalogManager::get(opCtx); const auto shardDrainingStatus = [&] { @@ -125,8 +126,7 @@ public: } }(); - const auto databases = - uassertStatusOK(shardingCatalogManager->getDatabasesForShard(opCtx, shardId)); + const auto databases = uassertStatusOK(catalogClient->getDatabasesForShard(opCtx, shardId)); // Get BSONObj containing: // 1) note about moving or dropping databases in a shard diff --git a/src/mongo/db/s/config/sharding_catalog_manager.cpp b/src/mongo/db/s/config/sharding_catalog_manager.cpp index 04348d28b9c..271fc1d52b8 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager.cpp @@ -327,6 +327,7 @@ void ShardingCatalogManager::startup() { if (_started) { return; } + _started = true; _executorForAddShard->startup(); @@ -336,11 +337,6 @@ void ShardingCatalogManager::startup() { } void ShardingCatalogManager::shutDown() { - { - stdx::lock_guard<Latch> lk(_mutex); - _inShutdown = true; - } - Grid::get(_serviceContext)->setCustomConnectionPoolStatsFn(nullptr); _executorForAddShard->shutdown(); diff --git a/src/mongo/db/s/config/sharding_catalog_manager.h b/src/mongo/db/s/config/sharding_catalog_manager.h index fa21318518f..aa3847ff594 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager.h +++ b/src/mongo/db/s/config/sharding_catalog_manager.h @@ -326,14 +326,6 @@ public: void enableSharding(OperationContext* opCtx, StringData dbName, const ShardId& primaryShard); /** - * Retrieves all databases for a shard. - * - * Returns a !OK status if an error occurs. - */ - StatusWith<std::vector<std::string>> getDatabasesForShard(OperationContext* opCtx, - const ShardId& shardId); - - /** * Updates metadata in config.databases collection to show the given primary database on its * new shard. */ @@ -628,9 +620,6 @@ private: Mutex _mutex = MONGO_MAKE_LATCH("ShardingCatalogManager::_mutex"); - // True if shutDown() has been called. False, otherwise. - bool _inShutdown{false}; // (M) - // True if startup() has been called. bool _started{false}; // (M) diff --git a/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp b/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp index 26826f55150..92397f38e88 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp @@ -183,8 +183,6 @@ void triggerFireAndForgetShardRefreshes(OperationContext* opCtx, const Collectio } } -} // namespace - void sendDropCollectionToAllShards(OperationContext* opCtx, const NamespaceString& nss) { const auto catalogClient = Grid::get(opCtx)->catalogClient(); @@ -314,6 +312,8 @@ void removeTagsForDroppedCollection(OperationContext* opCtx, const NamespaceStri ShardingCatalogClient::kMajorityWriteConcern)); } +} // namespace + void ShardingCatalogManager::dropCollection(OperationContext* opCtx, const NamespaceString& nss) { uassertStatusOK(ShardingLogging::get(opCtx)->logChangeChecked( opCtx, @@ -338,7 +338,7 @@ void ShardingCatalogManager::dropCollection(OperationContext* opCtx, const Names try { const auto catalogClient = Grid::get(opCtx)->catalogClient(); - auto collType = Grid::get(opCtx)->catalogClient()->getCollection(opCtx, nss); + auto collType = catalogClient->getCollection(opCtx, nss); const auto nssOrUUID = [&]() { if (collType.getTimestamp()) { return NamespaceStringOrUUID(std::string(), collType.getUuid()); diff --git a/src/mongo/db/s/config/sharding_catalog_manager_database_operations.cpp b/src/mongo/db/s/config/sharding_catalog_manager_database_operations.cpp index 65882b5c831..ff2ba0d90fc 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_database_operations.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_database_operations.cpp @@ -255,34 +255,6 @@ void ShardingCatalogManager::enableSharding(OperationContext* opCtx, ShardingCatalogClient::kLocalWriteConcern)); } -StatusWith<std::vector<std::string>> ShardingCatalogManager::getDatabasesForShard( - OperationContext* opCtx, const ShardId& shardId) { - auto findStatus = Grid::get(opCtx)->catalogClient()->_exhaustiveFindOnConfig( - opCtx, - kConfigReadSelector, - repl::ReadConcernLevel::kLocalReadConcern, - DatabaseType::ConfigNS, - BSON(DatabaseType::primary(shardId.toString())), - BSONObj(), - boost::none); // no limit - - if (!findStatus.isOK()) - return findStatus.getStatus(); - - std::vector<std::string> dbs; - for (const BSONObj& obj : findStatus.getValue().value) { - std::string dbName; - Status status = bsonExtractStringField(obj, DatabaseType::name(), &dbName); - if (!status.isOK()) { - return status; - } - - dbs.push_back(dbName); - } - - return dbs; -} - Status ShardingCatalogManager::commitMovePrimary(OperationContext* opCtx, const StringData dbname, const ShardId& toShard) { diff --git a/src/mongo/db/s/shardsvr_create_collection_command.cpp b/src/mongo/db/s/shardsvr_create_collection_command.cpp index 23efc3558d3..54ab4742d5c 100644 --- a/src/mongo/db/s/shardsvr_create_collection_command.cpp +++ b/src/mongo/db/s/shardsvr_create_collection_command.cpp @@ -184,14 +184,14 @@ public: using Request = ShardsvrCreateCollection; using Response = CreateCollectionResponse; - bool adminOnly() const override { - return false; - } - std::string help() const override { return "Internal command. Do not call directly. Creates a collection."; } + bool adminOnly() const override { + return false; + } + AllowedOnSecondary secondaryAllowed(ServiceContext*) const override { return AllowedOnSecondary::kNever; } @@ -215,18 +215,26 @@ public: "Create Collection path has not been implemented", request().getShardKey()); - if (feature_flags::gShardingFullDDLSupport.isEnabled( - serverGlobalParams.featureCompatibility)) { - LOGV2_DEBUG( - 5277910, 1, "Running new create collection procedure", "namespace"_attr = ns()); - return createCollection(opCtx, ns(), request()); - } else { + 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( + serverGlobalParams.featureCompatibility); + }(); + + if (!useNewPath) { LOGV2_DEBUG(5277911, 1, "Running legacy create collection procedure", "namespace"_attr = ns()); return createCollectionLegacy(opCtx, ns(), request()); } + + LOGV2_DEBUG( + 5277910, 1, "Running new create collection procedure", "namespace"_attr = ns()); + return createCollection(opCtx, ns(), request()); } private: diff --git a/src/mongo/db/s/shardsvr_drop_collection_command.cpp b/src/mongo/db/s/shardsvr_drop_collection_command.cpp index 0cd8bd76f20..bf0c068bdc2 100644 --- a/src/mongo/db/s/shardsvr_drop_collection_command.cpp +++ b/src/mongo/db/s/shardsvr_drop_collection_command.cpp @@ -60,6 +60,13 @@ void dropCollectionLegacy(OperationContext* opCtx, const NamespaceString& nss) { class ShardsvrDropCollectionCommand final : public TypedCommand<ShardsvrDropCollectionCommand> { public: + using Request = ShardsvrDropCollection; + + std::string help() const override { + return "Internal command, which is exported by the primary sharding server. Do not call " + "directly. Drops a collection."; + } + bool acceptsAnyApiVersionParameters() const override { return true; } @@ -68,13 +75,6 @@ public: return Command::AllowedOnSecondary::kNever; } - std::string help() const override { - return "Internal command, which is exported by the primary sharding server. Do not call " - "directly. Drops a collection."; - } - - using Request = ShardsvrDropCollection; - class Invocation final : public InvocationBase { public: using InvocationBase::InvocationBase; @@ -88,10 +88,16 @@ public: << opCtx->getWriteConcern().wMode, opCtx->getWriteConcern().wMode == WriteConcernOptions::kMajority); - if (!feature_flags::gShardingFullDDLSupport.isEnabled( - serverGlobalParams.featureCompatibility) || - feature_flags::gDisableIncompleteShardingDDLSupport.isEnabled( - serverGlobalParams.featureCompatibility)) { + 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( + serverGlobalParams.featureCompatibility); + }(); + + if (!useNewPath) { LOGV2_DEBUG(5280951, 1, "Running legacy drop collection procedure", diff --git a/src/mongo/db/s/shardsvr_drop_database_command.cpp b/src/mongo/db/s/shardsvr_drop_database_command.cpp index 98bdcfed9ad..4ba2286d8e5 100644 --- a/src/mongo/db/s/shardsvr_drop_database_command.cpp +++ b/src/mongo/db/s/shardsvr_drop_database_command.cpp @@ -63,6 +63,14 @@ DropDatabaseReply dropDatabaseLegacy(OperationContext* opCtx, StringData dbName) class ShardsvrDropDatabaseCommand final : public TypedCommand<ShardsvrDropDatabaseCommand> { public: + using Request = ShardsvrDropDatabase; + using Response = DropDatabaseReply; + + std::string help() const override { + return "Internal command, which is exported by the primary sharding server. Do not call " + "directly. Drops a database."; + } + bool acceptsAnyApiVersionParameters() const override { return true; } @@ -71,14 +79,6 @@ public: return Command::AllowedOnSecondary::kNever; } - std::string help() const override { - return "Internal command, which is exported by the primary sharding server. Do not call " - "directly. Drops a database."; - } - - using Request = ShardsvrDropDatabase; - using Response = DropDatabaseReply; - class Invocation final : public InvocationBase { public: using InvocationBase::InvocationBase; @@ -94,11 +94,16 @@ public: const auto dbName = request().getDbName(); - if (!feature_flags::gShardingFullDDLSupport.isEnabled( - serverGlobalParams.featureCompatibility) || - feature_flags::gDisableIncompleteShardingDDLSupport.isEnabled( - serverGlobalParams.featureCompatibility)) { + 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( + serverGlobalParams.featureCompatibility); + }(); + if (!useNewPath) { LOGV2_DEBUG( 5281110, 1, "Running legacy drop database procedure", "database"_attr = dbName); return dropDatabaseLegacy(opCtx, dbName); diff --git a/src/mongo/db/s/shardsvr_rename_collection_command.cpp b/src/mongo/db/s/shardsvr_rename_collection_command.cpp index 245e9fc9f0d..d0e098fcde0 100644 --- a/src/mongo/db/s/shardsvr_rename_collection_command.cpp +++ b/src/mongo/db/s/shardsvr_rename_collection_command.cpp @@ -207,14 +207,14 @@ public: using Request = ShardsvrRenameCollection; using Response = RenameCollectionResponse; - bool adminOnly() const override { - return false; - } - std::string help() const override { return "Internal command. Do not call directly. Renames a collection."; } + bool adminOnly() const override { + return false; + } + AllowedOnSecondary secondaryAllowed(ServiceContext*) const override { return AllowedOnSecondary::kNever; } @@ -229,10 +229,17 @@ public: auto const shardingState = ShardingState::get(opCtx); uassertStatusOK(shardingState->canAcceptShardedCommands()); - bool newPath = feature_flags::gShardingFullDDLSupport.isEnabled( - serverGlobalParams.featureCompatibility); - if (!isCollectionSharded(opCtx, fromNss) || !newPath) { + 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( + serverGlobalParams.featureCompatibility); + }(); + + if (!isCollectionSharded(opCtx, fromNss) || !useNewPath) { return renameUnshardedCollection(opCtx, req, fromNss); } |