SERVER-115575 Keep declaration and implementation of the dropDatabase, dropCommand and createIndexes commands in the shard_role/ddl directory (#45498)
GitOrigin-RevId: 8ef497d957f8ffe27aff036897e18b11382c3e87
This commit is contained in:
parent
5d4d6a1d1b
commit
4a98ad8cdc
3
.github/CODEOWNERS
vendored
3
.github/CODEOWNERS
vendored
@ -1943,7 +1943,6 @@ WORKSPACE.bazel @10gen/devprod-build @svc-auto-approve-bot
|
||||
/src/mongo/db/commands/**/buildinfo_common.* @10gen/server-programmability @svc-auto-approve-bot
|
||||
/src/mongo/db/commands/**/connection_status.* @10gen/server-security @svc-auto-approve-bot
|
||||
/src/mongo/db/commands/**/cpuload.* @10gen/server-programmability @svc-auto-approve-bot
|
||||
/src/mongo/db/commands/**/create_indexes* @10gen/server-index-builds @svc-auto-approve-bot
|
||||
/src/mongo/db/commands/**/db_command_test_fixture.* @10gen/server-programmability @svc-auto-approve-bot
|
||||
/src/mongo/db/commands/**/fail_point_cmd.* @10gen/server-programmability @svc-auto-approve-bot
|
||||
/src/mongo/db/commands/**/fsync* @10gen/server-storage-engine-integration @svc-auto-approve-bot
|
||||
@ -2841,6 +2840,8 @@ WORKSPACE.bazel @10gen/devprod-build @svc-auto-approve-bot
|
||||
|
||||
# The following patterns are parsed from ./src/mongo/db/shard_role/ddl/OWNERS.yml
|
||||
/src/mongo/db/shard_role/ddl/**/* @10gen/server-catalog-and-routing-ddl @10gen/server-catalog-and-routing-shard-catalog @svc-auto-approve-bot
|
||||
/src/mongo/db/shard_role/ddl/**/create_indexes* @10gen/server-catalog-and-routing-ddl @10gen/server-catalog-and-routing-shard-catalog @10gen/server-index-builds @svc-auto-approve-bot
|
||||
/src/mongo/db/shard_role/ddl/**/drop_indexes* @10gen/server-catalog-and-routing-ddl @10gen/server-catalog-and-routing-shard-catalog @10gen/server-index-builds @svc-auto-approve-bot
|
||||
|
||||
# The following patterns are parsed from ./src/mongo/db/shard_role/lock_manager/OWNERS.yml
|
||||
/src/mongo/db/shard_role/lock_manager/**/* @10gen/server-catalog-and-routing-shard-catalog @svc-auto-approve-bot
|
||||
|
||||
@ -793,7 +793,6 @@ index_builds: # authoritative: @10gen/server-index-builds
|
||||
- src/mongo/db/index/index_access_method*
|
||||
- src/mongo/db/index_key_validate*
|
||||
- src/mongo/db/index_spec_validate*
|
||||
- src/mongo/db/commands/create_indexes*
|
||||
- src/mongo/db/commands/set_index_commit_quorum*
|
||||
- src/mongo/db/commands/vote*index_build*
|
||||
- src/mongo/dbtests/indexupdatetests.cpp
|
||||
|
||||
@ -815,7 +815,6 @@ mongo_cc_library(
|
||||
mongo_cc_library(
|
||||
name = "standalone",
|
||||
srcs = [
|
||||
"create_indexes_cmd.cpp",
|
||||
"dbcommands.cpp",
|
||||
"fle2_get_count_info_command.cpp",
|
||||
"http_client.cpp",
|
||||
@ -845,6 +844,9 @@ mongo_cc_library(
|
||||
"//src/mongo/db/global_catalog/ddl:shuffle_list_command_results.cpp",
|
||||
"//src/mongo/db/shard_role/ddl:collmod_cmd.cpp",
|
||||
"//src/mongo/db/shard_role/ddl:create_command.cpp",
|
||||
"//src/mongo/db/shard_role/ddl:create_indexes_cmd.cpp",
|
||||
"//src/mongo/db/shard_role/ddl:drop_collection_cmd.cpp",
|
||||
"//src/mongo/db/shard_role/ddl:drop_database_cmd.cpp",
|
||||
"//src/mongo/db/shard_role/ddl:drop_indexes_cmd.cpp",
|
||||
"//src/mongo/db/shard_role/ddl:list_collections.cpp",
|
||||
"//src/mongo/db/shard_role/ddl:list_databases.cpp",
|
||||
@ -1178,22 +1180,6 @@ mongo_cc_unit_test(
|
||||
],
|
||||
)
|
||||
|
||||
mongo_cc_unit_test(
|
||||
name = "create_indexes_command_test",
|
||||
srcs = [
|
||||
"create_indexes_test.cpp",
|
||||
],
|
||||
tags = [
|
||||
"mongo_unittest_fifth_group",
|
||||
"server-index-builds",
|
||||
],
|
||||
deps = [
|
||||
"//src/mongo/db:dbdirectclient",
|
||||
"//src/mongo/db/repl:storage_interface_impl",
|
||||
"//src/mongo/db/shard_role/shard_catalog:catalog_test_fixture",
|
||||
],
|
||||
)
|
||||
|
||||
mongo_cc_unit_test(
|
||||
name = "dbcheck_and_compact_test",
|
||||
srcs = [
|
||||
|
||||
@ -15,9 +15,6 @@ filters:
|
||||
- "cpuload.*":
|
||||
approvers:
|
||||
- 10gen/server-programmability
|
||||
- "create_indexes*":
|
||||
approvers:
|
||||
- 10gen/server-index-builds
|
||||
- "db_command_test_fixture.*":
|
||||
approvers:
|
||||
- 10gen/server-programmability
|
||||
|
||||
@ -120,145 +120,6 @@ namespace {
|
||||
// Will cause 'CmdDatasize' to hang as it starts executing.
|
||||
MONGO_FAIL_POINT_DEFINE(hangBeforeDatasizeCount);
|
||||
|
||||
class CmdDropDatabase : public DropDatabaseCmdVersion1Gen<CmdDropDatabase> {
|
||||
public:
|
||||
std::string help() const final {
|
||||
return "drop (delete) this database";
|
||||
}
|
||||
AllowedOnSecondary secondaryAllowed(ServiceContext*) const final {
|
||||
return AllowedOnSecondary::kNever;
|
||||
}
|
||||
bool collectsResourceConsumptionMetrics() const final {
|
||||
return true;
|
||||
}
|
||||
bool allowedWithSecurityToken() const final {
|
||||
return true;
|
||||
}
|
||||
class Invocation final : public InvocationBaseGen {
|
||||
public:
|
||||
using InvocationBaseGen::InvocationBaseGen;
|
||||
bool supportsWriteConcern() const final {
|
||||
return true;
|
||||
}
|
||||
NamespaceString ns() const final {
|
||||
return NamespaceString(request().getDbName());
|
||||
}
|
||||
void doCheckAuthorization(OperationContext* opCtx) const final {
|
||||
uassert(ErrorCodes::Unauthorized,
|
||||
str::stream() << "Not authorized to drop database '"
|
||||
<< request().getDbName().toStringForErrorMsg() << "'",
|
||||
AuthorizationSession::get(opCtx->getClient())
|
||||
->isAuthorizedForActionsOnNamespace(ns(), ActionType::dropDatabase));
|
||||
}
|
||||
Reply typedRun(OperationContext* opCtx) final {
|
||||
ReplicaSetDDLTracker::ScopedReplicaSetDDL scopedReplicaSetDDL(
|
||||
opCtx, std::vector<NamespaceString>{ns()});
|
||||
|
||||
auto dbName = request().getDbName();
|
||||
// disallow dropping the config database
|
||||
if (serverGlobalParams.clusterRole.has(ClusterRole::ConfigServer) &&
|
||||
(dbName == DatabaseName::kConfig)) {
|
||||
uasserted(ErrorCodes::IllegalOperation,
|
||||
"Cannot drop 'config' database if mongod started "
|
||||
"with --configsvr");
|
||||
}
|
||||
|
||||
if ((repl::ReplicationCoordinator::get(opCtx)->getSettings().isReplSet()) &&
|
||||
(dbName == DatabaseName::kLocal)) {
|
||||
uasserted(ErrorCodes::IllegalOperation,
|
||||
str::stream() << "Cannot drop '" << dbName.toStringForErrorMsg()
|
||||
<< "' database while replication is active");
|
||||
}
|
||||
|
||||
if (request().getCommandParameter() != 1) {
|
||||
uasserted(5255100, "Have to pass 1 as 'drop' parameter");
|
||||
}
|
||||
|
||||
Status status = dropDatabase(opCtx, dbName);
|
||||
if (status != ErrorCodes::NamespaceNotFound) {
|
||||
uassertStatusOK(status);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
};
|
||||
};
|
||||
MONGO_REGISTER_COMMAND(CmdDropDatabase).forShard();
|
||||
|
||||
/* drop collection */
|
||||
class CmdDrop : public DropCmdVersion1Gen<CmdDrop> {
|
||||
public:
|
||||
AllowedOnSecondary secondaryAllowed(ServiceContext*) const final {
|
||||
return AllowedOnSecondary::kNever;
|
||||
}
|
||||
bool adminOnly() const final {
|
||||
return false;
|
||||
}
|
||||
std::string help() const final {
|
||||
return "drop a collection\n{drop : <collectionName>}";
|
||||
}
|
||||
bool collectsResourceConsumptionMetrics() const final {
|
||||
return true;
|
||||
}
|
||||
bool allowedWithSecurityToken() const final {
|
||||
return true;
|
||||
}
|
||||
|
||||
class Invocation final : public InvocationBaseGen {
|
||||
public:
|
||||
using InvocationBaseGen::InvocationBaseGen;
|
||||
bool supportsWriteConcern() const final {
|
||||
return true;
|
||||
}
|
||||
NamespaceString ns() const final {
|
||||
return request().getNamespace();
|
||||
}
|
||||
|
||||
bool isSubjectToIngressAdmissionControl() const override {
|
||||
return true;
|
||||
}
|
||||
|
||||
void doCheckAuthorization(OperationContext* opCtx) const final {
|
||||
auto ns = request().getNamespace();
|
||||
uassert(ErrorCodes::Unauthorized,
|
||||
str::stream() << "Not authorized to drop collection '"
|
||||
<< ns.toStringForErrorMsg() << "'",
|
||||
AuthorizationSession::get(opCtx->getClient())
|
||||
->isAuthorizedForActionsOnNamespace(ns, ActionType::dropCollection));
|
||||
}
|
||||
Reply typedRun(OperationContext* opCtx) final {
|
||||
ReplicaSetDDLTracker::ScopedReplicaSetDDL scopedReplicaSetDDL(
|
||||
opCtx, std::vector<NamespaceString>{ns()});
|
||||
|
||||
if (request().getNamespace().isOplog()) {
|
||||
uassert(5255000,
|
||||
"can't drop live oplog while replicating",
|
||||
!repl::ReplicationCoordinator::get(opCtx)->getSettings().isReplSet());
|
||||
auto storageEngine = opCtx->getServiceContext()->getStorageEngine();
|
||||
invariant(storageEngine);
|
||||
// We use the method supportsRecoveryTimestamp() to detect whether we are using
|
||||
// the WiredTiger storage engine, which is currently only storage engine that
|
||||
// supports the replSetResizeOplog command.
|
||||
uassert(
|
||||
5255001,
|
||||
"can't drop oplog on storage engines that support replSetResizeOplog command",
|
||||
!storageEngine->supportsRecoveryTimestamp());
|
||||
}
|
||||
|
||||
// We need to copy the serialization context from the request to the reply object
|
||||
Reply reply(
|
||||
SerializationContext::stateCommandReply(request().getSerializationContext()));
|
||||
uassertStatusOK(
|
||||
dropCollection(opCtx,
|
||||
request().getNamespace(),
|
||||
request().getCollectionUUID(),
|
||||
&reply,
|
||||
DropCollectionSystemCollectionMode::kDisallowSystemCollectionDrops));
|
||||
return reply;
|
||||
}
|
||||
};
|
||||
};
|
||||
MONGO_REGISTER_COMMAND(CmdDrop).forShard();
|
||||
|
||||
class CmdDataSize final : public TypedCommand<CmdDataSize> {
|
||||
public:
|
||||
using Request = DataSizeCommand;
|
||||
|
||||
@ -40,6 +40,7 @@ server_parameters:
|
||||
default: true
|
||||
test_only: true
|
||||
redact: false
|
||||
mod_visibility: needs_replacement
|
||||
|
||||
maxNumActiveUserIndexBuilds:
|
||||
description: >
|
||||
|
||||
@ -187,6 +187,17 @@ mongo_cc_library(
|
||||
],
|
||||
)
|
||||
|
||||
mongo_cc_unit_test(
|
||||
name = "create_indexes_command_test",
|
||||
srcs = [
|
||||
"create_indexes_test.cpp",
|
||||
],
|
||||
tags = ["mongo_unittest_second_group"],
|
||||
deps = [
|
||||
"//src/mongo/db/shard_role/shard_catalog:catalog_test_fixture",
|
||||
],
|
||||
)
|
||||
|
||||
mongo_cc_unit_test(
|
||||
name = "direct_connection_ddl_hook_test",
|
||||
srcs = [
|
||||
|
||||
@ -4,3 +4,13 @@ filters:
|
||||
approvers:
|
||||
- 10gen/server-catalog-and-routing-shard-catalog
|
||||
- 10gen/server-catalog-and-routing-ddl
|
||||
- "create_indexes*":
|
||||
approvers:
|
||||
- 10gen/server-catalog-and-routing-shard-catalog
|
||||
- 10gen/server-catalog-and-routing-ddl
|
||||
- 10gen/server-index-builds
|
||||
- "drop_indexes*":
|
||||
approvers:
|
||||
- 10gen/server-catalog-and-routing-shard-catalog
|
||||
- 10gen/server-catalog-and-routing-ddl
|
||||
- 10gen/server-index-builds
|
||||
|
||||
142
src/mongo/db/shard_role/ddl/drop_collection_cmd.cpp
Normal file
142
src/mongo/db/shard_role/ddl/drop_collection_cmd.cpp
Normal file
@ -0,0 +1,142 @@
|
||||
/**
|
||||
* Copyright (C) 2025-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.
|
||||
*/
|
||||
|
||||
#include "mongo/base/error_codes.h"
|
||||
#include "mongo/db/admission/execution_control/execution_admission_context.h"
|
||||
#include "mongo/db/auth/action_type.h"
|
||||
#include "mongo/db/auth/authorization_session.h"
|
||||
#include "mongo/db/client.h"
|
||||
#include "mongo/db/commands.h"
|
||||
#include "mongo/db/curop.h"
|
||||
#include "mongo/db/namespace_string.h"
|
||||
#include "mongo/db/operation_context.h"
|
||||
#include "mongo/db/profile_settings.h"
|
||||
#include "mongo/db/query/internal_plans.h"
|
||||
#include "mongo/db/repl/replication_coordinator.h"
|
||||
#include "mongo/db/service_context.h"
|
||||
#include "mongo/db/shard_role/ddl/coll_mod_gen.h"
|
||||
#include "mongo/db/shard_role/ddl/drop_database_gen.h"
|
||||
#include "mongo/db/shard_role/ddl/drop_gen.h"
|
||||
#include "mongo/db/shard_role/ddl/replica_set_ddl_tracker.h"
|
||||
#include "mongo/db/shard_role/shard_catalog/drop_collection.h"
|
||||
#include "mongo/db/shard_role/shard_catalog/drop_database.h"
|
||||
#include "mongo/db/storage/record_store.h"
|
||||
#include "mongo/db/storage/storage_engine.h"
|
||||
#include "mongo/util/assert_util.h"
|
||||
#include "mongo/util/serialization_context.h"
|
||||
#include "mongo/util/str.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <boost/move/utility_core.hpp>
|
||||
#include <boost/none.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/optional/optional.hpp>
|
||||
|
||||
#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kCommand
|
||||
|
||||
namespace mongo {
|
||||
namespace {
|
||||
|
||||
class CmdDrop : public DropCmdVersion1Gen<CmdDrop> {
|
||||
public:
|
||||
AllowedOnSecondary secondaryAllowed(ServiceContext*) const final {
|
||||
return AllowedOnSecondary::kNever;
|
||||
}
|
||||
bool adminOnly() const final {
|
||||
return false;
|
||||
}
|
||||
std::string help() const final {
|
||||
return "drop a collection\n{drop : <collectionName>}";
|
||||
}
|
||||
bool collectsResourceConsumptionMetrics() const final {
|
||||
return true;
|
||||
}
|
||||
bool allowedWithSecurityToken() const final {
|
||||
return true;
|
||||
}
|
||||
|
||||
class Invocation final : public InvocationBaseGen {
|
||||
public:
|
||||
using InvocationBaseGen::InvocationBaseGen;
|
||||
bool supportsWriteConcern() const final {
|
||||
return true;
|
||||
}
|
||||
NamespaceString ns() const final {
|
||||
return request().getNamespace();
|
||||
}
|
||||
|
||||
bool isSubjectToIngressAdmissionControl() const override {
|
||||
return true;
|
||||
}
|
||||
|
||||
void doCheckAuthorization(OperationContext* opCtx) const final {
|
||||
auto ns = request().getNamespace();
|
||||
uassert(ErrorCodes::Unauthorized,
|
||||
str::stream() << "Not authorized to drop collection '"
|
||||
<< ns.toStringForErrorMsg() << "'",
|
||||
AuthorizationSession::get(opCtx->getClient())
|
||||
->isAuthorizedForActionsOnNamespace(ns, ActionType::dropCollection));
|
||||
}
|
||||
Reply typedRun(OperationContext* opCtx) final {
|
||||
ReplicaSetDDLTracker::ScopedReplicaSetDDL scopedReplicaSetDDL(
|
||||
opCtx, std::vector<NamespaceString>{ns()});
|
||||
|
||||
if (request().getNamespace().isOplog()) {
|
||||
uassert(5255000,
|
||||
"can't drop live oplog while replicating",
|
||||
!repl::ReplicationCoordinator::get(opCtx)->getSettings().isReplSet());
|
||||
auto storageEngine = opCtx->getServiceContext()->getStorageEngine();
|
||||
invariant(storageEngine);
|
||||
// We use the method supportsRecoveryTimestamp() to detect whether we are using
|
||||
// the WiredTiger storage engine, which is currently only storage engine that
|
||||
// supports the replSetResizeOplog command.
|
||||
uassert(
|
||||
5255001,
|
||||
"can't drop oplog on storage engines that support replSetResizeOplog command",
|
||||
!storageEngine->supportsRecoveryTimestamp());
|
||||
}
|
||||
|
||||
// We need to copy the serialization context from the request to the reply object
|
||||
Reply reply(
|
||||
SerializationContext::stateCommandReply(request().getSerializationContext()));
|
||||
uassertStatusOK(
|
||||
dropCollection(opCtx,
|
||||
request().getNamespace(),
|
||||
request().getCollectionUUID(),
|
||||
&reply,
|
||||
DropCollectionSystemCollectionMode::kDisallowSystemCollectionDrops));
|
||||
return reply;
|
||||
}
|
||||
};
|
||||
};
|
||||
MONGO_REGISTER_COMMAND(CmdDrop).forShard();
|
||||
|
||||
} // namespace
|
||||
} // namespace mongo
|
||||
136
src/mongo/db/shard_role/ddl/drop_database_cmd.cpp
Normal file
136
src/mongo/db/shard_role/ddl/drop_database_cmd.cpp
Normal file
@ -0,0 +1,136 @@
|
||||
/**
|
||||
* Copyright (C) 2025-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.
|
||||
*/
|
||||
|
||||
#include "mongo/base/error_codes.h"
|
||||
#include "mongo/base/status.h"
|
||||
#include "mongo/db/admission/execution_control/execution_admission_context.h"
|
||||
#include "mongo/db/auth/action_type.h"
|
||||
#include "mongo/db/auth/authorization_session.h"
|
||||
#include "mongo/db/client.h"
|
||||
#include "mongo/db/commands.h"
|
||||
#include "mongo/db/curop.h"
|
||||
#include "mongo/db/database_name.h"
|
||||
#include "mongo/db/namespace_string.h"
|
||||
#include "mongo/db/operation_context.h"
|
||||
#include "mongo/db/profile_settings.h"
|
||||
#include "mongo/db/query/internal_plans.h"
|
||||
#include "mongo/db/repl/replication_coordinator.h"
|
||||
#include "mongo/db/server_options.h"
|
||||
#include "mongo/db/service_context.h"
|
||||
#include "mongo/db/shard_role/ddl/coll_mod_gen.h"
|
||||
#include "mongo/db/shard_role/ddl/drop_database_gen.h"
|
||||
#include "mongo/db/shard_role/ddl/drop_gen.h"
|
||||
#include "mongo/db/shard_role/ddl/replica_set_ddl_tracker.h"
|
||||
#include "mongo/db/shard_role/shard_catalog/drop_collection.h"
|
||||
#include "mongo/db/shard_role/shard_catalog/drop_database.h"
|
||||
#include "mongo/db/storage/record_store.h"
|
||||
#include "mongo/db/storage/storage_engine.h"
|
||||
#include "mongo/db/topology/cluster_role.h"
|
||||
#include "mongo/logv2/log.h"
|
||||
#include "mongo/util/assert_util.h"
|
||||
#include "mongo/util/str.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <boost/move/utility_core.hpp>
|
||||
#include <boost/none.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/optional/optional.hpp>
|
||||
|
||||
#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kCommand
|
||||
|
||||
namespace mongo {
|
||||
namespace {
|
||||
|
||||
class CmdDropDatabase : public DropDatabaseCmdVersion1Gen<CmdDropDatabase> {
|
||||
public:
|
||||
std::string help() const final {
|
||||
return "drop (delete) this database";
|
||||
}
|
||||
AllowedOnSecondary secondaryAllowed(ServiceContext*) const final {
|
||||
return AllowedOnSecondary::kNever;
|
||||
}
|
||||
bool collectsResourceConsumptionMetrics() const final {
|
||||
return true;
|
||||
}
|
||||
bool allowedWithSecurityToken() const final {
|
||||
return true;
|
||||
}
|
||||
class Invocation final : public InvocationBaseGen {
|
||||
public:
|
||||
using InvocationBaseGen::InvocationBaseGen;
|
||||
bool supportsWriteConcern() const final {
|
||||
return true;
|
||||
}
|
||||
NamespaceString ns() const final {
|
||||
return NamespaceString(request().getDbName());
|
||||
}
|
||||
void doCheckAuthorization(OperationContext* opCtx) const final {
|
||||
uassert(ErrorCodes::Unauthorized,
|
||||
str::stream() << "Not authorized to drop database '"
|
||||
<< request().getDbName().toStringForErrorMsg() << "'",
|
||||
AuthorizationSession::get(opCtx->getClient())
|
||||
->isAuthorizedForActionsOnNamespace(ns(), ActionType::dropDatabase));
|
||||
}
|
||||
Reply typedRun(OperationContext* opCtx) final {
|
||||
ReplicaSetDDLTracker::ScopedReplicaSetDDL scopedReplicaSetDDL(
|
||||
opCtx, std::vector<NamespaceString>{ns()});
|
||||
|
||||
auto dbName = request().getDbName();
|
||||
// disallow dropping the config database
|
||||
if (serverGlobalParams.clusterRole.has(ClusterRole::ConfigServer) &&
|
||||
(dbName == DatabaseName::kConfig)) {
|
||||
uasserted(ErrorCodes::IllegalOperation,
|
||||
"Cannot drop 'config' database if mongod started "
|
||||
"with --configsvr");
|
||||
}
|
||||
|
||||
if ((repl::ReplicationCoordinator::get(opCtx)->getSettings().isReplSet()) &&
|
||||
(dbName == DatabaseName::kLocal)) {
|
||||
uasserted(ErrorCodes::IllegalOperation,
|
||||
str::stream() << "Cannot drop '" << dbName.toStringForErrorMsg()
|
||||
<< "' database while replication is active");
|
||||
}
|
||||
|
||||
if (request().getCommandParameter() != 1) {
|
||||
uasserted(5255100, "Have to pass 1 as 'drop' parameter");
|
||||
}
|
||||
|
||||
Status status = dropDatabase(opCtx, dbName);
|
||||
if (status != ErrorCodes::NamespaceNotFound) {
|
||||
uassertStatusOK(status);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
};
|
||||
};
|
||||
MONGO_REGISTER_COMMAND(CmdDropDatabase).forShard();
|
||||
|
||||
} // namespace
|
||||
} // namespace mongo
|
||||
Loading…
Reference in New Issue
Block a user