Skip to content

Commit b995503

Browse files
authored
DRIVERS-2033 Require hello command + OP_MSG when 'loadBalanced=True' (#1123)
1 parent 568093c commit b995503

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

source/load-balancers/load-balancers.rst

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Load Balancer Support
99
:Status: Accepted
1010
:Type: Standards
1111
:Minimum Server Version: 5.0
12-
:Last Modified: 2021-12-22
12+
:Last Modified: 2022-01-18
1313

1414
.. contents::
1515

@@ -163,8 +163,10 @@ Connection Establishment
163163

164164
In the case of the driver having the :code:`loadBalanced=true` connection string option
165165
specified, every pooled connection MUST add a :code:`loadBalanced` field to the
166-
:code:`hello` or legacy hello command in its `handshake <../mongodb-handshake/handshake.rst#connection-handshake>`__.
167-
The value of the field MUST be :code:`true`.
166+
:code:`hello` command in its `handshake <../mongodb-handshake/handshake.rst#connection-handshake>`__.
167+
The value of the field MUST be :code:`true`. If :code:`loadBalanced=true` is
168+
specified then the ``OP_MSG`` protocol MUST be used for all steps of the
169+
connection handshake.
168170

169171
Example:
170172

@@ -263,7 +265,7 @@ Initial Handshake Errors
263265

264266
When establishing a new connection in load balanced mode, drivers MUST NOT perform SDAM
265267
error handling for any errors that occur before the MongoDB Handshake
266-
(i.e. :code:`hello` or legacy hello command) is complete. Errors during the MongoDB
268+
(i.e. :code:`hello` command) is complete. Errors during the MongoDB
267269
Handshake MUST also be ignored for SDAM error handling purposes. Once the initial
268270
handshake is complete, the connection MUST determine its generation number based
269271
on the :code:`serviceId` field in the handshake response. Any errors that occur
@@ -308,7 +310,7 @@ All services which terminate TLS MUST be configured to return a TLS certificate
308310
which matches the hostname the client is connecting to.
309311

310312
All services behind a load balancer that have been started with the aforementioned option MUST
311-
add a top level :code:`serviceId` field to their response to the :code:`hello` or legacy hello
313+
add a top level :code:`serviceId` field to their response to the :code:`hello`
312314
command. This field MUST be a BSON :code:`ObjectId` and SHOULD NOT change while the service is running.
313315
When a driver is configured to not be in load balanced mode and the service is configured behind
314316
a load balancer, the service MAY return an error from the driver's :code:`hello` command that
@@ -342,7 +344,7 @@ Why explicitly opt-in to this behaviour instead of letting mongos inform the dri
342344
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
343345

344346
Other versions of this design proposed a scheme in which the application does not have to opt-in to
345-
load balanced mode. Instead, the server would send a special field in :code:`hello` and legacy hello
347+
load balanced mode. Instead, the server would send a special field in :code:`hello`
346348
command responses to indicate that it was running behind a load balancer and the driver would change
347349
its behavior accordingly. We opted to take an approach that required code changes instead because
348350
load balancing changes driver behavior in ways that could cause unexpected application errors, so
@@ -424,6 +426,6 @@ be supported.
424426

425427
Change Log
426428
==========
427-
429+
- 2022-01-18: Clarify that ``OP_MSG`` must be used in load balanced mode.
428430
- 2021-12-22: Clarify that pinned connections in transactions are exclusive.
429431
- 2021-10-14: Note that ``loadBalanced=true`` conflicts with ``srvMaxHosts``.

source/mongodb-handshake/handshake.rst

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,12 @@ always be sent using the ``OP_MSG`` protocol. ``isMaster`` is referred to as
7676
that do not support the ``hello`` command.
7777

7878
If a `server API version <../versioned-api/versioned-api.rst>`__ is
79-
requested drivers MUST use the ``hello`` command
79+
requested or ``loadBalanced: True``, drivers MUST use the ``hello`` command
8080
for the initial handshake and use the ``OP_MSG`` protocol. If server API
81-
version is not requested drivers MUST
82-
use legacy hello for the first message of the initial handshake with the
83-
``OP_QUERY`` protocol (before switching to ``OP_MSG`` if the
84-
``maxWireVersion`` indicates compatibility), and include ``helloOk:true``in
85-
the handshake request.
81+
version is not requested and ``loadBalanced: False``, drivers MUST use legacy
82+
hello for the first message of the initial handshake with the ``OP_QUERY``
83+
protocol (before switching to ``OP_MSG`` if the ``maxWireVersion`` indicates
84+
compatibility), and include ``helloOk:true`` in the handshake request.
8685

8786
ASIDE: If the legacy handshake response includes ``helloOk: true``, then
8887
subsequent topology monitoring commands MUST use the ``hello`` command. If the
@@ -113,7 +112,7 @@ Consider the following pseudo-code for establishing a new connection:
113112
114113
conn = Connection()
115114
conn.connect() # Connect via TCP / TLS
116-
if versioned_api_configured:
115+
if versioned_api_configured or client_options.load_balanced:
117116
cmd = {"hello": 1}
118117
conn.supports_op_msg = True # Send the initial command via OP_MSG.
119118
else:

0 commit comments

Comments
 (0)