summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorTommaso Tocci <tommaso.tocci@mongodb.com>2021-07-27 12:19:42 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-07-27 12:40:57 +0000
commit53078d274792e569f03c6df044edf1d525163452 (patch)
tree561c15f7c5b15f79a81acb96a7028b7d61d560c7 /src/mongo
parente7e7fbc7dcd814c74ab2613a1ae3aa0adf7222b2 (diff)
downloadmongo-53078d274792e569f03c6df044edf1d525163452.tar.gz
SERVER-58820 Remove legacy drop collection/database paths
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/s/README.md2
-rw-r--r--src/mongo/db/s/SConscript5
-rw-r--r--src/mongo/db/s/config/configsvr_drop_collection_command.cpp127
-rw-r--r--src/mongo/db/s/config/configsvr_drop_database_command.cpp135
-rw-r--r--src/mongo/db/s/config/sharding_catalog_manager_drop_coll_test.cpp558
-rw-r--r--src/mongo/db/s/drop_collection_legacy.cpp373
-rw-r--r--src/mongo/db/s/drop_collection_legacy.h51
-rw-r--r--src/mongo/db/s/drop_database_legacy.cpp140
-rw-r--r--src/mongo/db/s/drop_database_legacy.h40
-rw-r--r--src/mongo/db/s/shardsvr_drop_collection_command.cpp20
-rw-r--r--src/mongo/db/s/shardsvr_drop_database_command.cpp22
11 files changed, 1 insertions, 1472 deletions
diff --git a/src/mongo/db/s/README.md b/src/mongo/db/s/README.md
index cc015ecf804..d931ed581c7 100644
--- a/src/mongo/db/s/README.md
+++ b/src/mongo/db/s/README.md
@@ -452,8 +452,6 @@ authoritative routing table.
[**forwards to the primary shard**](https://github.com/mongodb/mongo/blob/r4.3.4/src/mongo/s/commands/cluster_create_cmd.cpp#L128)
* Example of a DDL command (drop collection) mongos
[**forwards to the config server primary**](https://github.com/mongodb/mongo/blob/r4.3.4/src/mongo/s/commands/cluster_drop_cmd.cpp#L81-L82)
-* Example of a DDL command (drop collection) the config server
-[**coordinates itself**](https://github.com/mongodb/mongo/blob/r4.3.4/src/mongo/db/s/config/configsvr_drop_collection_command.cpp).
The business logic for most DDL commands that the config server coordinates lives in the
[**ShardingCatalogManager class**](https://github.com/mongodb/mongo/blob/r4.3.4/src/mongo/db/s/config/sharding_catalog_manager.h#L86),
including the logic for
diff --git a/src/mongo/db/s/SConscript b/src/mongo/db/s/SConscript
index 48b569b3cbd..f43fcce97e6 100644
--- a/src/mongo/db/s/SConscript
+++ b/src/mongo/db/s/SConscript
@@ -250,8 +250,6 @@ env.Library(
'dist_lock_catalog.cpp',
'dist_lock_manager_replset.cpp',
'dist_lock_manager.cpp',
- 'drop_collection_legacy.cpp',
- 'drop_database_legacy.cpp',
'sharding_config_server_parameters.idl',
'sharding_ddl_50_upgrade_downgrade.cpp',
'sharding_ddl_util.cpp',
@@ -309,8 +307,6 @@ env.Library(
'config/configsvr_commit_reshard_collection_command.cpp',
'config/configsvr_control_balancer_command.cpp',
'config/configsvr_create_database_command.cpp',
- 'config/configsvr_drop_collection_command.cpp',
- 'config/configsvr_drop_database_command.cpp',
'config/configsvr_ensure_chunk_version_is_greater_than_command.cpp',
'config/configsvr_merge_chunk_command.cpp',
'config/configsvr_merge_chunks_command.cpp',
@@ -578,7 +574,6 @@ env.CppUnitTest(
'config/sharding_catalog_manager_clear_jumbo_flag_test.cpp',
'config/sharding_catalog_manager_commit_chunk_migration_test.cpp',
'config/sharding_catalog_manager_config_initialization_test.cpp',
- 'config/sharding_catalog_manager_drop_coll_test.cpp',
'config/sharding_catalog_manager_ensure_chunk_version_is_greater_than_test.cpp',
'config/sharding_catalog_manager_merge_chunks_test.cpp',
'config/sharding_catalog_manager_remove_shard_from_zone_test.cpp',
diff --git a/src/mongo/db/s/config/configsvr_drop_collection_command.cpp b/src/mongo/db/s/config/configsvr_drop_collection_command.cpp
deleted file mode 100644
index 829b3c40ef1..00000000000
--- a/src/mongo/db/s/config/configsvr_drop_collection_command.cpp
+++ /dev/null
@@ -1,127 +0,0 @@
-/**
- * Copyright (C) 2018-present MongoDB, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the Server Side Public License, version 1,
- * as published by MongoDB, Inc.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * Server Side Public License for more details.
- *
- * You should have received a copy of the Server Side Public License
- * along with this program. If not, see
- * <http://www.mongodb.com/licensing/server-side-public-license>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the Server Side Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kSharding
-
-#include "mongo/platform/basic.h"
-
-#include "mongo/db/auth/authorization_session.h"
-#include "mongo/db/client.h"
-#include "mongo/db/commands.h"
-#include "mongo/db/commands/feature_compatibility_version.h"
-#include "mongo/db/operation_context.h"
-#include "mongo/db/repl/read_concern_args.h"
-#include "mongo/db/s/drop_collection_legacy.h"
-
-// TODO (SERVER-54879): Remove this command entirely after 5.0 branches
-namespace mongo {
-namespace {
-
-using FeatureCompatibility = ServerGlobalParams::FeatureCompatibility;
-using FCVersion = FeatureCompatibility::Version;
-
-/**
- * Internal sharding command run on config servers to drop a collection from a database.
- */
-class ConfigSvrDropCollectionCommand : public BasicCommand {
-public:
- ConfigSvrDropCollectionCommand() : BasicCommand("_configsvrDropCollection") {}
-
- /**
- * We accept any apiVersion, apiStrict, and/or apiDeprecationErrors, and forward it with the
- * "drop" command to shards.
- */
- bool acceptsAnyApiVersionParameters() const override {
- return true;
- }
-
- AllowedOnSecondary secondaryAllowed(ServiceContext*) const override {
- return AllowedOnSecondary::kNever;
- }
-
- bool adminOnly() const override {
- return true;
- }
-
- bool supportsWriteConcern(const BSONObj& cmd) const override {
- return true;
- }
-
- std::string help() const override {
- return "Internal command, which is exported by the sharding config server. Do not call "
- "directly. Drops a collection from a database.";
- }
-
- Status checkAuthForCommand(Client* client,
- const std::string& dbname,
- const BSONObj& cmdObj) const override {
- if (!AuthorizationSession::get(client)->isAuthorizedForActionsOnResource(
- ResourcePattern::forClusterResource(), ActionType::internal)) {
- return Status(ErrorCodes::Unauthorized, "Unauthorized");
- }
- return Status::OK();
- }
-
- std::string parseNs(const std::string& dbname, const BSONObj& cmdObj) const override {
- return CommandHelpers::parseNsFullyQualified(cmdObj);
- }
-
- bool run(OperationContext* opCtx,
- const std::string& dbname,
- const BSONObj& cmdObj,
- BSONObjBuilder& result) override {
- uassert(ErrorCodes::IllegalOperation,
- "_configsvrDropCollection can only be run on config servers",
- serverGlobalParams.clusterRole == ClusterRole::ConfigServer);
-
- // Set the operation context read concern level to local for reads into the config database.
- repl::ReadConcernArgs::get(opCtx) =
- repl::ReadConcernArgs(repl::ReadConcernLevel::kLocalReadConcern);
-
- const NamespaceString nss(parseNs(dbname, cmdObj));
-
- uassert(ErrorCodes::InvalidOptions,
- str::stream() << "dropCollection must be called with majority writeConcern, got "
- << cmdObj,
- opCtx->getWriteConcern().wMode == WriteConcernOptions::kMajority);
-
- FixedFCVRegion fcvRegion(opCtx);
-
- uassert(ErrorCodes::CommandNotSupported,
- "The _configsvrDropCollection command is only supported under feature "
- "compatibility version 4.4",
- fcvRegion == FCVersion::kFullyDowngradedTo44);
-
- dropCollectionLegacy(opCtx, nss, fcvRegion);
- return true;
- }
-} configsvrDropCollectionCmd;
-
-} // namespace
-} // namespace mongo
diff --git a/src/mongo/db/s/config/configsvr_drop_database_command.cpp b/src/mongo/db/s/config/configsvr_drop_database_command.cpp
deleted file mode 100644
index 346abbf8144..00000000000
--- a/src/mongo/db/s/config/configsvr_drop_database_command.cpp
+++ /dev/null
@@ -1,135 +0,0 @@
-/**
- * Copyright (C) 2018-present MongoDB, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the Server Side Public License, version 1,
- * as published by MongoDB, Inc.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * Server Side Public License for more details.
- *
- * You should have received a copy of the Server Side Public License
- * along with this program. If not, see
- * <http://www.mongodb.com/licensing/server-side-public-license>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the Server Side Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kSharding
-
-#include "mongo/platform/basic.h"
-
-#include "mongo/db/api_parameters.h"
-#include "mongo/db/auth/authorization_session.h"
-#include "mongo/db/client.h"
-#include "mongo/db/commands.h"
-#include "mongo/db/commands/feature_compatibility_version.h"
-#include "mongo/db/operation_context.h"
-#include "mongo/db/repl/repl_client_info.h"
-#include "mongo/db/s/drop_database_legacy.h"
-#include "mongo/s/catalog/type_database.h"
-
-// TODO (SERVER-54879): Remove this command entirely after 5.0 branches
-namespace mongo {
-namespace {
-
-using FeatureCompatibility = ServerGlobalParams::FeatureCompatibility;
-using FCVersion = FeatureCompatibility::Version;
-
-/**
- * Internal sharding command run on config servers to drop a database.
- */
-class ConfigSvrDropDatabaseCommand : public BasicCommand {
-public:
- ConfigSvrDropDatabaseCommand() : BasicCommand("_configsvrDropDatabase") {}
-
- /**
- * We accept any apiVersion, apiStrict, and/or apiDeprecationErrors, and forward it with the
- * "dropDatabase" command to shards.
- */
- bool acceptsAnyApiVersionParameters() const override {
- return true;
- }
-
- AllowedOnSecondary secondaryAllowed(ServiceContext*) const override {
- return AllowedOnSecondary::kNever;
- }
-
- bool adminOnly() const override {
- return true;
- }
-
- bool supportsWriteConcern(const BSONObj& cmd) const override {
- return true;
- }
-
- std::string help() const override {
- return "Internal command, which is exported by the sharding config server. Do not call "
- "directly. Drops a database.";
- }
-
- Status checkAuthForCommand(Client* client,
- const std::string& dbname,
- const BSONObj& cmdObj) const override {
- if (!AuthorizationSession::get(client)->isAuthorizedForActionsOnResource(
- ResourcePattern::forClusterResource(), ActionType::internal)) {
- return Status(ErrorCodes::Unauthorized, "Unauthorized");
- }
- return Status::OK();
- }
-
- std::string parseNs(const std::string& dbname, const BSONObj& cmdObj) const override {
- return cmdObj.firstElement().str();
- }
-
- bool run(OperationContext* opCtx,
- const std::string& dbname_unused,
- const BSONObj& cmdObj,
- BSONObjBuilder& result) override {
- uassert(ErrorCodes::IllegalOperation,
- "_configsvrDropDatabase can only be run on config servers",
- serverGlobalParams.clusterRole == ClusterRole::ConfigServer);
-
- // Set the operation context read concern level to local for reads into the config database.
- repl::ReadConcernArgs::get(opCtx) =
- repl::ReadConcernArgs(repl::ReadConcernLevel::kLocalReadConcern);
-
- const std::string dbname = parseNs("", cmdObj);
-
- uassert(
- ErrorCodes::InvalidNamespace,
- str::stream() << "invalid db name specified: " << dbname,
- NamespaceString::validDBName(dbname, NamespaceString::DollarInDbNameBehavior::Allow));
-
- uassert(ErrorCodes::InvalidOptions,
- str::stream() << "dropDatabase must be called with majority writeConcern, got "
- << cmdObj,
- opCtx->getWriteConcern().wMode == WriteConcernOptions::kMajority);
-
- FixedFCVRegion fcvRegion(opCtx);
-
- uassert(ErrorCodes::CommandNotSupported,
- "The _configsvrDropDatabase command is only supported under feature compatibility "
- "version 4.4",
- fcvRegion == FCVersion::kFullyDowngradedTo44);
-
- dropDatabaseLegacy(opCtx, dbname);
- repl::ReplClientInfo::forClient(opCtx->getClient()).setLastOpToSystemLastOpTime(opCtx);
- return true;
- }
-} configsvrDropDatabaseCmd;
-
-} // namespace
-} // namespace mongo
diff --git a/src/mongo/db/s/config/sharding_catalog_manager_drop_coll_test.cpp b/src/mongo/db/s/config/sharding_catalog_manager_drop_coll_test.cpp
deleted file mode 100644
index e3aef83547d..00000000000
--- a/src/mongo/db/s/config/sharding_catalog_manager_drop_coll_test.cpp
+++ /dev/null
@@ -1,558 +0,0 @@
-/**
- * Copyright (C) 2018-present MongoDB, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the Server Side Public License, version 1,
- * as published by MongoDB, Inc.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * Server Side Public License for more details.
- *
- * You should have received a copy of the Server Side Public License
- * along with this program. If not, see
- * <http://www.mongodb.com/licensing/server-side-public-license>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the Server Side Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kSharding
-
-#include "mongo/platform/basic.h"
-
-#include "mongo/client/remote_command_targeter_mock.h"
-#include "mongo/db/namespace_string.h"
-#include "mongo/db/s/config/config_server_test_fixture.h"
-#include "mongo/db/s/drop_collection_legacy.h"
-#include "mongo/rpc/metadata/tracking_metadata.h"
-#include "mongo/s/catalog/type_chunk.h"
-#include "mongo/s/catalog/type_collection.h"
-#include "mongo/s/catalog/type_database.h"
-#include "mongo/s/catalog/type_shard.h"
-#include "mongo/s/catalog/type_tags.h"
-#include "mongo/s/client/shard_registry.h"
-#include "mongo/util/scopeguard.h"
-
-namespace mongo {
-namespace {
-
-using executor::RemoteCommandRequest;
-using executor::RemoteCommandResponse;
-using unittest::assertGet;
-
-class DropColl2ShardTest : public ConfigServerTestFixture {
-public:
- void setUp() override {
- ConfigServerTestFixture::setUp();
-
- _shard1.setName("shard0001");
- _shard1.setHost("s:1");
-
- _shard2.setName("shard0002");
- _shard2.setHost("s:2");
-
- _zoneName = "zoneName";
- _shardKey = "x";
- _min = BSON(_shardKey << 0);
- _max = BSON(_shardKey << 10);
-
- setupShards({_shard1, _shard2});
-
- auto shard1Targeter = RemoteCommandTargeterMock::get(
- uassertStatusOK(shardRegistry()->getShard(operationContext(), _shard1.getName()))
- ->getTargeter());
- shard1Targeter->setFindHostReturnValue(HostAndPort(_shard1.getHost()));
-
- auto shard2Targeter = RemoteCommandTargeterMock::get(
- uassertStatusOK(shardRegistry()->getShard(operationContext(), _shard2.getName()))
- ->getTargeter());
- shard2Targeter->setFindHostReturnValue(HostAndPort(_shard2.getHost()));
-
- // Create the database, collection, chunks and zones in the config collection, so the test
- // starts with a properly created collection
- DatabaseType dbt(
- dropNS().db().toString(), _shard1.getName(), true, DatabaseVersion(UUID::gen()));
- ASSERT_OK(
- insertToConfigCollection(operationContext(), DatabaseType::ConfigNS, dbt.toBSON()));
-
- CollectionType shardedCollection(dropNS(), OID::gen(), Date_t::now(), UUID::gen());
- shardedCollection.setKeyPattern(BSON(_shardKey << 1));
- ASSERT_OK(insertToConfigCollection(
- operationContext(), CollectionType::ConfigNS, shardedCollection.toBSON()));
-
- BSONObjBuilder tagDocBuilder;
- tagDocBuilder.append("_id", BSON(TagsType::ns(dropNS().ns()) << TagsType::min(_min)));
- tagDocBuilder.append(TagsType::ns(), dropNS().ns());
- tagDocBuilder.append(TagsType::min(), _min);
- tagDocBuilder.append(TagsType::max(), _max);
- tagDocBuilder.append(TagsType::tag(), _zoneName);
- ASSERT_OK(
- insertToConfigCollection(operationContext(), TagsType::ConfigNS, tagDocBuilder.obj()));
-
- BSONObjBuilder chunkDocBuilder;
- chunkDocBuilder.append("ns", dropNS().ns());
- chunkDocBuilder.append("min", _min);
- chunkDocBuilder.append("max", _max);
- chunkDocBuilder.append("shard", _shard1.getName());
- ASSERT_OK(insertToConfigCollection(
- operationContext(), ChunkType::ConfigNS, chunkDocBuilder.obj()));
-
- // Initialize config.chunks secondary index
- getConfigShard()
- ->createIndexOnConfig(operationContext(),
- ChunkType::ConfigNS,
- BSON(ChunkType::ns() << 1 << ChunkType::min() << 1),
- /*unique*/ true)
- .transitional_ignore();
- }
-
- void expectStaleConfig(const ShardType& shard) {
- onCommand([this, shard](const RemoteCommandRequest& request) {
- BSONObjBuilder builder;
- builder.append("drop", _dropNS.coll());
- ChunkVersion::IGNORED().appendToCommand(&builder);
-
- ASSERT_EQ(HostAndPort(shard.getHost()), request.target);
- ASSERT_EQ(_dropNS.db(), request.dbname);
- ASSERT_BSONOBJ_EQ(builder.obj(), request.cmdObj);
-
- StaleConfigInfo sci(
- _dropNS, ChunkVersion::IGNORED(), boost::none, ShardId(shard.getName()));
- BSONObjBuilder responseBuilder;
- responseBuilder.append("ok", 0);
- responseBuilder.append("code", ErrorCodes::StaleShardVersion);
- sci.serialize(&responseBuilder);
- return responseBuilder.obj();
- });
- }
-
- void expectDrop(const ShardType& shard) {
- onCommand([this, shard](const RemoteCommandRequest& request) {
- BSONObjBuilder builder;
- builder.append("drop", _dropNS.coll());
- ChunkVersion::IGNORED().appendToCommand(&builder);
-
- ASSERT_EQ(HostAndPort(shard.getHost()), request.target);
- ASSERT_EQ(_dropNS.db(), request.dbname);
- ASSERT_BSONOBJ_EQ(builder.obj(), request.cmdObj);
-
- ASSERT_BSONOBJ_EQ(rpc::makeEmptyMetadata(),
- rpc::TrackingMetadata::removeTrackingData(request.metadata));
-
- return BSON("ns" << _dropNS.ns() << "ok" << 1);
- });
- }
-
- void expectSetShardVersionZero(const ShardType& shard) {
- expectSetShardVersion(
- HostAndPort(shard.getHost()), shard, dropNS(), ChunkVersion::UNSHARDED());
- }
-
- void expectNoCollectionDocs() {
- auto findStatus =
- findOneOnConfigCollection(operationContext(), CollectionType::ConfigNS, BSONObj());
- ASSERT_EQ(ErrorCodes::NoMatchingDocument, findStatus);
- }
-
- void expectNoChunkDocs() {
- auto findStatus =
- findOneOnConfigCollection(operationContext(), ChunkType::ConfigNS, BSONObj());
- ASSERT_EQ(ErrorCodes::NoMatchingDocument, findStatus);
- }
-
- void expectNoTagDocs() {
- auto findStatus =
- findOneOnConfigCollection(operationContext(), TagsType::ConfigNS, BSONObj());
- ASSERT_EQ(ErrorCodes::NoMatchingDocument, findStatus);
- }
-
- void shutdownExecutor() {
- ConfigServerTestFixture::executor()->shutdown();
- }
-
- void doDrop() {
- ThreadClient tc("Test", getServiceContext());
- auto opCtx = tc->makeOperationContext();
-
- FixedFCVRegion fcvRegion(opCtx.get());
- dropCollectionLegacy(opCtx.get(), dropNS(), fcvRegion);
- }
-
- const NamespaceString& dropNS() const {
- return _dropNS;
- }
-
- const ShardType& shard1() const {
- return _shard1;
- }
-
- const ShardType& shard2() const {
- return _shard2;
- }
-
-protected:
-private:
- const NamespaceString _dropNS{"test.user"};
- ShardType _shard1;
- ShardType _shard2;
- std::string _zoneName;
- std::string _shardKey;
- BSONObj _min;
- BSONObj _max;
-};
-
-TEST_F(DropColl2ShardTest, Basic) {
- auto future = launchAsync([this] { doDrop(); });
-
- expectDrop(shard1());
- expectDrop(shard2());
-
- expectSetShardVersionZero(shard1());
- expectSetShardVersionZero(shard2());
-
- future.default_timed_get();
-
- expectNoCollectionDocs();
- expectNoChunkDocs();
- expectNoTagDocs();
-}
-
-TEST_F(DropColl2ShardTest, NSNotFound) {
- auto future = launchAsync([this] { doDrop(); });
-
- onCommand([this](const RemoteCommandRequest& request) {
- BSONObjBuilder builder;
- builder.append("drop", dropNS().coll());
- ChunkVersion::IGNORED().appendToCommand(&builder);
-
- ASSERT_EQ(HostAndPort(shard1().getHost()), request.target);
- ASSERT_EQ(dropNS().db(), request.dbname);
- ASSERT_BSONOBJ_EQ(builder.obj(), request.cmdObj);
-
- ASSERT_BSONOBJ_EQ(rpc::makeEmptyMetadata(),
- rpc::TrackingMetadata::removeTrackingData(request.metadata));
-
- return BSON("ok" << 0 << "code" << ErrorCodes::NamespaceNotFound);
- });
-
- onCommand([this](const RemoteCommandRequest& request) {
- BSONObjBuilder builder;
- builder.append("drop", dropNS().coll());
- ChunkVersion::IGNORED().appendToCommand(&builder);
-
- ASSERT_EQ(HostAndPort(shard2().getHost()), request.target);
- ASSERT_EQ(dropNS().db(), request.dbname);
- ASSERT_BSONOBJ_EQ(builder.obj(), request.cmdObj);
-
- ASSERT_BSONOBJ_EQ(rpc::makeEmptyMetadata(),
- rpc::TrackingMetadata::removeTrackingData(request.metadata));
-
- return BSON("ok" << 0 << "code" << ErrorCodes::NamespaceNotFound);
- });
-
- expectSetShardVersionZero(shard1());
- expectSetShardVersionZero(shard2());
-
- future.default_timed_get();
-
- expectNoCollectionDocs();
- expectNoChunkDocs();
- expectNoTagDocs();
-}
-
-TEST_F(DropColl2ShardTest, FirstShardTargeterError) {
- auto shard1Targeter = RemoteCommandTargeterMock::get(
- uassertStatusOK(shardRegistry()->getShard(operationContext(), shard1().getName()))
- ->getTargeter());
- shard1Targeter->setFindHostReturnValue({ErrorCodes::HostUnreachable, "bad test network"});
-
- auto future = launchAsync(
- [this] { ASSERT_THROWS_CODE(doDrop(), AssertionException, ErrorCodes::HostUnreachable); });
-
- future.default_timed_get();
-}
-
-TEST_F(DropColl2ShardTest, FirstShardDropError) {
- auto future = launchAsync(
- [this] { ASSERT_THROWS_CODE(doDrop(), AssertionException, ErrorCodes::CallbackCanceled); });
-
- onCommand([this](const RemoteCommandRequest& request) {
- shutdownExecutor(); // shutdown executor so drop command will fail.
- return BSON("ok" << 1);
- });
-
- future.default_timed_get();
-}
-
-TEST_F(DropColl2ShardTest, SecondShardTargeterError) {
- auto shard2Targeter = RemoteCommandTargeterMock::get(
- uassertStatusOK(shardRegistry()->getShard(operationContext(), shard2().getName()))
- ->getTargeter());
- shard2Targeter->setFindHostReturnValue({ErrorCodes::HostUnreachable, "bad test network"});
-
- auto future = launchAsync(
- [this] { ASSERT_THROWS_CODE(doDrop(), AssertionException, ErrorCodes::HostUnreachable); });
-
- expectDrop(shard1());
-
- future.default_timed_get();
-}
-
-TEST_F(DropColl2ShardTest, SecondShardDropError) {
- auto future = launchAsync(
- [this] { ASSERT_THROWS_CODE(doDrop(), AssertionException, ErrorCodes::CallbackCanceled); });
-
- expectDrop(shard1());
-
- onCommand([this](const RemoteCommandRequest& request) {
- shutdownExecutor(); // shutdown executor so drop command will fail.
- return BSON("ok" << 1);
- });
-
- future.default_timed_get();
-}
-
-TEST_F(DropColl2ShardTest, SecondShardDropCmdError) {
- auto future = launchAsync(
- [this] { ASSERT_THROWS_CODE(doDrop(), AssertionException, ErrorCodes::Unauthorized); });
-
- expectDrop(shard1());
-
- onCommand([](const RemoteCommandRequest& request) {
- return BSON("ok" << 0 << "code" << ErrorCodes::Unauthorized);
- });
-
- future.default_timed_get();
-}
-
-TEST_F(DropColl2ShardTest, CleanupChunkError) {
- auto future = launchAsync(
- [this] { ASSERT_THROWS_CODE(doDrop(), AssertionException, ErrorCodes::Unauthorized); });
-
- expectDrop(shard1());
- expectDrop(shard2());
-
- onCommand([](const RemoteCommandRequest& request) {
- return BSON("ok" << 0 << "code" << ErrorCodes::Unauthorized << "errmsg"
- << "bad delete");
- });
-
- future.default_timed_get();
-
- expectNoCollectionDocs();
- expectNoChunkDocs();
- expectNoTagDocs();
-}
-
-TEST_F(DropColl2ShardTest, SSVCmdErrorOnShard1) {
- auto future = launchAsync(
- [this] { ASSERT_THROWS_CODE(doDrop(), AssertionException, ErrorCodes::Unauthorized); });
-
- expectDrop(shard1());
- expectDrop(shard2());
-
- onCommand([](const RemoteCommandRequest& request) {
- return BSON("ok" << 0 << "code" << ErrorCodes::Unauthorized << "errmsg"
- << "bad");
- });
-
- future.default_timed_get();
-
- expectNoCollectionDocs();
- expectNoChunkDocs();
- expectNoTagDocs();
-}
-
-TEST_F(DropColl2ShardTest, SSVErrorOnShard1) {
- auto future = launchAsync(
- [this] { ASSERT_THROWS_CODE(doDrop(), AssertionException, ErrorCodes::CallbackCanceled); });
-
- expectDrop(shard1());
- expectDrop(shard2());
-
- onCommand([this](const RemoteCommandRequest& request) {
- shutdownExecutor(); // shutdown executor so ssv command will fail.
- return BSON("ok" << 1);
- });
-
- future.default_timed_get();
-
- expectNoCollectionDocs();
- expectNoChunkDocs();
- expectNoTagDocs();
-}
-
-TEST_F(DropColl2ShardTest, SSVCmdErrorOnShard2) {
- auto future = launchAsync(
- [this] { ASSERT_THROWS_CODE(doDrop(), AssertionException, ErrorCodes::Unauthorized); });
-
- expectDrop(shard1());
- expectDrop(shard2());
-
- expectSetShardVersionZero(shard1());
-
- onCommand([](const RemoteCommandRequest& request) {
- return BSON("ok" << 0 << "code" << ErrorCodes::Unauthorized << "errmsg"
- << "bad");
- });
-
- future.default_timed_get();
-
- expectNoCollectionDocs();
- expectNoChunkDocs();
- expectNoTagDocs();
-}
-
-TEST_F(DropColl2ShardTest, SSVErrorOnShard2) {
- auto future = launchAsync(
- [this] { ASSERT_THROWS_CODE(doDrop(), AssertionException, ErrorCodes::CallbackCanceled); });
-
- expectDrop(shard1());
- expectDrop(shard2());
-
- expectSetShardVersionZero(shard1());
-
- onCommand([this](const RemoteCommandRequest& request) {
- shutdownExecutor(); // shutdown executor so ssv command will fail.
- return BSON("ok" << 1);
- });
-
- future.default_timed_get();
-
- expectNoCollectionDocs();
- expectNoChunkDocs();
- expectNoTagDocs();
-}
-
-/**
- * Tests of dropCollection retry behavior.
- */
-
-TEST_F(DropColl2ShardTest, AfterSuccessRetryWillStillSendDropSSV) {
- auto firstDropFuture = launchAsync([this] { doDrop(); });
-
- expectDrop(shard1());
- expectDrop(shard2());
-
- expectSetShardVersionZero(shard1());
- expectSetShardVersionZero(shard2());
-
- firstDropFuture.default_timed_get();
-
- expectNoCollectionDocs();
- expectNoChunkDocs();
- expectNoTagDocs();
-
- auto secondDropFuture = launchAsync([this] { doDrop(); });
-
- expectDrop(shard1());
- expectDrop(shard2());
-
- expectSetShardVersionZero(shard1());
- expectSetShardVersionZero(shard2());
-
- secondDropFuture.default_timed_get();
-
- expectNoCollectionDocs();
- expectNoChunkDocs();
- expectNoTagDocs();
-}
-
-TEST_F(DropColl2ShardTest, AfterFailedDropRetryWillStillSendDropSSV) {
- auto firstDropFuture = launchAsync(
- [this] { ASSERT_THROWS_CODE(doDrop(), AssertionException, ErrorCodes::Unauthorized); });
-
- onCommand([this](const RemoteCommandRequest& request) {
- return BSON("ok" << 0 << "code" << ErrorCodes::Unauthorized);
- });
-
- firstDropFuture.default_timed_get();
-
- auto secondDropFuture = launchAsync([this] { doDrop(); });
-
- expectDrop(shard1());
- expectDrop(shard2());
-
- expectSetShardVersionZero(shard1());
- expectSetShardVersionZero(shard2());
-
- secondDropFuture.default_timed_get();
-
- expectNoCollectionDocs();
- expectNoChunkDocs();
- expectNoTagDocs();
- expectNoTagDocs();
-}
-
-TEST_F(DropColl2ShardTest, AfterFailedSSVRetryWillStillSendDropSSV) {
- auto firstDropFuture = launchAsync(
- [this] { ASSERT_THROWS_CODE(doDrop(), AssertionException, ErrorCodes::Unauthorized); });
-
- expectDrop(shard1());
- expectDrop(shard2());
-
- onCommand([this](const RemoteCommandRequest& request) {
- return BSON("ok" << 0 << "code" << ErrorCodes::Unauthorized);
- });
-
- firstDropFuture.default_timed_get();
-
- auto secondDropFuture = launchAsync([this] { doDrop(); });
-
- expectDrop(shard1());
- expectDrop(shard2());
-
- expectSetShardVersionZero(shard1());
- expectSetShardVersionZero(shard2());
-
- secondDropFuture.default_timed_get();
-
- expectNoCollectionDocs();
- expectNoChunkDocs();
- expectNoTagDocs();
- expectNoTagDocs();
-}
-
-TEST_F(DropColl2ShardTest, SSVisRetried) {
- auto dropFuture = launchAsync([this] { doDrop(); });
-
- expectStaleConfig(shard1());
- expectDrop(shard1());
- expectDrop(shard2());
-
- expectSetShardVersionZero(shard1());
- expectSetShardVersionZero(shard2());
-
- dropFuture.default_timed_get();
-
- expectNoCollectionDocs();
- expectNoChunkDocs();
- expectNoTagDocs();
- expectNoTagDocs();
-}
-
-TEST_F(DropColl2ShardTest, maxSSVRetries) {
- auto dropFuture = launchAsync([this] {
- ASSERT_THROWS_CODE(doDrop(), AssertionException, ErrorCodes::StaleShardVersion);
- });
-
- for (int i = 0; i < 10; ++i) {
- expectStaleConfig(shard1());
- }
-
- dropFuture.default_timed_get();
-}
-
-} // unnamed namespace
-} // namespace mongo
diff --git a/src/mongo/db/s/drop_collection_legacy.cpp b/src/mongo/db/s/drop_collection_legacy.cpp
deleted file mode 100644
index e6573330da1..00000000000
--- a/src/mongo/db/s/drop_collection_legacy.cpp
+++ /dev/null
@@ -1,373 +0,0 @@
-/**
- * Copyright (C) 2021-present MongoDB, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the Server Side Public License, version 1,
- * as published by MongoDB, Inc.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * Server Side Public License for more details.
- *
- * You should have received a copy of the Server Side Public License
- * along with this program. If not, see
- * <http://www.mongodb.com/licensing/server-side-public-license>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the Server Side Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kSharding
-
-#include "mongo/platform/basic.h"
-
-#include "mongo/db/s/drop_collection_legacy.h"
-
-#include "mongo/db/s/database_sharding_state.h"
-#include "mongo/db/s/dist_lock_manager.h"
-#include "mongo/db/s/sharding_logging.h"
-#include "mongo/logv2/log.h"
-#include "mongo/s/catalog/type_database.h"
-#include "mongo/s/catalog/type_tags.h"
-#include "mongo/s/catalog_cache.h"
-#include "mongo/s/client/shard_registry.h"
-#include "mongo/s/grid.h"
-#include "mongo/s/request_types/set_shard_version_request.h"
-
-namespace mongo {
-namespace {
-
-static constexpr int kMaxNumStaleShardVersionRetries = 10;
-
-void sendDropCollectionToAllShards(OperationContext* opCtx,
- const NamespaceString& nss,
- const std::vector<ShardType>& allShards) {
- const auto dropCommandBSON = [opCtx, &nss] {
- BSONObjBuilder builder;
- builder.append("drop", nss.coll());
-
- if (!opCtx->getWriteConcern().usedDefaultConstructedWC) {
- builder.append(WriteConcernOptions::kWriteConcernField,
- opCtx->getWriteConcern().toBSON());
- }
-
- ChunkVersion::IGNORED().appendToCommand(&builder);
- return builder.obj();
- }();
-
- auto* const shardRegistry = Grid::get(opCtx)->shardRegistry();
-
- for (const auto& shardEntry : allShards) {
- bool keepTrying;
- size_t numStaleShardVersionAttempts = 0;
- do {
- const auto& shard =
- uassertStatusOK(shardRegistry->getShard(opCtx, shardEntry.getName()));
-
- auto swDropResult = shard->runCommandWithFixedRetryAttempts(
- opCtx,
- ReadPreferenceSetting{ReadPreference::PrimaryOnly},
- nss.db().toString(),
- dropCommandBSON,
- Shard::RetryPolicy::kIdempotent);
-
- const std::string dropCollectionErrMsg = str::stream()
- << "Error dropping collection on shard " << shardEntry.getName();
-
- auto dropResult = uassertStatusOKWithContext(swDropResult, dropCollectionErrMsg);
- uassertStatusOKWithContext(dropResult.writeConcernStatus, dropCollectionErrMsg);
-
- auto dropCommandStatus = std::move(dropResult.commandStatus);
-
- if (dropCommandStatus.code() == ErrorCodes::NamespaceNotFound) {
- // The dropCollection command on the shard is not idempotent, and can return
- // NamespaceNotFound. We can ignore NamespaceNotFound since we have already asserted
- // that there is no writeConcern error.
- keepTrying = false;
- } else if (ErrorCodes::isStaleShardVersionError(dropCommandStatus.code())) {
- numStaleShardVersionAttempts++;
- if (numStaleShardVersionAttempts == kMaxNumStaleShardVersionRetries) {
- uassertStatusOKWithContext(dropCommandStatus,
- str::stream() << dropCollectionErrMsg
- << " due to exceeded retry attempts");
- }
- // No need to refresh cache, the command was sent with ChunkVersion::IGNORED and the
- // shard is allowed to throw, which means that the drop will serialize behind a
- // refresh.
- keepTrying = true;
- } else {
- uassertStatusOKWithContext(dropCommandStatus, dropCollectionErrMsg);
- keepTrying = false;
- }
- } while (keepTrying);
- }
-}
-
-void sendSSVToAllShards(OperationContext* opCtx,
- const NamespaceString& nss,
- const std::vector<ShardType>& allShards) {
- auto* const shardRegistry = Grid::get(opCtx)->shardRegistry();
-
- IgnoreAPIParametersBlock ignoreApiParametersBlock(opCtx);
- for (const auto& shardEntry : allShards) {
- const auto& shard = uassertStatusOK(shardRegistry->getShard(opCtx, shardEntry.getName()));
-
- SetShardVersionRequest ssv(
- nss, ChunkVersion::UNSHARDED(), true /* isAuthoritative */, true /* forceRefresh */);
-
- auto ssvResult = shard->runCommandWithFixedRetryAttempts(
- opCtx,
- ReadPreferenceSetting{ReadPreference::PrimaryOnly},
- "admin",
- ssv.toBSON(),
- Shard::RetryPolicy::kIdempotent);
-
- uassertStatusOK(ssvResult.getStatus());
- uassertStatusOK(ssvResult.getValue().commandStatus);
- }
-}
-
-void removeChunksForDroppedCollection(OperationContext* opCtx,
- const NamespaceStringOrUUID& nssOrUUID) {
- IgnoreAPIParametersBlock ignoreApiParametersBlock(opCtx);
- const auto catalogClient = Grid::get(opCtx)->catalogClient();
-
- // Remove chunk data
- const auto chunksQuery = [&]() {
- if (nssOrUUID.uuid()) {
- return BSON(ChunkType::collectionUUID << *nssOrUUID.uuid());
- } else {
- return BSON(ChunkType::ns(nssOrUUID.nss()->ns()));
- }
- }();
-
- bool usingNssHint = true;
- while (true) {
- auto getHint = [&]() {
- return usingNssHint ? BSON(ChunkType::ns() << 1 << ChunkType::min() << 1)
- : BSON(ChunkType::collectionUUID() << 1 << ChunkType::min() << 1);
- };
-
- try {
- uassertStatusOK(
- // TODO SERVER-57221 don't use hint if not relevant anymore for delete performances
- catalogClient->removeConfigDocuments(opCtx,
- ChunkType::ConfigNS,
- chunksQuery,
- ShardingCatalogClient::kMajorityWriteConcern,
- getHint()));
-
- // Exit the loop just when all the chunks have been successfully removed.
- break;
- } catch (ExceptionFor<ErrorCodes::BadValue>& ex) {
- // The initially chosen indexes on `config.chunks` could not exist, catching the
- // exception to use the old/new one.
- LOGV2_INFO(5730700,
- "Index not found, switching index used for deleting chunks",
- "oldIndex"_attr = getHint(),
- "err"_attr = ex);
- usingNssHint = !usingNssHint;
- } catch (ExceptionFor<ErrorCodes::QueryPlanKilled>& ex) {
- // The indexes on `config.chunks` could change when yielding during upgrade/downgrade,
- // catching the exception to use the old/new one.
- LOGV2_INFO(5730701,
- "Index dropped, switching index for deleting chunks",
- "oldIndex"_attr = getHint(),
- "err"_attr = ex);
- usingNssHint = !usingNssHint;
- } catch (ExceptionFor<ErrorCodes::NetworkInterfaceExceededTimeLimit>&) {
- // The catalog client request could timeout before removing all the chunks: loop again
- // to delete the remaining documents.
- }
- }
-}
-
-void removeTagsForDroppedCollection(OperationContext* opCtx, const NamespaceString& nss) {
- IgnoreAPIParametersBlock ignoreApiParametersBlock(opCtx);
- const auto catalogClient = Grid::get(opCtx)->catalogClient();
-
- // Remove tag data
- uassertStatusOK(
- catalogClient->removeConfigDocuments(opCtx,
- TagsType::ConfigNS,
- BSON(TagsType::ns(nss.ns())),
- ShardingCatalogClient::kMajorityWriteConcern));
-}
-
-
-/**
- * Ensures that a namespace that has received a dropCollection, but no longer has an entry in
- * config.collections, has cleared all relevant metadata entries for the corresponding collection.
- * As part of this, sends dropCollection and setShardVersion to all shards -- in case shards didn't
- * receive these commands as part of the original dropCollection.
- *
- * This function does not guarantee that all shards will eventually receive setShardVersion, unless
- * the client infinitely retries until hearing back success. This function does, however, increase
- * the likelihood of shards having received setShardVersion.
- */
-void ensureDropCollectionCompleted(OperationContext* opCtx, const NamespaceString& nss) {
- const auto catalogClient = Grid::get(opCtx)->catalogClient();
- auto allShards = uassertStatusOK(catalogClient->getAllShards(
- opCtx, repl::ReadConcernLevel::kMajorityReadConcern))
- .value;
-
- LOGV2_DEBUG(21929,
- 1,
- "Ensuring config entries for {namespace} from previous dropCollection are cleared",
- "Ensuring config entries from previous dropCollection are cleared",
- "namespace"_attr = nss.ns());
-
- sendDropCollectionToAllShards(opCtx, nss, allShards);
-
- IgnoreAPIParametersBlock ignoreApiParametersBlock(opCtx);
- removeTagsForDroppedCollection(opCtx, nss);
- sendSSVToAllShards(opCtx, nss, allShards);
-}
-
-} // namespace
-
-void dropCollectionLegacy(OperationContext* opCtx,
- const NamespaceString& nss,
- const FixedFCVRegion& fcvRegion) {
- auto dbDistLock = uassertStatusOK(DistLockManager::get(opCtx)->lock(
- opCtx, nss.db(), "dropCollection", DistLockManager::kDefaultLockTimeout));
- auto collDistLock = uassertStatusOK(DistLockManager::get(opCtx)->lock(
- opCtx, nss.ns(), "dropCollection", DistLockManager::kDefaultLockTimeout));
-
- ON_BLOCK_EXIT([opCtx, nss] {
- Grid::get(opCtx)->catalogCache()->invalidateCollectionEntry_LINEARIZABLE(nss);
- });
-
- if (serverGlobalParams.clusterRole == ClusterRole::ShardServer && !nss.isConfigDB()) {
- DatabaseShardingState::checkIsPrimaryShardForDb(opCtx, nss.db());
- }
-
- auto const catalogClient = Grid::get(opCtx)->catalogClient();
-
- try {
- catalogClient->getCollection(opCtx, nss, repl::ReadConcernLevel::kMajorityReadConcern);
- dropCollectionNoDistLock(opCtx, nss);
- } catch (const ExceptionFor<ErrorCodes::NamespaceNotFound>&) {
- // If the DB isn't in the sharding catalog either, consider the drop a success.
- DatabaseType dbt;
- try {
- dbt = catalogClient->getDatabase(
- opCtx, nss.db().toString(), repl::ReadConcernLevel::kMajorityReadConcern);
- } catch (const ExceptionFor<ErrorCodes::NamespaceNotFound>&) {
- return;
- }
-
- // If we found the DB but not the collection, and the primary shard for the database is the
- // config server, run the drop only against the config server unless the collection is
- // config.system.sessions, since no other collections whose primary shard is the config
- // server can have been sharded.
- if (dbt.getPrimary() == ShardId::kConfigServerId &&
- nss != NamespaceString::kLogicalSessionsNamespace) {
- auto cmdDropResult =
- uassertStatusOK(Grid::get(opCtx)
- ->shardRegistry()
- ->getConfigShard()
- ->runCommandWithFixedRetryAttempts(
- opCtx,
- ReadPreferenceSetting{ReadPreference::PrimaryOnly},
- nss.db().toString(),
- BSON("drop" << nss.coll()),
- Shard::RetryPolicy::kIdempotent));
-
- // If the collection doesn't exist, consider the drop a success.
- if (cmdDropResult.commandStatus == ErrorCodes::NamespaceNotFound) {
- return;
- }
- uassertStatusOK(cmdDropResult.commandStatus);
- return;
- }
-
- ensureDropCollectionCompleted(opCtx, nss);
- }
-}
-
-void dropCollectionNoDistLock(OperationContext* opCtx, const NamespaceString& nss) {
- uassertStatusOK(ShardingLogging::get(opCtx)->logChangeChecked(
- opCtx,
- "dropCollection.start",
- nss.ns(),
- BSONObj(),
- ShardingCatalogClient::kMajorityWriteConcern));
-
- LOGV2_DEBUG(21924,
- 1,
- "dropCollection {namespace} started",
- "dropCollection started",
- "namespace"_attr = nss.ns());
-
- const auto catalogClient = Grid::get(opCtx)->catalogClient();
- auto allShards = uassertStatusOK(catalogClient->getAllShards(
- opCtx, repl::ReadConcernLevel::kMajorityReadConcern))
- .value;
- sendDropCollectionToAllShards(opCtx, nss, allShards);
-
- LOGV2_DEBUG(21925,
- 1,
- "dropCollection {namespace} shard data deleted",
- "dropCollection shard data deleted",
- "namespace"_attr = nss.ns());
-
- try {
- auto collType = catalogClient->getCollection(opCtx, nss);
- const auto nssOrUUID = [&] {
- if (collType.getTimestamp()) {
- return NamespaceStringOrUUID(collType.getNss().db().toString(), collType.getUuid());
- } else {
- return NamespaceStringOrUUID(collType.getNss());
- }
- }();
-
- removeChunksForDroppedCollection(opCtx, nssOrUUID);
- removeTagsForDroppedCollection(opCtx, nss);
-
- LOGV2_DEBUG(21926,
- 1,
- "dropCollection {namespace} chunk and tag data deleted",
- "dropCollection chunk and tag data deleted",
- "namespace"_attr = nss.ns());
-
- uassertStatusOK(
- catalogClient->removeConfigDocuments(opCtx,
- CollectionType::ConfigNS,
- BSON(CollectionType::kNssFieldName << nss.ns()),
- ShardingCatalogClient::kMajorityWriteConcern));
- LOGV2_DEBUG(21927,
- 1,
- "dropCollection {namespace} collection entry deleted",
- "dropCollection collection entry deleted",
- "namespace"_attr = nss.ns());
- } catch (const ExceptionFor<ErrorCodes::NamespaceNotFound>&) {
- LOGV2(5310500,
- "dropCollection {namespace} collection entry not found",
- "dropCollection {namespace} collection entry not found",
- "namespace"_attr = nss.ns());
- }
-
- sendSSVToAllShards(opCtx, nss, allShards);
-
- LOGV2_DEBUG(21928,
- 1,
- "dropCollection {namespace} completed",
- "dropCollection completed",
- "namespace"_attr = nss.ns());
-
- ShardingLogging::get(opCtx)->logChange(
- opCtx, "dropCollection", nss.ns(), BSONObj(), ShardingCatalogClient::kMajorityWriteConcern);
-}
-
-} // namespace mongo
diff --git a/src/mongo/db/s/drop_collection_legacy.h b/src/mongo/db/s/drop_collection_legacy.h
deleted file mode 100644
index 2deef3deb33..00000000000
--- a/src/mongo/db/s/drop_collection_legacy.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * Copyright (C) 2021-present MongoDB, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the Server Side Public License, version 1,
- * as published by MongoDB, Inc.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * Server Side Public License for more details.
- *
- * You should have received a copy of the Server Side Public License
- * along with this program. If not, see
- * <http://www.mongodb.com/licensing/server-side-public-license>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the Server Side Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#pragma once
-
-#include "mongo/db/commands/feature_compatibility_version.h"
-#include "mongo/db/namespace_string.h"
-#include "mongo/db/operation_context.h"
-
-namespace mongo {
-
-void dropCollectionLegacy(OperationContext* opCtx,
- const NamespaceString& nss,
- const FixedFCVRegion& fcvRegion);
-
-/**
- * Contains the underlying logic for drop collection, assuming that the caller calls it in isolation
- * from other DDLs through the means of the DistLock.
- *
- * Throws a DBException for any failures. These are some of the known failures:
- * - NamespaceNotFound - Collection does not exist
- */
-void dropCollectionNoDistLock(OperationContext* opCtx, const NamespaceString& nss);
-
-} // namespace mongo
diff --git a/src/mongo/db/s/drop_database_legacy.cpp b/src/mongo/db/s/drop_database_legacy.cpp
deleted file mode 100644
index c6b9fa7e444..00000000000
--- a/src/mongo/db/s/drop_database_legacy.cpp
+++ /dev/null
@@ -1,140 +0,0 @@
-/**
- * Copyright (C) 2021-present MongoDB, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the Server Side Public License, version 1,
- * as published by MongoDB, Inc.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * Server Side Public License for more details.
- *
- * You should have received a copy of the Server Side Public License
- * along with this program. If not, see
- * <http://www.mongodb.com/licensing/server-side-public-license>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the Server Side Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kSharding
-
-#include "mongo/platform/basic.h"
-
-#include "mongo/db/s/drop_database_legacy.h"
-
-#include "mongo/db/s/config/sharding_catalog_manager.h"
-#include "mongo/db/s/database_sharding_state.h"
-#include "mongo/db/s/dist_lock_manager.h"
-#include "mongo/db/s/drop_collection_legacy.h"
-#include "mongo/db/s/sharding_logging.h"
-#include "mongo/s/grid.h"
-
-namespace mongo {
-namespace {
-
-void dropDatabaseFromShard(OperationContext* opCtx, const ShardId& shardId, StringData dbName) {
- const auto dropDatabaseCommandBSON = [opCtx] {
- BSONObjBuilder builder;
- builder.append("dropDatabase", 1);
- builder.append(WriteConcernOptions::kWriteConcernField, opCtx->getWriteConcern().toBSON());
- return builder.obj();
- }();
-
- const auto shard = uassertStatusOK(Grid::get(opCtx)->shardRegistry()->getShard(opCtx, shardId));
- auto cmdDropDatabaseResult = uassertStatusOK(
- shard->runCommandWithFixedRetryAttempts(opCtx,
- ReadPreferenceSetting{ReadPreference::PrimaryOnly},
- dbName.toString(),
- dropDatabaseCommandBSON,
- Shard::RetryPolicy::kIdempotent));
-
- uassertStatusOK(cmdDropDatabaseResult.commandStatus);
- uassertStatusOK(cmdDropDatabaseResult.writeConcernStatus);
-}
-
-} // namespace
-
-void dropDatabaseLegacy(OperationContext* opCtx, StringData dbName) {
- auto dbDistLock = uassertStatusOK(DistLockManager::get(opCtx)->lock(
- opCtx, dbName, "dropDatabase", DistLockManager::kDefaultLockTimeout));
-
- ON_BLOCK_EXIT([&] { Grid::get(opCtx)->catalogCache()->purgeDatabase(dbName); });
-
- if (serverGlobalParams.clusterRole == ClusterRole::ShardServer &&
- dbName != NamespaceString::kConfigDb) {
- DatabaseShardingState::checkIsPrimaryShardForDb(opCtx, dbName);
- }
-
- auto const catalogClient = Grid::get(opCtx)->catalogClient();
-
- DatabaseType dbType;
- try {
- dbType =
- catalogClient->getDatabase(opCtx, dbName, repl::ReadConcernLevel::kMajorityReadConcern);
- } catch (const ExceptionFor<ErrorCodes::NamespaceNotFound>&) {
- return;
- }
-
- uassertStatusOK(ShardingLogging::get(opCtx)->logChangeChecked(
- opCtx,
- "dropDatabase.start",
- dbName,
- BSONObj(),
- ShardingCatalogClient::kMajorityWriteConcern));
-
- // Drop the database's collections.
- for (const auto& nss : catalogClient->getAllShardedCollectionsForDb(
- opCtx, dbName, repl::ReadConcernLevel::kMajorityReadConcern)) {
- auto collDistLock = uassertStatusOK(DistLockManager::get(opCtx)->lock(
- opCtx, nss.ns(), "dropCollection", DistLockManager::kDefaultLockTimeout));
- dropCollectionNoDistLock(opCtx, nss);
- }
-
- // Drop the database from the primary shard first.
- dropDatabaseFromShard(opCtx, dbType.getPrimary(), dbName);
-
- // Drop the database from each of the remaining shards.
- const auto allShardIds = Grid::get(opCtx)->shardRegistry()->getAllShardIdsNoReload();
- for (const ShardId& shardId : allShardIds) {
- dropDatabaseFromShard(opCtx, shardId, dbName);
- }
-
- // Remove the database entry from the metadata.
- const Status status =
- catalogClient->removeConfigDocuments(opCtx,
- DatabaseType::ConfigNS,
- BSON(DatabaseType::name(dbName.toString())),
- ShardingCatalogClient::kMajorityWriteConcern);
- uassertStatusOKWithContext(
- status, str::stream() << "Could not remove database '" << dbName << "' from metadata");
-
- // Send _flushDatabaseCacheUpdates to all shards
- IgnoreAPIParametersBlock ignoreApiParametersBlock{opCtx};
- for (const ShardId& shardId : allShardIds) {
- const auto shard =
- uassertStatusOK(Grid::get(opCtx)->shardRegistry()->getShard(opCtx, shardId));
- auto cmdResponse = uassertStatusOK(shard->runCommandWithFixedRetryAttempts(
- opCtx,
- ReadPreferenceSetting{ReadPreference::PrimaryOnly},
- "admin",
- BSON("_flushDatabaseCacheUpdates" << dbName),
- Shard::RetryPolicy::kIdempotent));
- uassertStatusOK(cmdResponse.commandStatus);
- }
-
- ShardingLogging::get(opCtx)->logChange(
- opCtx, "dropDatabase", dbName, BSONObj(), ShardingCatalogClient::kMajorityWriteConcern);
-}
-
-} // namespace mongo
diff --git a/src/mongo/db/s/drop_database_legacy.h b/src/mongo/db/s/drop_database_legacy.h
deleted file mode 100644
index 78f0b4d0751..00000000000
--- a/src/mongo/db/s/drop_database_legacy.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
- * Copyright (C) 2021-present MongoDB, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the Server Side Public License, version 1,
- * as published by MongoDB, Inc.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * Server Side Public License for more details.
- *
- * You should have received a copy of the Server Side Public License
- * along with this program. If not, see
- * <http://www.mongodb.com/licensing/server-side-public-license>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the Server Side Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#pragma once
-
-#include "mongo/db/namespace_string.h"
-#include "mongo/db/operation_context.h"
-#include "mongo/s/request_types/sharded_ddl_commands_gen.h"
-
-namespace mongo {
-
-void dropDatabaseLegacy(OperationContext* opCtx, StringData dbName);
-
-} // namespace mongo
diff --git a/src/mongo/db/s/shardsvr_drop_collection_command.cpp b/src/mongo/db/s/shardsvr_drop_collection_command.cpp
index e7d3bcac1b9..dd0c414b884 100644
--- a/src/mongo/db/s/shardsvr_drop_collection_command.cpp
+++ b/src/mongo/db/s/shardsvr_drop_collection_command.cpp
@@ -29,15 +29,10 @@
#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kSharding
-#include "mongo/platform/basic.h"
-
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/commands.h"
#include "mongo/db/curop.h"
#include "mongo/db/s/drop_collection_coordinator.h"
-#include "mongo/db/s/drop_collection_legacy.h"
-#include "mongo/db/s/sharding_ddl_50_upgrade_downgrade.h"
-#include "mongo/db/s/sharding_ddl_coordinator_service.h"
#include "mongo/db/s/sharding_state.h"
#include "mongo/logv2/log.h"
#include "mongo/s/catalog/sharding_catalog_client.h"
@@ -89,21 +84,6 @@ public:
// The collection is not sharded or doesn't exist.
}
- FixedFCVRegion fcvRegion(opCtx);
-
- bool useNewPath = feature_flags::gShardingFullDDLSupport.isEnabled(*fcvRegion);
- if (!useNewPath) {
- LOGV2_DEBUG(5280951,
- 1,
- "Running legacy drop collection procedure",
- "namespace"_attr = ns());
- dropCollectionLegacy(opCtx, ns(), fcvRegion);
- return;
- }
-
- LOGV2_DEBUG(
- 5280952, 1, "Running new drop collection procedure", "namespace"_attr = ns());
-
// Since this operation is not directly writing locally we need to force its db
// profile level increase in order to be logged in "<db>.system.profile"
CurOp::get(opCtx)->raiseDbProfileLevel(
diff --git a/src/mongo/db/s/shardsvr_drop_database_command.cpp b/src/mongo/db/s/shardsvr_drop_database_command.cpp
index 58237654643..85f070929be 100644
--- a/src/mongo/db/s/shardsvr_drop_database_command.cpp
+++ b/src/mongo/db/s/shardsvr_drop_database_command.cpp
@@ -29,15 +29,11 @@
#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kSharding
-#include "mongo/platform/basic.h"
-
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/catalog/collection_catalog.h"
#include "mongo/db/commands.h"
#include "mongo/db/curop.h"
#include "mongo/db/s/drop_database_coordinator.h"
-#include "mongo/db/s/drop_database_legacy.h"
-#include "mongo/db/s/sharding_ddl_50_upgrade_downgrade.h"
#include "mongo/db/s/sharding_ddl_coordinator_service.h"
#include "mongo/db/s/sharding_state.h"
#include "mongo/logv2/log.h"
@@ -79,26 +75,10 @@ public:
opCtx->setAlwaysInterruptAtStepDownOrUp();
- const auto dbName = request().getDbName();
-
- FixedFCVRegion fixedFCVRegion(opCtx);
-
- const auto useNewPath =
- feature_flags::gShardingFullDDLSupport.isEnabled(*fixedFCVRegion);
-
- if (!useNewPath) {
- LOGV2_DEBUG(
- 5281110, 1, "Running legacy drop database procedure", "db"_attr = dbName);
- dropDatabaseLegacy(opCtx, dbName);
- return;
- }
-
- LOGV2_DEBUG(5281111, 1, "Running new drop database procedure", "db"_attr = dbName);
-
// Since this operation is not directly writing locally we need to force its db
// profile level increase in order to be logged in "<db>.system.profile"
CurOp::get(opCtx)->raiseDbProfileLevel(
- CollectionCatalog::get(opCtx)->getDatabaseProfileLevel(dbName));
+ CollectionCatalog::get(opCtx)->getDatabaseProfileLevel(request().getDbName()));
auto coordinatorDoc = DropDatabaseCoordinatorDocument();
coordinatorDoc.setShardingDDLCoordinatorMetadata(