diff options
author | Ali Mir <ali.mir@mongodb.com> | 2020-09-23 18:18:26 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-09-23 20:41:59 +0000 |
commit | e178007c01565bf59d038f3be1566da036c60397 (patch) | |
tree | f5e348c2a116c0977483dad5cc599a169edc705e /src/mongo/db/repl/replication_info.cpp | |
parent | 62e89bd2119904531b591b6948f57b00eb52ec79 (diff) | |
download | mongo-e178007c01565bf59d038f3be1566da036c60397.tar.gz |
SERVER-51106 Make the isMaster command a derived class of hello
Diffstat (limited to 'src/mongo/db/repl/replication_info.cpp')
-rw-r--r-- | src/mongo/db/repl/replication_info.cpp | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/src/mongo/db/repl/replication_info.cpp b/src/mongo/db/repl/replication_info.cpp index c65e36a8e2b..e4ad5980808 100644 --- a/src/mongo/db/repl/replication_info.cpp +++ b/src/mongo/db/repl/replication_info.cpp @@ -83,7 +83,6 @@ 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; @@ -239,11 +238,9 @@ public: } } oplogInfoServerStatus; -class CmdHello final : public BasicCommandWithReplyBuilderInterface { +class CmdHello : public BasicCommandWithReplyBuilderInterface { public: - CmdHello() - : BasicCommandWithReplyBuilderInterface( - kHelloString, {kCamelCaseIsMasterString, kLowerCaseIsMasterString}) {} + CmdHello() : CmdHello(kHelloString, {}) {} const std::set<std::string>& apiVersions() const { return kApiVersions1; @@ -285,11 +282,6 @@ public: LastError::get(opCtx->getClient()).disable(); } - // Parse the command name, which should be one of the following: hello, isMaster, or - // ismaster. If the command is "hello", we must attach an "isWritablePrimary" response field - // instead of "ismaster" and "secondaryDelaySecs" response field instead of "slaveDelay". - bool useLegacyResponseFields = (cmdObj.firstElementFieldNameStringData() != kHelloString); - transport::Session::TagMask sessionTagsToSet = 0; transport::Session::TagMask sessionTagsToUnset = 0; @@ -434,7 +426,7 @@ public: auto result = replyBuilder->getBodyBuilder(); auto currentTopologyVersion = appendReplicationInfo( - opCtx, &result, 0, useLegacyResponseFields, clientTopologyVersion, maxAwaitTimeMS); + opCtx, &result, 0, useLegacyResponseFields(), clientTopologyVersion, maxAwaitTimeMS); if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer) { const int configServerModeNumber = 2; @@ -506,8 +498,36 @@ public: return true; } + +protected: + CmdHello(const StringData cmdName, const std::initializer_list<StringData>& alias) + : BasicCommandWithReplyBuilderInterface(cmdName, alias) {} + + virtual bool useLegacyResponseFields() { + return false; + } + } cmdhello; +class CmdIsMaster : public CmdHello { +public: + CmdIsMaster() : CmdHello(kCamelCaseIsMasterString, {kLowerCaseIsMasterString}) {} + + std::string help() const override { + return "Check if this server is primary for a replica set\n" + "{ isMaster : 1 }"; + } + +protected: + // Parse the command name, which should be one of the following: hello, isMaster, or + // ismaster. If the command is "hello", we must attach an "isWritablePrimary" response field + // instead of "ismaster" and "secondaryDelaySecs" response field instead of "slaveDelay". + bool useLegacyResponseFields() override { + return true; + } + +} cmdIsMaster; + OpCounterServerStatusSection replOpCounterServerStatusSection("opcountersRepl", &replOpCounters); } // namespace |