@@ -10,8 +10,8 @@ Initial DNS Seedlist Discovery
1010:Authors: Derick Rethans
1111:Status: Draft
1212:Type: Standards
13- :Last Modified: 2019-03-07
14- :Version: 1.3.2
13+ :Last Modified: 2021-10-14
14+ :Version: 1.6.0
1515:Spec Lead: Matt Broadstone
1616:Advisory Group: \A . Jesse Jiryu Davis
1717:Approver(s): Bernie Hackett, David Golden, Jeff Yemin, Matt Broadstone, A. Jesse Jiryu Davis
@@ -48,6 +48,9 @@ interpreted as described in `RFC 2119 <https://www.ietf.org/rfc/rfc2119.txt>`_.
4848Specification
4949=============
5050
51+ Connection String Format
52+ ------------------------
53+
5154The connection string parser in the driver is extended with a new protocol
5255``mongodb+srv `` as a logical pre-processing step before it considers the
5356connection string and SDAM specifications. In this protocol, the comma
@@ -61,33 +64,59 @@ format is::
6164specification following the ``Host Information ``. This includes the ``Auth
6265database `` and ``Connection Options ``.
6366
64- Seedlist Discovery
65- ------------------
6667
67- In this preprocessing step, the driver will query the DNS server for SRV
68- records on ``{hostname}.{domainname} ``, prefixed with ``_mongodb._tcp. ``:
69- ``_mongodb._tcp.{hostname}.{domainname} ``. This DNS query is expected to
70- respond with one or more SRV records. From the DNS result, the driver now MUST
71- behave the same as if an ``mongodb:// `` URI was provided with all the host
72- names and port numbers that were returned as part of the DNS SRV query result.
68+ MongoClient Configuration
69+ -------------------------
7370
74- The priority and weight fields in returned SRV records MUST be ignored.
71+ srvMaxHosts
72+ ~~~~~~~~~~~
7573
76- If ``mongodb+srv `` is used, a driver MUST implicitly also enable TLS. Clients
77- can turn this off by passing ``ssl=false `` in either the Connection String,
78- or options passed in as parameters in code to the MongoClient constructor (or
79- equivalent API for each driver), but not through a TXT record (discussed in
80- the next section).
74+ This option is used to limit the number of mongos connections that may be
75+ created for sharded topologies. This option limits the number of SRV records
76+ used to populate the seedlist during initial discovery, as well as the number of
77+ additional hosts that may be added during
78+ `SRV polling <../polling-srv-records-for-mongos-discovery/polling-srv-records-for-mongos-discovery.rst >`_.
79+ This option requires a non-negative integer and defaults to zero (i.e. no
80+ limit). This option MUST only be configurable at the level of a ``MongoClient ``.
8181
82- A driver MUST verify that in addition to the ``{hostname} ``, the
83- ``{domainname} `` consists of at least two parts: the domain name, and a TLD.
84- Drivers MUST raise an error and MUST NOT contact the DNS server to obtain SRV
85- (or TXT records) if the full URI does not consists of at least three parts.
8682
87- A driver MUST verify that the host names returned through SRV records have the
88- same parent ``{domainname} ``. Drivers MUST raise an error and MUST NOT
89- initiate a connection to any returned host name which does not share the same
90- ``{domainname} ``.
83+ srvServiceName
84+ ~~~~~~~~~~~~~~
85+
86+ This option specifies a valid SRV service name according to
87+ `RFC 6335 <https://datatracker.ietf.org/doc/html/rfc6335#section-5.1 >`_, with
88+ the exception that it may exceed 15 characters as long as the 63rd (62nd with
89+ prepended underscore) character DNS query limit is not surpassed. This option
90+ requires a string value and defaults to "mongodb". This option MUST only be
91+ configurable at the level of a ``MongoClient ``.
92+
93+
94+ URI Validation
95+ ~~~~~~~~~~~~~~
96+
97+ The driver MUST report an error if either the ``srvServiceName `` or
98+ ``srvMaxHosts `` URI options are specified with a non-SRV URI (i.e. scheme other
99+ than ``mongodb+srv ``). The driver MUST allow specifying the ``srvServiceName ``
100+ and ``srvMaxHosts `` URI options with an SRV URI (i.e. ``mongodb+srv `` scheme).
101+
102+ If ``srvMaxHosts `` is a positive integer, the driver MUST throw an error in the
103+ following cases:
104+
105+ - The connection string contains a ``replicaSet `` option.
106+ - The connection string contains a ``loadBalanced `` option with a value of
107+ ``true ``.
108+
109+ When validating URI options, the driver MUST first do the SRV and TXT lookup and
110+ then perform the validation. For drivers that do SRV lookup asynchronously this
111+ may result in a ``MongoClient `` being instantiated but erroring later during
112+ operation execution.
113+
114+
115+ Seedlist Discovery
116+ ------------------
117+
118+ Validation Before Querying DNS
119+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
91120
92121It is an error to specify a port in a connection string with the
93122``mongodb+srv `` protocol, and the driver MUST raise a parse error and MUST NOT
@@ -97,14 +126,54 @@ It is an error to specify more than one host name in a connection string with
97126the ``mongodb+srv `` protocol, and the driver MUST raise a parse error and MUST
98127NOT do DNS resolution or contact hosts.
99128
100- The driver MUST NOT attempt to connect to any hosts until the DNS query has
101- returned its results.
129+ A driver MUST verify that in addition to the ``{hostname} ``, the
130+ ``{domainname} `` consists of at least two parts: the domain name, and a TLD.
131+ Drivers MUST raise an error and MUST NOT contact the DNS server to obtain SRV
132+ (or TXT records) if the full URI does not consist of at least three parts.
133+
134+ If ``mongodb+srv `` is used, a driver MUST implicitly also enable TLS. Clients
135+ can turn this off by passing ``tls=false `` in either the Connection String,
136+ or options passed in as parameters in code to the MongoClient constructor (or
137+ equivalent API for each driver), but not through a TXT record (discussed in a
138+ later section).
139+
140+
141+ Querying DNS
142+ ~~~~~~~~~~~~
143+
144+ In this preprocessing step, the driver will query the DNS server for SRV records
145+ on ``{hostname}.{domainname} ``, prefixed with the SRV service name and protocol.
146+ The SRV service name is provided in the ``srvServiceName `` URI option and
147+ defaults to ``mongodb ``. The protocol is always ``tcp ``. After prefixing, the
148+ URI should look like: ``_{srvServiceName}._tcp.{hostname}.{domainname} ``. This
149+ DNS query is expected to respond with one or more SRV records.
150+
151+ The priority and weight fields in returned SRV records MUST be ignored.
102152
103153If the DNS result returns no SRV records, or no records at all, or a DNS error
104154happens, an error MUST be raised indicating that the URI could not be used to
105155find hostnames. The error SHALL include the reason why they could not be
106156found.
107157
158+ A driver MUST verify that the host names returned through SRV records have the
159+ same parent ``{domainname} ``. Drivers MUST raise an error and MUST NOT
160+ initiate a connection to any returned host name which does not share the same
161+ ``{domainname} ``.
162+
163+ The driver MUST NOT attempt to connect to any hosts until the DNS query has
164+ returned its results.
165+
166+ If ``srvMaxHosts `` is zero or greater than or equal to the number of hosts in
167+ the DNS result, the driver MUST populate the seedlist with all hosts.
168+
169+ If ``srvMaxHosts `` is greater than zero and less than the number of hosts in the
170+ DNS result, the driver MUST randomly select that many hosts and use them to
171+ populate the seedlist. Drivers SHOULD use the `Fisher-Yates shuffle `_ for
172+ randomization.
173+
174+ .. _`Fisher-Yates shuffle` : https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm
175+
176+
108177Default Connection String Options
109178---------------------------------
110179
@@ -122,8 +191,8 @@ raise an error when multiple TXT records are encountered.
122191Information returned within a TXT record is a simple URI string, just like
123192the ``{options} `` in a connection string.
124193
125- A Client MUST only support the ``authSource `` and ``replicaSet `` options
126- through a TXT record, and MUST raise an error if any other option is
194+ A Client MUST only support the ``authSource ``, ``replicaSet ``, and `` loadBalanced ``
195+ options through a TXT record, and MUST raise an error if any other option is
127196encountered. Although using ``mongodb+srv:// `` implicitly enables TLS, a
128197Client MUST NOT allow the ``ssl `` option to be set through a TXT record
129198option.
@@ -274,6 +343,18 @@ SRV records.
274343ChangeLog
275344=========
276345
346+ 2021-10-14 - 1.6.0
347+ Add ``srvMaxHosts `` MongoClient option and restructure Seedlist Discovery
348+ section. Improve documentation for the ``srvServiceName `` MongoClient
349+ option and add a new URI Validation section.
350+
351+ 2021-09-15 - 1.5.0
352+ Clarify that service name only defaults to ``mongodb ``, and should be
353+ defined by the ``srvServiceName `` URI option.
354+
355+ 2021-04-15 - 1.4.0
356+ Adding in behaviour for load balancer mode.
357+
2773582019-03-07 - 1.3.2
278359 Clarify that CNAME is not supported
279360
0 commit comments