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>2020-11-09 01:56:39 +0000
commitfc1b099c92ea269875e52c07f8f02a94bbb3a906 (patch)
treefeaea939418d62ad1f78d8fbb4ed1027835d9d0d
parent74648046a74da68b167fbf43742f9d702b5c282d (diff)
downloadmongo-fc1b099c92ea269875e52c07f8f02a94bbb3a906.tar.gz
SERVER-50412 implement helloOk protocol negotiation on mongos
-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.cpp13
3 files changed, 41 insertions, 0 deletions
diff --git a/etc/backports_required_for_multiversion_tests.yml b/etc/backports_required_for_multiversion_tests.yml
index 86ad5ec743f..8a2384b0a56 100644
--- a/etc/backports_required_for_multiversion_tests.yml
+++ b/etc/backports_required_for_multiversion_tests.yml
@@ -104,6 +104,8 @@ all:
test_file: jstests/sharding/mongos_quiesce_mode.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
# Tests that should only be excluded from particular suites should be listed under that suite.
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 1ae4b497576..1579d99843b 100644
--- a/src/mongo/s/commands/cluster_is_master_cmd.cpp
+++ b/src/mongo/s/commands/cluster_is_master_cmd.cpp
@@ -144,6 +144,19 @@ public:
// The isMaster response always includes a topologyVersion.
auto currentMongosTopologyVersion = mongosIsMasterResponse->getTopologyVersion();
+ // 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);