summaryrefslogtreecommitdiff
path: root/src/mongo/s
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/s')
-rw-r--r--src/mongo/s/SConscript1
-rw-r--r--src/mongo/s/commands/cluster_drop_database_cmd.cpp63
-rw-r--r--src/mongo/s/request_types/sharded_ddl_commands.idl44
3 files changed, 85 insertions, 23 deletions
diff --git a/src/mongo/s/SConscript b/src/mongo/s/SConscript
index bf4fc8cc3a6..29518c5d5ae 100644
--- a/src/mongo/s/SConscript
+++ b/src/mongo/s/SConscript
@@ -171,6 +171,7 @@ env.Library(
'request_types/reshard_collection.idl',
'request_types/set_shard_version_request.cpp',
'request_types/shard_collection.idl',
+ 'request_types/sharded_ddl_commands.idl',
'request_types/split_chunk_request_type.cpp',
'request_types/update_zone_key_range_request_type.cpp',
'request_types/wait_for_fail_point.idl',
diff --git a/src/mongo/s/commands/cluster_drop_database_cmd.cpp b/src/mongo/s/commands/cluster_drop_database_cmd.cpp
index f96a2cef9fc..3cb36fe8518 100644
--- a/src/mongo/s/commands/cluster_drop_database_cmd.cpp
+++ b/src/mongo/s/commands/cluster_drop_database_cmd.cpp
@@ -35,9 +35,12 @@
#include "mongo/db/commands.h"
#include "mongo/db/drop_database_gen.h"
#include "mongo/db/operation_context.h"
+#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/s/catalog_cache.h"
#include "mongo/s/client/shard_registry.h"
+#include "mongo/s/cluster_commands_helpers.h"
#include "mongo/s/grid.h"
+#include "mongo/s/request_types/sharded_ddl_commands_gen.h"
#include "mongo/util/scopeguard.h"
namespace mongo {
@@ -78,7 +81,6 @@ public:
uassert(ErrorCodes::IllegalOperation,
"Cannot drop the config database",
dbname != NamespaceString::kConfigDb);
-
uassert(ErrorCodes::IllegalOperation,
"Cannot drop the admin database",
dbname != NamespaceString::kAdminDb);
@@ -88,28 +90,43 @@ public:
"have to pass 1 as db parameter",
request.getCommandParameter() == 1);
- // Invalidate the database metadata so the next access kicks off a full reload, even if
- // sending the command to the config server fails due to e.g. a NetworkError.
- ON_BLOCK_EXIT([opCtx, dbname] { Grid::get(opCtx)->catalogCache()->purgeDatabase(dbname); });
-
- // Send _configsvrDropDatabase to the config server.
- auto configShard = Grid::get(opCtx)->shardRegistry()->getConfigShard();
- auto cmdResponse = uassertStatusOK(configShard->runCommandWithFixedRetryAttempts(
- opCtx,
- ReadPreferenceSetting(ReadPreference::PrimaryOnly),
- "admin",
- CommandHelpers::appendMajorityWriteConcern(
- CommandHelpers::appendGenericCommandArgs(cmdObj,
- BSON("_configsvrDropDatabase" << dbname)),
- opCtx->getWriteConcern()),
- Shard::RetryPolicy::kIdempotent));
-
- // The cmdResponse status can be OK even if the config server replied ok: 0.
- uassertStatusOK(cmdResponse.commandStatus);
- auto reply = DropDatabaseReply::parse(IDLParserErrorContext("dropDatabase-reply"),
- cmdResponse.response);
- CommandHelpers::appendGenericReplyFields(cmdResponse.response, reply.toBSON(), &result);
- return true;
+ try {
+
+ const CachedDatabaseInfo dbInfo =
+ uassertStatusOK(Grid::get(opCtx)->catalogCache()->getDatabase(opCtx, dbname));
+
+ // Invalidate the database metadata so the next access kicks off a full reload, even if
+ // sending the command to the config server fails due to e.g. a NetworkError.
+ ON_BLOCK_EXIT(
+ [opCtx, dbname] { Grid::get(opCtx)->catalogCache()->purgeDatabase(dbname); });
+
+ // Send it to the primary shard
+ ShardsvrDropDatabase dropDatabaseCommand(1);
+ dropDatabaseCommand.setDbName(dbname);
+
+ auto cmdResponse = executeCommandAgainstDatabasePrimary(
+ opCtx,
+ dbname,
+ dbInfo,
+ CommandHelpers::appendMajorityWriteConcern(dropDatabaseCommand.toBSON({}),
+ opCtx->getWriteConcern()),
+ ReadPreferenceSetting(ReadPreference::PrimaryOnly),
+ Shard::RetryPolicy::kIdempotent);
+
+ const auto remoteResponse = uassertStatusOK(cmdResponse.swResponse);
+ uassertStatusOK(getStatusFromCommandResult(remoteResponse.data));
+
+ auto reply = DropDatabaseReply::parse(IDLParserErrorContext("dropDatabase-reply"),
+ remoteResponse.data);
+ CommandHelpers::appendGenericReplyFields(remoteResponse.data, reply.toBSON(), &result);
+
+ return true;
+ } catch (const ExceptionFor<ErrorCodes::NamespaceNotFound>&) {
+ // If the namespace isn't found, treat the drop as a success but inform about the
+ // failure.
+ result.append("info", "database does not exist");
+ return true;
+ }
}
} clusterDropDatabaseCmd;
diff --git a/src/mongo/s/request_types/sharded_ddl_commands.idl b/src/mongo/s/request_types/sharded_ddl_commands.idl
new file mode 100644
index 00000000000..cf94288655b
--- /dev/null
+++ b/src/mongo/s/request_types/sharded_ddl_commands.idl
@@ -0,0 +1,44 @@
+# Copyright (C) 2020-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.
+#
+
+global:
+ cpp_namespace: "mongo"
+
+imports:
+ - "mongo/db/drop_database.idl"
+ - "mongo/s/database_version.idl"
+
+commands:
+ _shardsvrDropDatabase:
+ description: "Parser for the shardDropDatabase command"
+ command_name: _shardsvrDropDatabase
+ namespace: type
+ type: safeInt64
+ cpp_name: ShardsvrDropDatabase
+ strict: true
+ reply_type: DropDatabaseReply \ No newline at end of file