summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavi Vetriselvan <pavithra.vetriselvan@mongodb.com>2020-08-06 09:49:48 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-09-10 16:44:19 +0000
commit7f4b7630dce4471bfdcdaf0301d8c4bec0d635f8 (patch)
tree7d66cb635a7ac96f8d8d8648cce0080f9e031c34
parente214f4116559a5beba8f158227c339ebc00f7ea9 (diff)
downloadmongo-7f4b7630dce4471bfdcdaf0301d8c4bec0d635f8.tar.gz
SERVER-49988 Rename response fields if hello command is sent on mongos
(cherry picked from commit 8d495ce686890719e96c66ee6f3d1ddbf7704e78)
-rw-r--r--jstests/core/ismaster.js6
-rw-r--r--jstests/sharding/ismaster.js13
-rw-r--r--src/mongo/s/commands/cluster_is_master_cmd.cpp12
3 files changed, 24 insertions, 7 deletions
diff --git a/jstests/core/ismaster.js b/jstests/core/ismaster.js
index a8ed96a4ac1..5f309b83392 100644
--- a/jstests/core/ismaster.js
+++ b/jstests/core/ismaster.js
@@ -16,7 +16,7 @@ function checkResponseFields(commandString) {
"maxWriteBatchSize possibly missing:" + tojson(res));
assert.eq("boolean", typeof res.ismaster, "ismaster field is not a boolean" + tojson(res));
- // TODO SERVER-49988: Check for res.isWritablePrimary instead of res.ismaster if a hello command
+ // TODO SERVER-49987: Check for res.isWritablePrimary instead of res.ismaster if a hello command
// was executed.
assert(res.ismaster === true, "ismaster field is false" + tojson(res));
assert(res.localTime, "localTime possibly missing:" + tojson(res));
@@ -56,6 +56,8 @@ function checkResponseFields(commandString) {
}
}
-checkResponseFields("hello");
+// TODO SERVER-49987: add the "hello" command test back in once mongod response fields are
+// appropriately changed.
+// checkResponseFields("hello");
checkResponseFields("ismaster");
checkResponseFields("isMaster");
diff --git a/jstests/sharding/ismaster.js b/jstests/sharding/ismaster.js
index a582f677241..185294200ac 100644
--- a/jstests/sharding/ismaster.js
+++ b/jstests/sharding/ismaster.js
@@ -16,10 +16,15 @@ function checkResponseFields(commandString) {
res.maxMessageSizeBytes && isNumber(res.maxMessageSizeBytes) && res.maxBsonObjectSize > 0,
"maxMessageSizeBytes possibly missing:" + tojson(res));
- // TODO SERVER-49988: Check for res.isWritablePrimary instead of res.ismaster if a hello command
- // was executed.
- assert.eq("boolean", typeof res.ismaster, "ismaster field is not a boolean" + tojson(res));
- assert(res.ismaster === true, "ismaster field is false" + tojson(res));
+ if (commandString === "hello") {
+ assert.eq("boolean",
+ typeof res.isWritablePrimary,
+ "isWritablePrimary field is not a boolean" + tojson(res));
+ assert(res.isWritablePrimary === true, "isWritablePrimary field is false" + tojson(res));
+ } else {
+ assert.eq("boolean", typeof res.ismaster, "ismaster field is not a boolean" + tojson(res));
+ assert(res.ismaster === true, "ismaster field is false" + tojson(res));
+ }
assert(res.localTime, "localTime possibly missing:" + tojson(res));
assert(res.msg && res.msg == "isdbgrid", "msg possibly missing or wrong:" + tojson(res));
diff --git a/src/mongo/s/commands/cluster_is_master_cmd.cpp b/src/mongo/s/commands/cluster_is_master_cmd.cpp
index ed3f8181d4c..490605fbefe 100644
--- a/src/mongo/s/commands/cluster_is_master_cmd.cpp
+++ b/src/mongo/s/commands/cluster_is_master_cmd.cpp
@@ -83,6 +83,12 @@ public:
const BSONObj& cmdObj,
BSONObjBuilder& result) override {
CommandHelpers::handleMarkKillOnClientDisconnect(opCtx);
+
+ // 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".
+ bool useLegacyResponseFields = (cmdObj.firstElementFieldNameStringData() != kHelloString);
+
auto& clientMetadataIsMasterState = ClientMetadataIsMasterState::get(opCtx->getClient());
bool seenIsMaster = clientMetadataIsMasterState.hasSeenIsMaster();
if (!seenIsMaster) {
@@ -112,7 +118,11 @@ public:
opCtx->getClient(), std::move(swParseClientMetadata.getValue()));
}
- result.appendBool("ismaster", true);
+ if (useLegacyResponseFields) {
+ result.appendBool("ismaster", true);
+ } else {
+ result.appendBool("isWritablePrimary", true);
+ }
result.append("msg", "isdbgrid");
result.appendNumber("maxBsonObjectSize", BSONObjMaxUserSize);
result.appendNumber("maxMessageSizeBytes", MaxMessageSizeBytes);