diff options
author | Samy Lanka <samy.lanka@mongodb.com> | 2020-04-02 18:56:20 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-04-16 00:32:40 +0000 |
commit | f7e7e994cb14bf349ea1ce9a86ec6012b7330b66 (patch) | |
tree | 5ee821bbdad14864fdd6ebf71d78a60ef63058df /src/mongo/db/commands/drop_indexes.cpp | |
parent | dcd3b4b465fed5449866aaf34909b9e2de53a6c6 (diff) | |
download | mongo-f7e7e994cb14bf349ea1ce9a86ec6012b7330b66.tar.gz |
SERVER-44343 Make 'reIndex' a standalone-only command
Diffstat (limited to 'src/mongo/db/commands/drop_indexes.cpp')
-rw-r--r-- | src/mongo/db/commands/drop_indexes.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/mongo/db/commands/drop_indexes.cpp b/src/mongo/db/commands/drop_indexes.cpp index 1b48d355e5c..38266a3cf48 100644 --- a/src/mongo/db/commands/drop_indexes.cpp +++ b/src/mongo/db/commands/drop_indexes.cpp @@ -100,13 +100,16 @@ public: class CmdReIndex : public ErrmsgCommandDeprecated { public: AllowedOnSecondary secondaryAllowed(ServiceContext*) const override { - return AllowedOnSecondary::kAlways; // can reindex on a secondary + // Even though reIndex is a standalone-only command, this will return that the command is + // allowed on secondaries so that it will fail with a more useful error message to the user + // rather than with a NotMaster error. + return AllowedOnSecondary::kAlways; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; } std::string help() const override { - return "re-index a collection"; + return "re-index a collection (can only be run on a standalone mongod)"; } virtual void addRequiredPrivileges(const std::string& dbname, const BSONObj& cmdObj, @@ -128,6 +131,15 @@ public: LOGV2(20457, "CMD: reIndex {toReIndexNss}", "toReIndexNss"_attr = toReIndexNss); + if (repl::ReplicationCoordinator::get(opCtx)->getReplicationMode() != + repl::ReplicationCoordinator::modeNone) { + uasserted( + ErrorCodes::IllegalOperation, + str::stream() + << "reIndex is only allowed on a standalone mongod instance. Cannot reIndex '" + << toReIndexNss << "' while replication is active"); + } + AutoGetCollection autoColl(opCtx, toReIndexNss, MODE_X); Collection* collection = autoColl.getCollection(); if (!collection) { |