summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTommaso Tocci <tommaso.tocci@mongodb.com>2021-03-11 10:01:06 +0100
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-03-16 10:48:04 +0000
commitb134809bd5db091c0517ee0fb4378ad420a5c021 (patch)
tree3716fd90ff7c07fd28ef3dc5a7349b0e76138578 /src
parent8bc0340b458b363510bd2caca8c1b6a5790f41db (diff)
downloadmongo-b134809bd5db091c0517ee0fb4378ad420a5c021.tar.gz
SERVER-55145 Make dropping a nonexistent database a noop
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/commands/dbcommands.cpp9
-rw-r--r--src/mongo/db/drop_database.idl16
-rw-r--r--src/mongo/db/s/config/configsvr_drop_database_command.cpp7
-rw-r--r--src/mongo/db/s/drop_database_legacy.cpp10
-rw-r--r--src/mongo/db/s/drop_database_legacy.h2
-rw-r--r--src/mongo/db/s/shardsvr_drop_database_command.cpp9
-rw-r--r--src/mongo/s/commands/cluster_drop_database_cmd.cpp11
-rw-r--r--src/mongo/s/request_types/sharded_ddl_commands.idl2
8 files changed, 13 insertions, 53 deletions
diff --git a/src/mongo/db/commands/dbcommands.cpp b/src/mongo/db/commands/dbcommands.cpp
index b6c1790794f..299ebc197c5 100644
--- a/src/mongo/db/commands/dbcommands.cpp
+++ b/src/mongo/db/commands/dbcommands.cpp
@@ -208,15 +208,10 @@ public:
}
Status status = dropDatabase(opCtx, dbName.toString());
- DropDatabaseReply reply;
- if (status == ErrorCodes::NamespaceNotFound) {
- reply.setInfo("database does not exist"_sd);
- } else {
+ if (status != ErrorCodes::NamespaceNotFound) {
uassertStatusOK(status);
- reply.setDropped(request().getDbName());
}
-
- return reply;
+ return {};
}
};
} cmdDropDatabase;
diff --git a/src/mongo/db/drop_database.idl b/src/mongo/db/drop_database.idl
index 65871ce89f8..5083a0d8559 100644
--- a/src/mongo/db/drop_database.idl
+++ b/src/mongo/db/drop_database.idl
@@ -32,20 +32,6 @@ global:
imports:
- "mongo/idl/basic_types.idl"
-structs:
- DropDatabaseReply:
- description: "The dropDatabase command's reply"
- strict: false
- fields:
- dropped:
- description: "The database's name, if it existed and was dropped"
- type: string
- optional: true
- info:
- description: "May provide information on dropDatabase's outcome"
- type: string
- optional: true
-
commands:
dropDatabase:
description: "Parser for the dropDatabase command"
@@ -55,4 +41,4 @@ commands:
cpp_name: DropDatabase
strict: true
api_version: "1"
- reply_type: DropDatabaseReply
+ reply_type: OkReply
diff --git a/src/mongo/db/s/config/configsvr_drop_database_command.cpp b/src/mongo/db/s/config/configsvr_drop_database_command.cpp
index de258fab32d..f725a778f68 100644
--- a/src/mongo/db/s/config/configsvr_drop_database_command.cpp
+++ b/src/mongo/db/s/config/configsvr_drop_database_command.cpp
@@ -113,11 +113,8 @@ public:
<< cmdObj,
opCtx->getWriteConcern().wMode == WriteConcernOptions::kMajority);
- auto reply = dropDatabaseLegacy(opCtx, dbname);
- if (!reply.getDropped()) {
- repl::ReplClientInfo::forClient(opCtx->getClient()).setLastOpToSystemLastOpTime(opCtx);
- }
- reply.serialize(&result);
+ dropDatabaseLegacy(opCtx, dbname);
+ repl::ReplClientInfo::forClient(opCtx->getClient()).setLastOpToSystemLastOpTime(opCtx);
return true;
}
} configsvrDropDatabaseCmd;
diff --git a/src/mongo/db/s/drop_database_legacy.cpp b/src/mongo/db/s/drop_database_legacy.cpp
index cd257699ce8..ffab770a1aa 100644
--- a/src/mongo/db/s/drop_database_legacy.cpp
+++ b/src/mongo/db/s/drop_database_legacy.cpp
@@ -64,7 +64,7 @@ void dropDatabaseFromShard(OperationContext* opCtx, const ShardId& shardId, Stri
} // namespace
-DropDatabaseReply dropDatabaseLegacy(OperationContext* opCtx, StringData dbName) {
+void dropDatabaseLegacy(OperationContext* opCtx, StringData dbName) {
auto dbDistLock = uassertStatusOK(DistLockManager::get(opCtx)->lock(
opCtx, dbName, "dropDatabase", DistLockManager::kDefaultLockTimeout));
@@ -77,9 +77,7 @@ DropDatabaseReply dropDatabaseLegacy(OperationContext* opCtx, StringData dbName)
dbType =
catalogClient->getDatabase(opCtx, dbName, repl::ReadConcernLevel::kMajorityReadConcern);
} catch (const ExceptionFor<ErrorCodes::NamespaceNotFound>&) {
- DropDatabaseReply reply;
- reply.setInfo("database does not exist"_sd);
- return reply;
+ return;
}
uassertStatusOK(ShardingLogging::get(opCtx)->logChangeChecked(
@@ -131,10 +129,6 @@ DropDatabaseReply dropDatabaseLegacy(OperationContext* opCtx, StringData dbName)
ShardingLogging::get(opCtx)->logChange(
opCtx, "dropDatabase", dbName, BSONObj(), ShardingCatalogClient::kMajorityWriteConcern);
-
- DropDatabaseReply reply;
- reply.setDropped(dbName);
- return reply;
}
} // namespace mongo
diff --git a/src/mongo/db/s/drop_database_legacy.h b/src/mongo/db/s/drop_database_legacy.h
index f03f06c688d..78f0b4d0751 100644
--- a/src/mongo/db/s/drop_database_legacy.h
+++ b/src/mongo/db/s/drop_database_legacy.h
@@ -35,6 +35,6 @@
namespace mongo {
-DropDatabaseReply dropDatabaseLegacy(OperationContext* opCtx, StringData dbName);
+void dropDatabaseLegacy(OperationContext* opCtx, StringData dbName);
} // namespace mongo
diff --git a/src/mongo/db/s/shardsvr_drop_database_command.cpp b/src/mongo/db/s/shardsvr_drop_database_command.cpp
index 617ec9a3eb3..3a4088d01e8 100644
--- a/src/mongo/db/s/shardsvr_drop_database_command.cpp
+++ b/src/mongo/db/s/shardsvr_drop_database_command.cpp
@@ -49,7 +49,6 @@ namespace {
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 "
@@ -68,7 +67,7 @@ public:
public:
using InvocationBase::InvocationBase;
- Response typedRun(OperationContext* opCtx) {
+ void typedRun(OperationContext* opCtx) {
uassertStatusOK(ShardingState::get(opCtx)->canAcceptShardedCommands());
uassert(ErrorCodes::InvalidOptions,
@@ -89,7 +88,8 @@ public:
if (!useNewPath) {
LOGV2_DEBUG(
5281110, 1, "Running legacy drop database procedure", "database"_attr = dbName);
- return dropDatabaseLegacy(opCtx, dbName);
+ dropDatabaseLegacy(opCtx, dbName);
+ return;
}
LOGV2_DEBUG(
@@ -102,9 +102,6 @@ public:
auto dropDatabaseCoordinator = std::make_shared<DropDatabaseCoordinator>(opCtx, dbName);
dropDatabaseCoordinator->run(opCtx).get();
-
- // The following response can be omitted once 5.0 became last LTS
- return Response();
}
private:
diff --git a/src/mongo/s/commands/cluster_drop_database_cmd.cpp b/src/mongo/s/commands/cluster_drop_database_cmd.cpp
index 313da69ea31..7eff991cf4c 100644
--- a/src/mongo/s/commands/cluster_drop_database_cmd.cpp
+++ b/src/mongo/s/commands/cluster_drop_database_cmd.cpp
@@ -106,17 +106,10 @@ public:
const auto remoteResponse = uassertStatusOK(cmdResponse.swResponse);
uassertStatusOK(getStatusFromCommandResult(remoteResponse.data));
-
- DropDatabaseReply reply;
- reply.setDropped(dbName);
- return reply;
} catch (const ExceptionFor<ErrorCodes::NamespaceNotFound>&) {
- // If the namespace isn't found, treat the drop as a success but inform about the
- // failure.
- DropDatabaseReply reply;
- reply.setInfo("database does not exist"_sd);
- return reply;
+ // If the namespace isn't found, treat the drop as a success
}
+ return {};
}
};
} clusterDropDatabaseCmd;
diff --git a/src/mongo/s/request_types/sharded_ddl_commands.idl b/src/mongo/s/request_types/sharded_ddl_commands.idl
index bebedb8853f..2e142c46424 100644
--- a/src/mongo/s/request_types/sharded_ddl_commands.idl
+++ b/src/mongo/s/request_types/sharded_ddl_commands.idl
@@ -133,8 +133,6 @@ commands:
namespace: ignored
api_version: ""
cpp_name: ShardsvrDropDatabase
- # The reply can completely removed once 5.0 becomes last lts
- reply_type: DropDatabaseReply
_shardsvrDropDatabaseParticipant:
description: "Internal command sent to participants shards to drop a database."