@@ -10,8 +10,8 @@ Initial DNS Seedlist Discovery
10
10
:Authors: Derick Rethans
11
11
:Status: Draft
12
12
:Type: Standards
13
- :Last Modified: 2021-09-15
14
- :Version: 1.5 .0
13
+ :Last Modified: 2021-10-14
14
+ :Version: 1.6 .0
15
15
:Spec Lead: Matt Broadstone
16
16
:Advisory Group: \A . Jesse Jiryu Davis
17
17
: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>`_.
48
48
Specification
49
49
=============
50
50
51
+ Connection String Format
52
+ ------------------------
53
+
51
54
The connection string parser in the driver is extended with a new protocol
52
55
``mongodb+srv `` as a logical pre-processing step before it considers the
53
56
connection string and SDAM specifications. In this protocol, the comma
@@ -61,35 +64,59 @@ format is::
61
64
specification following the ``Host Information ``. This includes the ``Auth
62
65
database `` and ``Connection Options ``.
63
66
64
- Seedlist Discovery
65
- ------------------
66
67
67
- In this preprocessing step, the driver will query the DNS server for SRV
68
- records on ``{hostname}.{domainname} ``, prefixed with the SRV service name
69
- and protocol. The SRV service name is provided in the ``srvServiceName `` URI option and
70
- defaults to ``mongodb ``. The protocol is always ``tcp ``. After prefixing, the URI
71
- should look like: ``_{srvServiceName}._tcp.{hostname}.{domainname} ``. This DNS query
72
- is expected to respond with one or more SRV records. The driver MUST add all the host
73
- names and port numbers that were returned as part of the DNS SRV query result to the
74
- seedlist.
68
+ MongoClient Configuration
69
+ -------------------------
75
70
76
- The priority and weight fields in returned SRV records MUST be ignored.
71
+ srvMaxHosts
72
+ ~~~~~~~~~~~
77
73
78
- If ``mongodb+srv `` is used, a driver MUST implicitly also enable TLS. Clients
79
- can turn this off by passing ``ssl=false `` in either the Connection String,
80
- or options passed in as parameters in code to the MongoClient constructor (or
81
- equivalent API for each driver), but not through a TXT record (discussed in
82
- 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 ``.
83
81
84
- A driver MUST verify that in addition to the ``{hostname} ``, the
85
- ``{domainname} `` consists of at least two parts: the domain name, and a TLD.
86
- Drivers MUST raise an error and MUST NOT contact the DNS server to obtain SRV
87
- (or TXT records) if the full URI does not consists of at least three parts.
88
82
89
- A driver MUST verify that the host names returned through SRV records have the
90
- same parent ``{domainname} ``. Drivers MUST raise an error and MUST NOT
91
- initiate a connection to any returned host name which does not share the same
92
- ``{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
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
93
120
94
121
It is an error to specify a port in a connection string with the
95
122
``mongodb+srv `` protocol, and the driver MUST raise a parse error and MUST NOT
@@ -99,14 +126,54 @@ It is an error to specify more than one host name in a connection string with
99
126
the ``mongodb+srv `` protocol, and the driver MUST raise a parse error and MUST
100
127
NOT do DNS resolution or contact hosts.
101
128
102
- The driver MUST NOT attempt to connect to any hosts until the DNS query has
103
- 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.
104
152
105
153
If the DNS result returns no SRV records, or no records at all, or a DNS error
106
154
happens, an error MUST be raised indicating that the URI could not be used to
107
155
find hostnames. The error SHALL include the reason why they could not be
108
156
found.
109
157
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
+
110
177
Default Connection String Options
111
178
---------------------------------
112
179
@@ -276,6 +343,11 @@ SRV records.
276
343
ChangeLog
277
344
=========
278
345
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
+
279
351
2021-09-15 - 1.5.0
280
352
Clarify that service name only defaults to ``mongodb ``, and should be
281
353
defined by the ``srvServiceName `` URI option.
0 commit comments