Skip to content

Commit 2fa2b7c

Browse files
authored
GODRIVER-2092 Add srvMaxHosts URI option (#764)
1 parent 0bef69c commit 2fa2b7c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+646
-49
lines changed

data/initial-dns-seedlist-discovery/README.rst

Lines changed: 84 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,22 @@ to prove their conformance to the Initial DNS Seedlist Discovery spec.
88
Test Setup
99
----------
1010

11-
Start a three-node replica set on localhost, on ports 27017, 27018, and 27019,
12-
with replica set name "repl0". The replica set MUST be started with SSL
13-
enabled.
11+
The tests in the ``replica-set`` directory MUST be executed against a
12+
three-node replica set on localhost ports 27017, 27018, and 27019 with
13+
replica set name ``repl0``.
14+
15+
The tests in the ``load-balanced`` directory MUST be executed against a
16+
load-balanced sharded cluster with the mongos servers running on localhost ports
17+
27017 and 27018 (corresponding to the script in `drivers-evergreen-tools`_). The
18+
load balancers, shard servers, and config servers may run on any open ports.
19+
20+
.. _`drivers-evergreen-tools`: ../../connection-string/connection-string-spec.rst
21+
22+
The tests in the ``sharded`` directory MUST be executed against a sharded
23+
cluster with the mongos servers running on localhost ports 27017 and 27018.
24+
Shard servers and config servers may run on any open ports.
25+
26+
In all cases, the clusters MUST be started with SSL enabled.
1427

1528
To run the tests that accompany this spec, you need to configure the SRV and
1629
TXT records with a real name server. The following records are required for
@@ -20,27 +33,30 @@ these tests::
2033
localhost.test.build.10gen.cc. 86400 IN A 127.0.0.1
2134
localhost.sub.test.build.10gen.cc. 86400 IN A 127.0.0.1
2235

23-
Record TTL Class Port Target
24-
_mongodb._tcp.test1.test.build.10gen.cc. 86400 IN SRV 27017 localhost.test.build.10gen.cc.
25-
_mongodb._tcp.test1.test.build.10gen.cc. 86400 IN SRV 27018 localhost.test.build.10gen.cc.
26-
_mongodb._tcp.test2.test.build.10gen.cc. 86400 IN SRV 27018 localhost.test.build.10gen.cc.
27-
_mongodb._tcp.test2.test.build.10gen.cc. 86400 IN SRV 27019 localhost.test.build.10gen.cc.
28-
_mongodb._tcp.test3.test.build.10gen.cc. 86400 IN SRV 27017 localhost.test.build.10gen.cc.
29-
_mongodb._tcp.test5.test.build.10gen.cc. 86400 IN SRV 27017 localhost.test.build.10gen.cc.
30-
_mongodb._tcp.test6.test.build.10gen.cc. 86400 IN SRV 27017 localhost.test.build.10gen.cc.
31-
_mongodb._tcp.test7.test.build.10gen.cc. 86400 IN SRV 27017 localhost.test.build.10gen.cc.
32-
_mongodb._tcp.test8.test.build.10gen.cc. 86400 IN SRV 27017 localhost.test.build.10gen.cc.
33-
_mongodb._tcp.test10.test.build.10gen.cc. 86400 IN SRV 27017 localhost.test.build.10gen.cc.
34-
_mongodb._tcp.test11.test.build.10gen.cc. 86400 IN SRV 27017 localhost.test.build.10gen.cc.
35-
_mongodb._tcp.test12.test.build.10gen.cc. 86400 IN SRV 27017 localhost.build.10gen.cc.
36-
_mongodb._tcp.test13.test.build.10gen.cc. 86400 IN SRV 27017 test.build.10gen.cc.
37-
_mongodb._tcp.test14.test.build.10gen.cc. 86400 IN SRV 27017 localhost.not-test.build.10gen.cc.
38-
_mongodb._tcp.test15.test.build.10gen.cc. 86400 IN SRV 27017 localhost.test.not-build.10gen.cc.
39-
_mongodb._tcp.test16.test.build.10gen.cc. 86400 IN SRV 27017 localhost.test.build.not-10gen.cc.
40-
_mongodb._tcp.test17.test.build.10gen.cc. 86400 IN SRV 27017 localhost.test.build.10gen.not-cc.
41-
_mongodb._tcp.test18.test.build.10gen.cc. 86400 IN SRV 27017 localhost.sub.test.build.10gen.cc.
42-
_mongodb._tcp.test19.test.build.10gen.cc. 86400 IN SRV 27017 localhost.evil.build.10gen.cc.
43-
_mongodb._tcp.test19.test.build.10gen.cc. 86400 IN SRV 27017 localhost.test.build.10gen.cc.
36+
Record TTL Class Port Target
37+
_mongodb._tcp.test1.test.build.10gen.cc. 86400 IN SRV 27017 localhost.test.build.10gen.cc.
38+
_mongodb._tcp.test1.test.build.10gen.cc. 86400 IN SRV 27018 localhost.test.build.10gen.cc.
39+
_mongodb._tcp.test2.test.build.10gen.cc. 86400 IN SRV 27018 localhost.test.build.10gen.cc.
40+
_mongodb._tcp.test2.test.build.10gen.cc. 86400 IN SRV 27019 localhost.test.build.10gen.cc.
41+
_mongodb._tcp.test3.test.build.10gen.cc. 86400 IN SRV 27017 localhost.test.build.10gen.cc.
42+
_mongodb._tcp.test5.test.build.10gen.cc. 86400 IN SRV 27017 localhost.test.build.10gen.cc.
43+
_mongodb._tcp.test6.test.build.10gen.cc. 86400 IN SRV 27017 localhost.test.build.10gen.cc.
44+
_mongodb._tcp.test7.test.build.10gen.cc. 86400 IN SRV 27017 localhost.test.build.10gen.cc.
45+
_mongodb._tcp.test8.test.build.10gen.cc. 86400 IN SRV 27017 localhost.test.build.10gen.cc.
46+
_mongodb._tcp.test10.test.build.10gen.cc. 86400 IN SRV 27017 localhost.test.build.10gen.cc.
47+
_mongodb._tcp.test11.test.build.10gen.cc. 86400 IN SRV 27017 localhost.test.build.10gen.cc.
48+
_mongodb._tcp.test12.test.build.10gen.cc. 86400 IN SRV 27017 localhost.build.10gen.cc.
49+
_mongodb._tcp.test13.test.build.10gen.cc. 86400 IN SRV 27017 test.build.10gen.cc.
50+
_mongodb._tcp.test14.test.build.10gen.cc. 86400 IN SRV 27017 localhost.not-test.build.10gen.cc.
51+
_mongodb._tcp.test15.test.build.10gen.cc. 86400 IN SRV 27017 localhost.test.not-build.10gen.cc.
52+
_mongodb._tcp.test16.test.build.10gen.cc. 86400 IN SRV 27017 localhost.test.build.not-10gen.cc.
53+
_mongodb._tcp.test17.test.build.10gen.cc. 86400 IN SRV 27017 localhost.test.build.10gen.not-cc.
54+
_mongodb._tcp.test18.test.build.10gen.cc. 86400 IN SRV 27017 localhost.sub.test.build.10gen.cc.
55+
_mongodb._tcp.test19.test.build.10gen.cc. 86400 IN SRV 27017 localhost.evil.build.10gen.cc.
56+
_mongodb._tcp.test19.test.build.10gen.cc. 86400 IN SRV 27017 localhost.test.build.10gen.cc.
57+
_mongodb._tcp.test20.test.build.10gen.cc. 86400 IN SRV 27017 localhost.test.build.10gen.cc.
58+
_mongodb._tcp.test21.test.build.10gen.cc. 86400 IN SRV 27017 localhost.test.build.10gen.cc.
59+
_customname._tcp.test22.test.build.10gen.cc 86400 IN SRV 27017 localhost.test.build.10gen.cc
4460

4561
Record TTL Class Text
4662
test5.test.build.10gen.cc. 86400 IN TXT "replicaSet=repl0&authSource=thisDB"
@@ -50,11 +66,14 @@ these tests::
5066
test8.test.build.10gen.cc. 86400 IN TXT "authSource"
5167
test10.test.build.10gen.cc. 86400 IN TXT "socketTimeoutMS=500"
5268
test11.test.build.10gen.cc. 86400 IN TXT "replicaS" "et=rep" "l0"
69+
test20.test.build.10gen.cc. 86400 IN TXT "loadBalanced=true"
70+
test21.test.build.10gen.cc. 86400 IN TXT "loadBalanced=false"
5371

5472
Note that ``test4`` is omitted deliberately to test what happens with no SRV
5573
record. ``test9`` is missing because it was deleted during the development of
5674
the tests. The missing ``test.`` sub-domain in the SRV record target for
57-
``test12`` is deliberate.
75+
``test12`` is deliberate. ``test22`` is used to test a custom service name
76+
(``customname``).
5877

5978
In our tests we have used ``localhost.test.build.10gen.cc`` as the domain, and
6079
then configured ``localhost.test.build.10gen.cc`` to resolve to 127.0.0.1.
@@ -68,20 +87,49 @@ Test Format and Use
6887

6988
These YAML and JSON files contain the following fields:
7089

71-
- ``uri``: a mongodb+srv connection string
90+
- ``uri``: a ``mongodb+srv`` connection string
7291
- ``seeds``: the expected set of initial seeds discovered from the SRV record
92+
- ``numSeeds``: the expected number of initial seeds discovered from the SRV
93+
record. This is mainly used to test ``srvMaxHosts``, since randomly selected
94+
hosts cannot be deterministically asserted.
7395
- ``hosts``: the discovered topology's list of hosts once SDAM completes a scan
74-
- ``options``: the parsed connection string options as discovered from URI and
75-
TXT records
96+
- ``numHosts``: the expected number of hosts discovered once SDAM completes a
97+
scan. This is mainly used to test ``srvMaxHosts``, since randomly selected
98+
hosts cannot be deterministically asserted.
99+
- ``options``: the parsed `URI options`_ as discovered from the
100+
`Connection String`_'s "Connection Options" component and SRV resolution
101+
(e.g. TXT records, implicit ``ssl`` default).
102+
- ``parsed_options``: additional, parsed options from other `Connection String`_
103+
components. This is mainly used for asserting ``UserInfo`` (as ``user`` and
104+
``password``) and ``Auth database`` (as ``auth_database``).
76105
- ``error``: indicates that the parsing of the URI, or the resolving or
77106
contents of the SRV or TXT records included errors.
78107
- ``comment``: a comment to indicate why a test would fail.
79108

80-
For each file, create MongoClient initialized with the mongodb+srv connection
81-
string. You SHOULD verify that the client's initial seed list matches the list of
82-
seeds. You MUST verify that the set of ServerDescriptions in the client's
83-
TopologyDescription eventually matches the list of hosts. You MUST verify that
84-
each of the values of the Connection String Options under ``options`` match the
85-
Client's parsed value for that option. There may be other options parsed by
86-
the Client as well, which a test does not verify. You MUST verify that an
87-
error has been thrown if ``error`` is present.
109+
.. _`Connection String`: ../../connection-string/connection-string-spec.rst
110+
.. _`URI options`: ../../uri-options/uri-options.rst
111+
112+
For each file, create MongoClient initialized with the ``mongodb+srv``
113+
connection string.
114+
115+
If ``seeds`` is specified, drivers SHOULD verify that the set of hosts in the
116+
client's initial seedlist matches the list in ``seeds``. If ``numSeeds`` is
117+
specified, drivers SHOULD verify that the size of that set matches ``numSeeds``.
118+
119+
If ``hosts`` is specified, drivers MUST verify that the set of
120+
ServerDescriptions in the client's TopologyDescription eventually matches the
121+
list in ``hosts``. If ``numHosts`` is specified, drivers MUST verify that the
122+
size of that set matches ``numHosts``.
123+
124+
If ``options`` is specified, drivers MUST verify each of the values under
125+
``options`` match the MongoClient's parsed value for that option. There may be
126+
other options parsed by the Client as well, which a test does not verify.
127+
128+
If ``parsed_options`` is specified, drivers MUST verify that each of the values
129+
under ``parsed_options`` match the MongoClient's parsed value for that option.
130+
Support values include, but are not limited to, ``user`` and ``password``
131+
(parsed from ``UserInfo``) and ``auth_database`` (parsed from
132+
``Auth database``).
133+
134+
If ``error`` is specified and ``true``, drivers MUST verify that an error has
135+
been thrown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"uri": "mongodb+srv://test4.test.build.10gen.cc/?loadBalanced=true",
3+
"seeds": [],
4+
"hosts": [],
5+
"error": true,
6+
"comment": "Should fail because no SRV records are present for this URI."
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
uri: "mongodb+srv://test4.test.build.10gen.cc/?loadBalanced=true"
2+
seeds: []
3+
hosts: []
4+
error: true
5+
comment: Should fail because no SRV records are present for this URI.

data/initial-dns-seedlist-discovery/replica-set/srv-service-name.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
"ssl": true,
1414
"srvServiceName": "customname"
1515
}
16-
}
16+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"uri": "mongodb+srv://test1.test.build.10gen.cc/?replicaSet=repl0&srvMaxHosts=2",
3+
"numSeeds": 2,
4+
"seeds": [
5+
"localhost.test.build.10gen.cc:27017",
6+
"localhost.test.build.10gen.cc:27018"
7+
],
8+
"hosts": [
9+
"localhost:27017",
10+
"localhost:27018",
11+
"localhost:27019"
12+
],
13+
"options": {
14+
"replicaSet": "repl0",
15+
"srvMaxHosts": 2,
16+
"ssl": true
17+
}
18+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# When srvMaxHosts equals the number of SRV records, all hosts are added to the
2+
# seed list.
3+
uri: "mongodb+srv://test1.test.build.10gen.cc/?replicaSet=repl0&srvMaxHosts=2"
4+
numSeeds: 2
5+
seeds:
6+
- localhost.test.build.10gen.cc:27017
7+
- localhost.test.build.10gen.cc:27018
8+
hosts:
9+
- localhost:27017
10+
- localhost:27018
11+
- localhost:27019
12+
options:
13+
replicaSet: repl0
14+
srvMaxHosts: 2
15+
ssl: true
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"uri": "mongodb+srv://test1.test.build.10gen.cc/?replicaSet=repl0&srvMaxHosts=3",
3+
"seeds": [
4+
"localhost.test.build.10gen.cc:27017",
5+
"localhost.test.build.10gen.cc:27018"
6+
],
7+
"hosts": [
8+
"localhost:27017",
9+
"localhost:27018",
10+
"localhost:27019"
11+
],
12+
"options": {
13+
"replicaSet": "repl0",
14+
"srvMaxHosts": 3,
15+
"ssl": true
16+
}
17+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# When srvMaxHosts is greater than the number of SRV records, all hosts are
2+
# added to the seed list.
3+
uri: "mongodb+srv://test1.test.build.10gen.cc/?replicaSet=repl0&srvMaxHosts=3"
4+
seeds:
5+
- localhost.test.build.10gen.cc:27017
6+
- localhost.test.build.10gen.cc:27018
7+
hosts:
8+
- localhost:27017
9+
- localhost:27018
10+
- localhost:27019
11+
options:
12+
replicaSet: repl0
13+
srvMaxHosts: 3
14+
ssl: true
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"uri": "mongodb+srv://test1.test.build.10gen.cc/?replicaSet=repl0&srvMaxHosts=-1",
3+
"seeds": [],
4+
"hosts": [],
5+
"error": true,
6+
"comment": "Should fail because srvMaxHosts is not greater than or equal to zero"
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
uri: "mongodb+srv://test1.test.build.10gen.cc/?replicaSet=repl0&srvMaxHosts=-1"
2+
seeds: []
3+
hosts: []
4+
error: true
5+
comment: Should fail because srvMaxHosts is not greater than or equal to zero
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"uri": "mongodb+srv://test1.test.build.10gen.cc/?replicaSet=repl0&srvMaxHosts=foo",
3+
"seeds": [],
4+
"hosts": [],
5+
"error": true,
6+
"comment": "Should fail because srvMaxHosts is not an integer"
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
uri: "mongodb+srv://test1.test.build.10gen.cc/?replicaSet=repl0&srvMaxHosts=foo"
2+
seeds: []
3+
hosts: []
4+
error: true
5+
comment: Should fail because srvMaxHosts is not an integer
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"uri": "mongodb+srv://test1.test.build.10gen.cc/?replicaSet=repl0&srvMaxHosts=1",
3+
"numSeeds": 1,
4+
"hosts": [
5+
"localhost:27017",
6+
"localhost:27018",
7+
"localhost:27019"
8+
],
9+
"options": {
10+
"replicaSet": "repl0",
11+
"srvMaxHosts": 1,
12+
"ssl": true
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# When srvMaxHosts is less than the number of SRV records, a random subset of
2+
# hosts are added to the seed list. We cannot anticipate which hosts will be
3+
# selected, so this test uses numSeeds instead of seeds. Since this is a replica
4+
# set, all hosts should ultimately be discovered by SDAM.
5+
uri: "mongodb+srv://test1.test.build.10gen.cc/?replicaSet=repl0&srvMaxHosts=1"
6+
numSeeds: 1
7+
hosts:
8+
- localhost:27017
9+
- localhost:27018
10+
- localhost:27019
11+
options:
12+
replicaSet: repl0
13+
srvMaxHosts: 1
14+
ssl: true
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"uri": "mongodb+srv://test1.test.build.10gen.cc/?replicaSet=repl0&srvMaxHosts=0",
3+
"seeds": [
4+
"localhost.test.build.10gen.cc:27017",
5+
"localhost.test.build.10gen.cc:27018"
6+
],
7+
"hosts": [
8+
"localhost:27017",
9+
"localhost:27018",
10+
"localhost:27019"
11+
],
12+
"options": {
13+
"replicaSet": "repl0",
14+
"srvMaxHosts": 0,
15+
"ssl": true
16+
}
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# When srvMaxHosts is zero, all hosts are added to the seed list.
2+
uri: "mongodb+srv://test1.test.build.10gen.cc/?replicaSet=repl0&srvMaxHosts=0"
3+
seeds:
4+
- localhost.test.build.10gen.cc:27017
5+
- localhost.test.build.10gen.cc:27018
6+
hosts:
7+
- localhost:27017
8+
- localhost:27018
9+
- localhost:27019
10+
options:
11+
replicaSet: repl0
12+
srvMaxHosts: 0
13+
ssl: true
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"uri": "mongodb+srv://test1.test.build.10gen.cc/adminDB?replicaSet=repl0",
3+
"seeds": [
4+
"localhost.test.build.10gen.cc:27017",
5+
"localhost.test.build.10gen.cc:27018"
6+
],
7+
"hosts": [
8+
"localhost:27017",
9+
"localhost:27018",
10+
"localhost:27019"
11+
],
12+
"options": {
13+
"replicaSet": "repl0",
14+
"ssl": true
15+
},
16+
"parsed_options": {
17+
"auth_database": "adminDB"
18+
}
19+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
uri: "mongodb+srv://test1.test.build.10gen.cc/adminDB?replicaSet=repl0"
2+
seeds:
3+
- localhost.test.build.10gen.cc:27017
4+
- localhost.test.build.10gen.cc:27018
5+
hosts:
6+
- localhost:27017
7+
- localhost:27018
8+
- localhost:27019
9+
options:
10+
replicaSet: repl0
11+
ssl: true
12+
parsed_options:
13+
auth_database: adminDB
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"uri": "mongodb+srv://test1.test.build.10gen.cc/?srvMaxHosts=2",
3+
"numSeeds": 2,
4+
"seeds": [
5+
"localhost.test.build.10gen.cc:27017",
6+
"localhost.test.build.10gen.cc:27018"
7+
],
8+
"hosts": [
9+
"localhost.test.build.10gen.cc:27017",
10+
"localhost.test.build.10gen.cc:27018"
11+
],
12+
"options": {
13+
"srvMaxHosts": 2,
14+
"ssl": true
15+
}
16+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# When srvMaxHosts equals the number of SRV records, all hosts are added to the
2+
# seed list.
3+
uri: "mongodb+srv://test1.test.build.10gen.cc/?srvMaxHosts=2"
4+
numSeeds: 2
5+
seeds:
6+
- localhost.test.build.10gen.cc:27017
7+
- localhost.test.build.10gen.cc:27018
8+
hosts:
9+
- localhost.test.build.10gen.cc:27017
10+
- localhost.test.build.10gen.cc:27018
11+
options:
12+
srvMaxHosts: 2
13+
ssl: true

0 commit comments

Comments
 (0)