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-15 12:06:53 +0000
commit33b4c37fde21018a23e7068afe3aea035fdeb141 (patch)
tree0685d21aff2754738d21130b5f58e2d1353e0525
parent33cac55a20a8cf5d1d1e93fb370af09abceed998 (diff)
downloadmongo-33b4c37fde21018a23e7068afe3aea035fdeb141.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.cpp11
3 files changed, 23 insertions, 7 deletions
diff --git a/jstests/core/ismaster.js b/jstests/core/ismaster.js
index 985eeb3ed8d..4f2b41c64f7 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));
@@ -55,6 +55,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 a8321dabad6..fa5257b1fd5 100644
--- a/src/mongo/s/commands/cluster_is_master_cmd.cpp
+++ b/src/mongo/s/commands/cluster_is_master_cmd.cpp
@@ -85,6 +85,11 @@ public:
const std::string& dbname,
const BSONObj& cmdObj,
BSONObjBuilder& result) override {
+ // 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.firstElementFieldName() != kHelloString);
+
auto& clientMetadataIsMasterState = ClientMetadataIsMasterState::get(opCtx->getClient());
bool seenIsMaster = clientMetadataIsMasterState.hasSeenIsMaster();
if (!seenIsMaster) {
@@ -114,7 +119,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);