From 8b8385f99237738faf06de6ee352269569ae3473 Mon Sep 17 00:00:00 2001 From: Pavi Vetriselvan Date: Thu, 30 Jul 2020 12:39:35 -0400 Subject: SERVER-49986 Convert isMaster command to hello and keep isMaster, ismaster aliases (cherry picked from commit 9a4be902441496be7ef40e5404a91ac30dc81f77) --- src/mongo/db/repl/replication_info.cpp | 13 ++++++++++--- src/mongo/s/commands/cluster_is_master_cmd.cpp | 12 +++++++++--- 2 files changed, 19 insertions(+), 6 deletions(-) (limited to 'src/mongo') diff --git a/src/mongo/db/repl/replication_info.cpp b/src/mongo/db/repl/replication_info.cpp index 4007bfda120..afb68ed3314 100644 --- a/src/mongo/db/repl/replication_info.cpp +++ b/src/mongo/db/repl/replication_info.cpp @@ -33,6 +33,7 @@ #include #include +#include "mongo/base/string_data.h" #include "mongo/client/connpool.h" #include "mongo/db/client.h" #include "mongo/db/commands/server_status.h" @@ -70,6 +71,11 @@ using std::stringstream; namespace repl { namespace { +constexpr auto kHelloString = "hello"_sd; +// Aliases for the hello command in order to provide backwards compatibility. +constexpr auto kCamelCaseIsMasterString = "isMaster"_sd; +constexpr auto kLowerCaseIsMasterString = "ismaster"_sd; + void appendReplicationInfo(OperationContext* opCtx, BSONObjBuilder& result, int level) { ReplicationCoordinator* replCoord = getGlobalReplicationCoordinator(); if (replCoord->getSettings().usingReplSets()) { @@ -214,8 +220,10 @@ public: } } oplogInfoServerStatus; -class CmdIsMaster : public BasicCommand { +class CmdHello final : public BasicCommand { public: + CmdHello() : BasicCommand(kHelloString, {kCamelCaseIsMasterString, kLowerCaseIsMasterString}) {} + bool requiresAuth() const override { return false; } @@ -233,7 +241,6 @@ public: virtual void addRequiredPrivileges(const std::string& dbname, const BSONObj& cmdObj, std::vector* out) {} // No auth required - CmdIsMaster() : BasicCommand("isMaster", "ismaster") {} virtual bool run(OperationContext* opCtx, const string&, const BSONObj& cmdObj, @@ -403,7 +410,7 @@ public: return true; } -} cmdismaster; +} cmdhello; OpCounterServerStatusSection replOpCounterServerStatusSection("opcountersRepl", &replOpCounters); diff --git a/src/mongo/s/commands/cluster_is_master_cmd.cpp b/src/mongo/s/commands/cluster_is_master_cmd.cpp index cf5e9b81bed..d6e2c1b1187 100644 --- a/src/mongo/s/commands/cluster_is_master_cmd.cpp +++ b/src/mongo/s/commands/cluster_is_master_cmd.cpp @@ -30,6 +30,7 @@ #include "mongo/platform/basic.h" +#include "mongo/base/string_data.h" #include "mongo/db/client.h" #include "mongo/db/commands.h" #include "mongo/db/logical_session_cache.h" @@ -48,9 +49,14 @@ namespace mongo { namespace { -class CmdIsMaster : public BasicCommand { +constexpr auto kHelloString = "hello"_sd; +// Aliases for the hello command in order to provide backwards compatibility. +constexpr auto kCamelCaseIsMasterString = "isMaster"_sd; +constexpr auto kLowerCaseIsMasterString = "ismaster"_sd; + +class CmdHello : public BasicCommand { public: - CmdIsMaster() : BasicCommand("isMaster", "ismaster") {} + CmdHello() : BasicCommand(kHelloString, {kCamelCaseIsMasterString, kLowerCaseIsMasterString}) {} bool supportsWriteConcern(const BSONObj& cmd) const override { return false; @@ -141,7 +147,7 @@ public: return true; } -} isMaster; +} hello; } // namespace } // namespace mongo -- cgit v1.2.1