diff options
author | Pavi Vetriselvan <pavithra.vetriselvan@mongodb.com> | 2020-08-06 09:49:48 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-09-16 01:41:14 +0000 |
commit | c18aec098f8d604b5cce4a9c8bc14e37b53a4a25 (patch) | |
tree | fbd3b6b2d518d08ff9176ec4fadd9b6e115cc9b9 | |
parent | 5c22d7a3271ccb6b31e52557bc3d484deebb7f12 (diff) | |
download | mongo-c18aec098f8d604b5cce4a9c8bc14e37b53a4a25.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.js | 6 | ||||
-rw-r--r-- | jstests/sharding/ismaster.js | 13 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_is_master_cmd.cpp | 11 |
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 d6e2c1b1187..e4876f7c1a7 100644 --- a/src/mongo/s/commands/cluster_is_master_cmd.cpp +++ b/src/mongo/s/commands/cluster_is_master_cmd.cpp @@ -84,6 +84,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) { @@ -118,7 +123,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); |