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-17 01:12:55 +0000
commitdeb0d4434518321c65bb264558dd957c53cfd434 (patch)
tree738a883fde61320f756f8c814d1c5d66bb7451c4
parent0aa0aad87fdd50f98abe0640385ab5a2bc443928 (diff)
downloadmongo-deb0d4434518321c65bb264558dd957c53cfd434.tar.gz
SERVER-50412 implement helloOk protocol negotiation on mongos
(cherry picked from commit fc1b099c92ea269875e52c07f8f02a94bbb3a906) (cherry picked from commit 53da5624fe9afaa5751cc34d7806dee652004303)
-rw-r--r--buildscripts/resmokeconfig/suites/sharding_last_stable_mongos_and_mixed_shards.yml2
-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
4 files changed, 45 insertions, 0 deletions
diff --git a/buildscripts/resmokeconfig/suites/sharding_last_stable_mongos_and_mixed_shards.yml b/buildscripts/resmokeconfig/suites/sharding_last_stable_mongos_and_mixed_shards.yml
index 95a049e468c..6a34cf5edfa 100644
--- a/buildscripts/resmokeconfig/suites/sharding_last_stable_mongos_and_mixed_shards.yml
+++ b/buildscripts/resmokeconfig/suites/sharding_last_stable_mongos_and_mixed_shards.yml
@@ -175,6 +175,8 @@ selector:
- jstests/sharding/kill_pinned_cursor.js
# Uses the ShardingTaskExecutorPoolReplicaSetMatching parameter which does not exist on 4.0.
- jstests/sharding/sharding_task_executor_pool_matching_policy.js
+ # Enable the following once SERVER-50412 is backported to 4.0. "helloOk" does not exist on 4.0.
+ - jstests/sharding/mongos_helloOk_protocol.js
executor:
config:
shell_options:
diff --git a/etc/backports_required_for_multiversion_tests.yml b/etc/backports_required_for_multiversion_tests.yml
index bd64ec3b1e2..1c575e036c8 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/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
# 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 4a7ecc1aa02..260e15800f8 100644
--- a/src/mongo/s/commands/cluster_is_master_cmd.cpp
+++ b/src/mongo/s/commands/cluster_is_master_cmd.cpp
@@ -30,6 +30,7 @@
#include "mongo/platform/basic.h"
#include "mongo/base/string_data.h"
+#include "mongo/bson/util/bson_extract.h"
#include "mongo/db/auth/sasl_mechanism_registry.h"
#include "mongo/db/client.h"
#include "mongo/db/commands.h"
@@ -118,6 +119,20 @@ public:
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);