summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavi Vetriselvan <pavithra.vetriselvan@mongodb.com>2020-11-05 11:32:11 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-03-15 13:28:56 +0000
commit53da5624fe9afaa5751cc34d7806dee652004303 (patch)
tree1785113ad096f6c3124933b8fbe5eb328cec9b18
parent4dbefcfc9304a9ffa1fec8390dc2bd30e0dc9a54 (diff)
downloadmongo-53da5624fe9afaa5751cc34d7806dee652004303.tar.gz
SERVER-50412 implement helloOk protocol negotiation on mongos
(cherry picked from commit fc1b099c92ea269875e52c07f8f02a94bbb3a906)
-rw-r--r--etc/backports_required_for_multiversion_tests.yml2
-rw-r--r--jstests/sharding/mongos_helloOk_protocol.js26
-rw-r--r--src/mongo/s/commands/cluster_is_master_cmd.cpp15
3 files changed, 43 insertions, 0 deletions
diff --git a/etc/backports_required_for_multiversion_tests.yml b/etc/backports_required_for_multiversion_tests.yml
index 22aba039b62..cfac01f0093 100644
--- a/etc/backports_required_for_multiversion_tests.yml
+++ b/etc/backports_required_for_multiversion_tests.yml
@@ -119,6 +119,8 @@ all:
test_file: jstests/core/geo_near_point_query.js
- ticket: SERVER-50412
test_file: jstests/replsets/not_primary_errors_returned_if_client_sends_helloOk.js
+ - ticket: SERVER-50412
+ test_file: jstests/sharding/mongos_helloOk_protocol.js
suites:
diff --git a/jstests/sharding/mongos_helloOk_protocol.js b/jstests/sharding/mongos_helloOk_protocol.js
new file mode 100644
index 00000000000..2579d0404a6
--- /dev/null
+++ b/jstests/sharding/mongos_helloOk_protocol.js
@@ -0,0 +1,26 @@
+/*
+ * Tests that when a client sends "helloOk: true" as a part of their isMaster request, mongos
+ * will respond with helloOk: true. This ensures that the client knows it can send the hello
+ * command.
+ *
+ * In practice, drivers will send "helloOk: true" in the initial handshake when
+ * opening a connection to the database.
+ */
+(function() {
+"use strict";
+const st = new ShardingTest({shards: 1, mongos: 1});
+const mongos = st.s;
+
+// Simulate an initial handshake request without "helloOk: true". Mongos should not return
+// "helloOk: true" in its response.
+let res = assert.commandWorked(mongos.adminCommand({isMaster: 1}));
+assert.eq(res.helloOk, undefined);
+
+// Simulate an initial handshake request with "helloOk: true". Mongos should now return
+// "helloOk: true" in its response.
+res = assert.commandWorked(mongos.adminCommand({isMaster: 1, helloOk: true}));
+assert.eq("boolean", typeof res.helloOk, "helloOk field is not a boolean" + tojson(res));
+assert.eq(res.helloOk, true);
+
+st.stop();
+})(); \ No newline at end of file
diff --git a/src/mongo/s/commands/cluster_is_master_cmd.cpp b/src/mongo/s/commands/cluster_is_master_cmd.cpp
index 0401d196be5..14ae6d27ae8 100644
--- a/src/mongo/s/commands/cluster_is_master_cmd.cpp
+++ b/src/mongo/s/commands/cluster_is_master_cmd.cpp
@@ -187,12 +187,27 @@ public:
}
auto result = replyBuilder->getBodyBuilder();
+
if (useLegacyResponseFields()) {
result.appendBool("ismaster", true);
} else {
result.appendBool("isWritablePrimary", true);
}
result.append("msg", "isdbgrid");
+
+ // Try to parse the optional 'helloOk' field. On mongos, if we see this field, we will
+ // respond with helloOk: true so the client knows that it can continue to send the hello
+ // command to mongos.
+ bool helloOk;
+ Status status = bsonExtractBooleanField(cmdObj, "helloOk", &helloOk);
+ if (status.isOK()) {
+ // Attach helloOk: true to the response so that the client knows the server supports
+ // the hello command.
+ result.append("helloOk", true);
+ } else if (status.code() != ErrorCodes::NoSuchKey) {
+ uassertStatusOK(status);
+ }
+
result.appendNumber("maxBsonObjectSize", BSONObjMaxUserSize);
result.appendNumber("maxMessageSizeBytes", MaxMessageSizeBytes);
result.appendNumber("maxWriteBatchSize", write_ops::kMaxWriteBatchSize);