Skip to content

fix: adds topology discovery for mongos #2557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions lib/core/uri_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -687,15 +687,6 @@ function parseConnectionString(uri, options, callback) {
return callback(new MongoParseError('directConnection option requires exactly one host'));
}

// NOTE: this behavior will go away in v4.0, we will always auto discover there
if (
parsedOptions.directConnection == null &&
hosts.length === 1 &&
parsedOptions.replicaSet == null
) {
parsedOptions.directConnection = true;
}

const result = {
hosts: hosts,
auth: auth.db || auth.username ? auth : null,
Expand Down
16 changes: 16 additions & 0 deletions test/functional/sharding_connection.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
'use strict';

const withClient = require('./shared').withClient;
const setupDatabase = require('./shared').setupDatabase;
const expect = require('chai').expect;
const TopologyType = require('../../lib/core/sdam/common').TopologyType;

describe('Sharding (Connection)', function() {
before(function() {
return setupDatabase(this.configuration);
});

it('Should use sharded topology', {
metadata: { requires: { topology: 'sharded' } },
test: function() {
const client = this.configuration.newClient({}, { useUnifiedTopology: true });
return withClient(client, (client, done) => {
expect(client).to.exist;
expect(client)
.nested.property('topology.description.type')
.to.equal(TopologyType.Sharded);
return done();
})();
}
});

/**
* @ignore
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ tests:
appname: commandErrorHandshakeTest
operations:
# The command error on the initial handshake should mark the server
# Unknown and clear the pool.
# Unknown (emitting a ServerDescriptionChangedEvent) and clear the pool.
- name: waitForEvent
object: testRunner
arguments:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ tests:
appname: networkErrorHandshakeTest
operations:
# The network error on the initial handshake should mark the server
# Unknown and clear the pool.
# Unknown (emitting a ServerDescriptionChangedEvent) and clear the pool.
- name: waitForEvent
object: testRunner
arguments:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ tests:
appname: timeoutMonitorHandshakeTest
operations:
# The network error on the initial handshake should mark the server
# Unknown and clear the pool.
# Unknown (emitting a ServerDescriptionChangedEvent) and clear the pool.
- name: waitForEvent
object: testRunner
arguments:
Expand Down Expand Up @@ -101,6 +101,9 @@ tests:
failCommands: ["isMaster"]
appName: timeoutMonitorCheckTest
blockConnection: true
# blockTimeMS is evaluated after the waiting for heartbeatFrequencyMS server-side, so this value only
# needs to be greater than connectTimeoutMS. The driver will wait for (500+750)ms and the server will
# respond after (500+1000)ms.
blockTimeMS: 1000
# The network error on the next check should mark the server Unknown and
# clear the pool.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{
"description": "Monitoring a discovered standalone connection",
"uri": "mongodb://a:27017/?directConnection=false",
"phases": [
{
"responses": [
[
"a:27017",
{
"ok": 1,
"ismaster": true,
"minWireVersion": 0,
"maxWireVersion": 4
}
]
],
"outcome": {
"events": [
{
"topology_opening_event": {
"topologyId": "42"
}
},
{
"topology_description_changed_event": {
"topologyId": "42",
"previousDescription": {
"topologyType": "Unknown",
"servers": []
},
"newDescription": {
"topologyType": "Unknown",
"servers": [
{
"address": "a:27017",
"arbiters": [],
"hosts": [],
"passives": [],
"type": "Unknown"
}
]
}
}
},
{
"server_opening_event": {
"topologyId": "42",
"address": "a:27017"
}
},
{
"server_description_changed_event": {
"topologyId": "42",
"address": "a:27017",
"previousDescription": {
"address": "a:27017",
"arbiters": [],
"hosts": [],
"passives": [],
"type": "Unknown"
},
"newDescription": {
"address": "a:27017",
"arbiters": [],
"hosts": [],
"passives": [],
"type": "Standalone"
}
}
},
{
"topology_description_changed_event": {
"topologyId": "42",
"previousDescription": {
"topologyType": "Unknown",
"servers": [
{
"address": "a:27017",
"arbiters": [],
"hosts": [],
"passives": [],
"type": "Unknown"
}
]
},
"newDescription": {
"topologyType": "Single",
"servers": [
{
"address": "a:27017",
"arbiters": [],
"hosts": [],
"passives": [],
"type": "Standalone"
}
]
}
}
}
]
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
description: "Monitoring a discovered standalone connection"
uri: "mongodb://a:27017/?directConnection=false"
phases:
-
responses:
-
- "a:27017"
- { ok: 1, ismaster: true, minWireVersion: 0, maxWireVersion: 4 }

outcome:
events:
-
topology_opening_event:
topologyId: "42"
-
topology_description_changed_event:
topologyId: "42"
previousDescription:
topologyType: "Unknown"
servers: []
newDescription:
topologyType: "Unknown"
servers:
-
address: "a:27017"
arbiters: []
hosts: []
passives: []
type: "Unknown"
-
server_opening_event:
topologyId: "42"
address: "a:27017"
-
server_description_changed_event:
topologyId: "42"
address: "a:27017"
previousDescription:
address: "a:27017"
arbiters: []
hosts: []
passives: []
type: "Unknown"
newDescription:
address: "a:27017"
arbiters: []
hosts: []
passives: []
type: "Standalone"
-
topology_description_changed_event:
topologyId: "42"
previousDescription:
topologyType: "Unknown"
servers:
-
address: "a:27017"
arbiters: []
hosts: []
passives: []
type: "Unknown"
newDescription:
topologyType: "Single"
servers:
-
address: "a:27017"
arbiters: []
hosts: []
passives: []
type: "Standalone"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"description": "Monitoring a standalone connection",
"uri": "mongodb://a:27017",
"description": "Monitoring a direct connection",
"uri": "mongodb://a:27017/?directConnection=true",
"phases": [
{
"responses": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
description: "Monitoring a standalone connection"
uri: "mongodb://a:27017"
description: "Monitoring a direct connection"
uri: "mongodb://a:27017/?directConnection=true"
phases:
-
responses:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"description": "Monitoring a standalone connection - suppress update events for equal server descriptions",
"uri": "mongodb://a:27017",
"description": "Monitoring a direct connection - suppress update events for equal server descriptions",
"uri": "mongodb://a:27017/?directConnection=true",
"phases": [
{
"responses": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
description: "Monitoring a standalone connection - suppress update events for equal server descriptions"
uri: "mongodb://a:27017"
description: "Monitoring a direct connection - suppress update events for equal server descriptions"
uri: "mongodb://a:27017/?directConnection=true"
phases:
-
responses:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@
],
"setName": "rs",
"minWireVersion": 0,
"maxWireVersion": 9,
"topologyVersion": null
"maxWireVersion": 9
}
]
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ phases: [
hosts: ["a:27017", "d:27017"],
setName: "rs",
minWireVersion: 0,
maxWireVersion: 9,
topologyVersion: null
maxWireVersion: 9
}]
],

Expand Down