diff options
author | Pavi Vetriselvan <pavithra.vetriselvan@mongodb.com> | 2020-08-31 08:53:04 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-09-16 01:41:14 +0000 |
commit | 5c22d7a3271ccb6b31e52557bc3d484deebb7f12 (patch) | |
tree | 82456a872b68e416d01995c1b275ec6da96a86d1 | |
parent | 8b8385f99237738faf06de6ee352269569ae3473 (diff) | |
download | mongo-5c22d7a3271ccb6b31e52557bc3d484deebb7f12.tar.gz |
SERVER-50640 listCommands should list isMaster in addition to hello
(cherry picked from commit 2756fa678945f890c73318efa72d3793c6e918d8)
7 files changed, 27 insertions, 16 deletions
diff --git a/jstests/core/list_commands.js b/jstests/core/list_commands.js index 2310d7d9a0a..e9c021ff32b 100644 --- a/jstests/core/list_commands.js +++ b/jstests/core/list_commands.js @@ -22,6 +22,7 @@ // Test that result contains basic commands. assert(commands.hasOwnProperty("commands")); assert(commands["commands"].hasOwnProperty("hello")); + assert(commands["commands"].hasOwnProperty("isMaster")); assert(commands["commands"].hasOwnProperty("insert")); assert(commands["commands"].hasOwnProperty("ping")); })(); diff --git a/jstests/core/views/views_all_commands.js b/jstests/core/views/views_all_commands.js index 46f161bf122..59d5d0be518 100644 --- a/jstests/core/views/views_all_commands.js +++ b/jstests/core/views/views_all_commands.js @@ -305,6 +305,7 @@ insert: {command: {insert: "view", documents: [{x: 1}]}, expectFailure: true}, invalidateUserCache: {skip: isUnrelated}, isdbgrid: {skip: isUnrelated}, + isMaster: {skip: isUnrelated}, journalLatencyTest: {skip: isUnrelated}, killCursors: { setup: function(conn) { diff --git a/jstests/replsets/db_reads_while_recovering_all_commands.js b/jstests/replsets/db_reads_while_recovering_all_commands.js index 036fecbc6e6..06be14ffe96 100644 --- a/jstests/replsets/db_reads_while_recovering_all_commands.js +++ b/jstests/replsets/db_reads_while_recovering_all_commands.js @@ -205,6 +205,7 @@ insert: {skip: isPrimaryOnly}, internalRenameIfOptionsAndIndexesMatch: {skip: isAnInternalCommand}, invalidateUserCache: {skip: isNotAUserDataRead}, + isMaster: {skip: isNotAUserDataRead}, journalLatencyTest: {skip: isNotAUserDataRead}, killAllSessions: {skip: isNotAUserDataRead}, killAllSessionsByPattern: {skip: isNotAUserDataRead}, diff --git a/jstests/sharding/safe_secondary_reads_drop_recreate.js b/jstests/sharding/safe_secondary_reads_drop_recreate.js index e9794244aca..24f104bfc03 100644 --- a/jstests/sharding/safe_secondary_reads_drop_recreate.js +++ b/jstests/sharding/safe_secondary_reads_drop_recreate.js @@ -234,6 +234,7 @@ insert: {skip: "primary only"}, invalidateUserCache: {skip: "does not return user data"}, isdbgrid: {skip: "does not return user data"}, + isMaster: {skip: "does not return user data"}, journalLatencyTest: {skip: "does not return user data"}, killAllSessions: {skip: "does not return user data"}, killAllSessionsByPattern: {skip: "does not return user data"}, diff --git a/jstests/sharding/safe_secondary_reads_single_migration_suspend_range_deletion.js b/jstests/sharding/safe_secondary_reads_single_migration_suspend_range_deletion.js index ab5fe6ae322..b65e7fabae4 100644 --- a/jstests/sharding/safe_secondary_reads_single_migration_suspend_range_deletion.js +++ b/jstests/sharding/safe_secondary_reads_single_migration_suspend_range_deletion.js @@ -274,6 +274,7 @@ insert: {skip: "primary only"}, invalidateUserCache: {skip: "does not return user data"}, isdbgrid: {skip: "does not return user data"}, + isMaster: {skip: "does not return user data"}, journalLatencyTest: {skip: "does not return user data"}, killCursors: {skip: "does not return user data"}, killAllSessions: {skip: "does not return user data"}, diff --git a/jstests/sharding/safe_secondary_reads_single_migration_waitForDelete.js b/jstests/sharding/safe_secondary_reads_single_migration_waitForDelete.js index af12768b14d..126ace906a9 100644 --- a/jstests/sharding/safe_secondary_reads_single_migration_waitForDelete.js +++ b/jstests/sharding/safe_secondary_reads_single_migration_waitForDelete.js @@ -238,6 +238,7 @@ insert: {skip: "primary only"}, invalidateUserCache: {skip: "does not return user data"}, isdbgrid: {skip: "does not return user data"}, + isMaster: {skip: "does not return user data"}, journalLatencyTest: {skip: "does not return user data"}, killAllSessions: {skip: "does not return user data"}, killAllSessionsByPattern: {skip: "does not return user data"}, diff --git a/src/mongo/db/commands/generic.cpp b/src/mongo/db/commands/generic.cpp index 22a54ca1be4..4940d1106dd 100644 --- a/src/mongo/db/commands/generic.cpp +++ b/src/mongo/db/commands/generic.cpp @@ -34,6 +34,7 @@ #include <time.h> +#include "mongo/base/string_data.h" #include "mongo/bson/util/bson_extract.h" #include "mongo/bson/util/builder.h" #include "mongo/client/dbclient_rs.h" @@ -72,6 +73,8 @@ using std::string; using std::stringstream; using std::vector; +constexpr auto kIsMasterString = "isMaster"_sd; + class CmdBuildInfo : public BasicCommand { public: CmdBuildInfo() : BasicCommand("buildInfo", "buildinfo") {} @@ -278,33 +281,35 @@ public: const string& ns, const BSONObj& cmdObj, BSONObjBuilder& result) { - // sort the commands before building the result BSON - std::vector<Command*> commands; + // Sort the command names before building the result BSON. + std::vector<std::string> commandNames; for (const auto command : allCommands()) { - // don't show oldnames - if (command.first == command.second->getName()) - commands.push_back(command.second); + // Don't show oldnames unless it's "isMaster". The output of the listCommands command + // must include "isMaster," even though it's an alias for the "hello" command, in order + // to preserve backwards compatibility with Ops Manager 4.4. + if (command.first == command.second->getName() || command.first == kIsMasterString) + commandNames.push_back(command.first); } - std::sort(commands.begin(), commands.end(), [](Command* lhs, Command* rhs) { - return (lhs->getName()) < (rhs->getName()); - }); + std::sort(commandNames.begin(), commandNames.end()); BSONObjBuilder b(result.subobjStart("commands")); - for (const auto& c : commands) { - BSONObjBuilder temp(b.subobjStart(c->getName())); - + for (const auto& c : commandNames) { + const auto command = findCommand(c); + auto name = (c == kIsMasterString) ? kIsMasterString : command->getName(); + BSONObjBuilder temp(b.subobjStart(name)); { stringstream help; - c->help(help); + command->help(help); temp.append("help", help.str()); } - temp.append("slaveOk", c->slaveOk()); - temp.append("adminOnly", c->adminOnly()); + temp.append("slaveOk", command->slaveOk()); + temp.append("adminOnly", command->adminOnly()); // optionally indicates that the command can be forced to run on a slave/secondary - if (c->slaveOverrideOk()) - temp.append("slaveOverrideOk", c->slaveOverrideOk()); + if (command->slaveOverrideOk()) + temp.append("slaveOverrideOk", command->slaveOverrideOk()); temp.done(); } + b.done(); return 1; |