mongodb 3.2.5 → 3.3.0-beta2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HISTORY.md +0 -10
- package/index.js +4 -4
- package/lib/admin.js +56 -56
- package/lib/aggregation_cursor.js +7 -3
- package/lib/bulk/common.js +18 -13
- package/lib/change_stream.js +196 -89
- package/lib/collection.js +217 -169
- package/lib/command_cursor.js +17 -7
- package/lib/core/auth/auth_provider.js +158 -0
- package/lib/core/auth/defaultAuthProviders.js +29 -0
- package/lib/core/auth/gssapi.js +241 -0
- package/lib/core/auth/mongo_credentials.js +81 -0
- package/lib/core/auth/mongocr.js +51 -0
- package/lib/core/auth/plain.js +35 -0
- package/lib/core/auth/scram.js +293 -0
- package/lib/core/auth/sspi.js +131 -0
- package/lib/core/auth/x509.js +26 -0
- package/lib/core/connection/apm.js +236 -0
- package/lib/core/connection/command_result.js +36 -0
- package/lib/core/connection/commands.js +507 -0
- package/lib/core/connection/connect.js +370 -0
- package/lib/core/connection/connection.js +624 -0
- package/lib/core/connection/logger.js +246 -0
- package/lib/core/connection/msg.js +219 -0
- package/lib/core/connection/pool.js +1285 -0
- package/lib/core/connection/utils.js +57 -0
- package/lib/core/cursor.js +752 -0
- package/lib/core/error.js +186 -0
- package/lib/core/index.js +50 -0
- package/lib/core/sdam/monitoring.js +228 -0
- package/lib/core/sdam/server.js +467 -0
- package/lib/core/sdam/server_description.js +163 -0
- package/lib/core/sdam/server_selectors.js +244 -0
- package/lib/core/sdam/srv_polling.js +135 -0
- package/lib/core/sdam/topology.js +1151 -0
- package/lib/core/sdam/topology_description.js +408 -0
- package/lib/core/sessions.js +711 -0
- package/lib/core/tools/smoke_plugin.js +61 -0
- package/lib/core/topologies/mongos.js +1337 -0
- package/lib/core/topologies/read_preference.js +202 -0
- package/lib/core/topologies/replset.js +1507 -0
- package/lib/core/topologies/replset_state.js +1121 -0
- package/lib/core/topologies/server.js +984 -0
- package/lib/core/topologies/shared.js +453 -0
- package/lib/core/transactions.js +167 -0
- package/lib/core/uri_parser.js +631 -0
- package/lib/core/utils.js +165 -0
- package/lib/core/wireprotocol/command.js +170 -0
- package/lib/core/wireprotocol/compression.js +73 -0
- package/lib/core/wireprotocol/constants.js +13 -0
- package/lib/core/wireprotocol/get_more.js +86 -0
- package/lib/core/wireprotocol/index.js +18 -0
- package/lib/core/wireprotocol/kill_cursors.js +70 -0
- package/lib/core/wireprotocol/query.js +224 -0
- package/lib/core/wireprotocol/shared.js +115 -0
- package/lib/core/wireprotocol/write_command.js +50 -0
- package/lib/cursor.js +40 -46
- package/lib/db.js +141 -95
- package/lib/dynamic_loaders.js +32 -0
- package/lib/error.js +12 -10
- package/lib/gridfs/chunk.js +2 -2
- package/lib/gridfs/grid_store.js +31 -25
- package/lib/gridfs-stream/index.js +4 -4
- package/lib/gridfs-stream/upload.js +1 -1
- package/lib/mongo_client.js +37 -15
- package/lib/operations/add_user.js +96 -0
- package/lib/operations/aggregate.js +24 -13
- package/lib/operations/aggregate_operation.js +127 -0
- package/lib/operations/bulk_write.js +104 -0
- package/lib/operations/close.js +47 -0
- package/lib/operations/collection_ops.js +28 -287
- package/lib/operations/collections.js +55 -0
- package/lib/operations/command.js +120 -0
- package/lib/operations/command_v2.js +43 -0
- package/lib/operations/common_functions.js +372 -0
- package/lib/operations/{mongo_client_ops.js → connect.js} +185 -157
- package/lib/operations/count.js +72 -0
- package/lib/operations/count_documents.js +46 -0
- package/lib/operations/create_collection.js +118 -0
- package/lib/operations/create_index.js +92 -0
- package/lib/operations/create_indexes.js +61 -0
- package/lib/operations/cursor_ops.js +3 -4
- package/lib/operations/db_ops.js +15 -12
- package/lib/operations/delete_many.js +25 -0
- package/lib/operations/delete_one.js +25 -0
- package/lib/operations/distinct.js +85 -0
- package/lib/operations/drop.js +53 -0
- package/lib/operations/drop_index.js +42 -0
- package/lib/operations/drop_indexes.js +23 -0
- package/lib/operations/estimated_document_count.js +33 -0
- package/lib/operations/execute_db_admin_command.js +34 -0
- package/lib/operations/execute_operation.js +165 -0
- package/lib/operations/explain.js +23 -0
- package/lib/operations/find_and_modify.js +98 -0
- package/lib/operations/find_one.js +33 -0
- package/lib/operations/find_one_and_delete.js +16 -0
- package/lib/operations/find_one_and_replace.js +18 -0
- package/lib/operations/find_one_and_update.js +19 -0
- package/lib/operations/geo_haystack_search.js +79 -0
- package/lib/operations/has_next.js +40 -0
- package/lib/operations/index_exists.js +39 -0
- package/lib/operations/index_information.js +23 -0
- package/lib/operations/indexes.js +22 -0
- package/lib/operations/insert_many.js +63 -0
- package/lib/operations/insert_one.js +75 -0
- package/lib/operations/is_capped.js +19 -0
- package/lib/operations/list_indexes.js +66 -0
- package/lib/operations/map_reduce.js +189 -0
- package/lib/operations/next.js +32 -0
- package/lib/operations/operation.js +63 -0
- package/lib/operations/options_operation.js +32 -0
- package/lib/operations/profiling_level.js +31 -0
- package/lib/operations/re_index.js +28 -0
- package/lib/operations/remove_user.js +52 -0
- package/lib/operations/rename.js +61 -0
- package/lib/operations/replace_one.js +47 -0
- package/lib/operations/set_profiling_level.js +48 -0
- package/lib/operations/stats.js +45 -0
- package/lib/operations/to_array.js +68 -0
- package/lib/operations/update_many.js +29 -0
- package/lib/operations/update_one.js +44 -0
- package/lib/operations/validate_collection.js +40 -0
- package/lib/read_concern.js +55 -0
- package/lib/topologies/mongos.js +3 -3
- package/lib/topologies/native_topology.js +22 -2
- package/lib/topologies/replset.js +3 -3
- package/lib/topologies/server.js +4 -4
- package/lib/topologies/topology_base.js +6 -6
- package/lib/url_parser.js +4 -3
- package/lib/utils.js +46 -59
- package/lib/write_concern.js +66 -0
- package/package.json +15 -6
- package/lib/.DS_Store +0 -0
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const ServerType = require('./server_description').ServerType;
|
|
3
|
+
const TopologyType = require('./topology_description').TopologyType;
|
|
4
|
+
const ReadPreference = require('../topologies/read_preference');
|
|
5
|
+
const MongoError = require('../error').MongoError;
|
|
6
|
+
|
|
7
|
+
// max staleness constants
|
|
8
|
+
const IDLE_WRITE_PERIOD = 10000;
|
|
9
|
+
const SMALLEST_MAX_STALENESS_SECONDS = 90;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Returns a server selector that selects for writable servers
|
|
13
|
+
*/
|
|
14
|
+
function writableServerSelector() {
|
|
15
|
+
return function(topologyDescription, servers) {
|
|
16
|
+
return latencyWindowReducer(topologyDescription, servers.filter(s => s.isWritable));
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Reduces the passed in array of servers by the rules of the "Max Staleness" specification
|
|
22
|
+
* found here: https://github.com/mongodb/specifications/blob/master/source/max-staleness/max-staleness.rst
|
|
23
|
+
*
|
|
24
|
+
* @param {ReadPreference} readPreference The read preference providing max staleness guidance
|
|
25
|
+
* @param {topologyDescription} topologyDescription The topology description
|
|
26
|
+
* @param {ServerDescription[]} servers The list of server descriptions to be reduced
|
|
27
|
+
* @return {ServerDescription[]} The list of servers that satisfy the requirements of max staleness
|
|
28
|
+
*/
|
|
29
|
+
function maxStalenessReducer(readPreference, topologyDescription, servers) {
|
|
30
|
+
if (readPreference.maxStalenessSeconds == null || readPreference.maxStalenessSeconds < 0) {
|
|
31
|
+
return servers;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const maxStaleness = readPreference.maxStalenessSeconds;
|
|
35
|
+
const maxStalenessVariance =
|
|
36
|
+
(topologyDescription.heartbeatFrequencyMS + IDLE_WRITE_PERIOD) / 1000;
|
|
37
|
+
if (maxStaleness < maxStalenessVariance) {
|
|
38
|
+
throw new MongoError(`maxStalenessSeconds must be at least ${maxStalenessVariance} seconds`);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (maxStaleness < SMALLEST_MAX_STALENESS_SECONDS) {
|
|
42
|
+
throw new MongoError(
|
|
43
|
+
`maxStalenessSeconds must be at least ${SMALLEST_MAX_STALENESS_SECONDS} seconds`
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (topologyDescription.type === TopologyType.ReplicaSetWithPrimary) {
|
|
48
|
+
const primary = servers.filter(primaryFilter)[0];
|
|
49
|
+
return servers.reduce((result, server) => {
|
|
50
|
+
const stalenessMS =
|
|
51
|
+
server.lastUpdateTime -
|
|
52
|
+
server.lastWriteDate -
|
|
53
|
+
(primary.lastUpdateTime - primary.lastWriteDate) +
|
|
54
|
+
topologyDescription.heartbeatFrequencyMS;
|
|
55
|
+
|
|
56
|
+
const staleness = stalenessMS / 1000;
|
|
57
|
+
if (staleness <= readPreference.maxStalenessSeconds) result.push(server);
|
|
58
|
+
return result;
|
|
59
|
+
}, []);
|
|
60
|
+
} else if (topologyDescription.type === TopologyType.ReplicaSetNoPrimary) {
|
|
61
|
+
const sMax = servers.reduce((max, s) => (s.lastWriteDate > max.lastWriteDate ? s : max));
|
|
62
|
+
return servers.reduce((result, server) => {
|
|
63
|
+
const stalenessMS =
|
|
64
|
+
sMax.lastWriteDate - server.lastWriteDate + topologyDescription.heartbeatFrequencyMS;
|
|
65
|
+
|
|
66
|
+
const staleness = stalenessMS / 1000;
|
|
67
|
+
if (staleness <= readPreference.maxStalenessSeconds) result.push(server);
|
|
68
|
+
return result;
|
|
69
|
+
}, []);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return servers;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Determines whether a server's tags match a given set of tags
|
|
77
|
+
*
|
|
78
|
+
* @param {String[]} tagSet The requested tag set to match
|
|
79
|
+
* @param {String[]} serverTags The server's tags
|
|
80
|
+
*/
|
|
81
|
+
function tagSetMatch(tagSet, serverTags) {
|
|
82
|
+
const keys = Object.keys(tagSet);
|
|
83
|
+
const serverTagKeys = Object.keys(serverTags);
|
|
84
|
+
for (let i = 0; i < keys.length; ++i) {
|
|
85
|
+
const key = keys[i];
|
|
86
|
+
if (serverTagKeys.indexOf(key) === -1 || serverTags[key] !== tagSet[key]) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Reduces a set of server descriptions based on tags requested by the read preference
|
|
96
|
+
*
|
|
97
|
+
* @param {ReadPreference} readPreference The read preference providing the requested tags
|
|
98
|
+
* @param {ServerDescription[]} servers The list of server descriptions to reduce
|
|
99
|
+
* @return {ServerDescription[]} The list of servers matching the requested tags
|
|
100
|
+
*/
|
|
101
|
+
function tagSetReducer(readPreference, servers) {
|
|
102
|
+
if (
|
|
103
|
+
readPreference.tags == null ||
|
|
104
|
+
(Array.isArray(readPreference.tags) && readPreference.tags.length === 0)
|
|
105
|
+
) {
|
|
106
|
+
return servers;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
for (let i = 0; i < readPreference.tags.length; ++i) {
|
|
110
|
+
const tagSet = readPreference.tags[i];
|
|
111
|
+
const serversMatchingTagset = servers.reduce((matched, server) => {
|
|
112
|
+
if (tagSetMatch(tagSet, server.tags)) matched.push(server);
|
|
113
|
+
return matched;
|
|
114
|
+
}, []);
|
|
115
|
+
|
|
116
|
+
if (serversMatchingTagset.length) {
|
|
117
|
+
return serversMatchingTagset;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return [];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Reduces a list of servers to ensure they fall within an acceptable latency window. This is
|
|
126
|
+
* further specified in the "Server Selection" specification, found here:
|
|
127
|
+
* https://github.com/mongodb/specifications/blob/master/source/server-selection/server-selection.rst
|
|
128
|
+
*
|
|
129
|
+
* @param {topologyDescription} topologyDescription The topology description
|
|
130
|
+
* @param {ServerDescription[]} servers The list of servers to reduce
|
|
131
|
+
* @returns {ServerDescription[]} The servers which fall within an acceptable latency window
|
|
132
|
+
*/
|
|
133
|
+
function latencyWindowReducer(topologyDescription, servers) {
|
|
134
|
+
const low = servers.reduce(
|
|
135
|
+
(min, server) => (min === -1 ? server.roundTripTime : Math.min(server.roundTripTime, min)),
|
|
136
|
+
-1
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
const high = low + topologyDescription.localThresholdMS;
|
|
140
|
+
|
|
141
|
+
return servers.reduce((result, server) => {
|
|
142
|
+
if (server.roundTripTime <= high && server.roundTripTime >= low) result.push(server);
|
|
143
|
+
return result;
|
|
144
|
+
}, []);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// filters
|
|
148
|
+
function primaryFilter(server) {
|
|
149
|
+
return server.type === ServerType.RSPrimary;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function secondaryFilter(server) {
|
|
153
|
+
return server.type === ServerType.RSSecondary;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function nearestFilter(server) {
|
|
157
|
+
return server.type === ServerType.RSSecondary || server.type === ServerType.RSPrimary;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function knownFilter(server) {
|
|
161
|
+
return server.type !== ServerType.Unknown;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Returns a function which selects servers based on a provided read preference
|
|
166
|
+
*
|
|
167
|
+
* @param {ReadPreference} readPreference The read preference to select with
|
|
168
|
+
*/
|
|
169
|
+
function readPreferenceServerSelector(readPreference) {
|
|
170
|
+
if (!readPreference.isValid()) {
|
|
171
|
+
throw new TypeError('Invalid read preference specified');
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return function(topologyDescription, servers) {
|
|
175
|
+
const commonWireVersion = topologyDescription.commonWireVersion;
|
|
176
|
+
if (
|
|
177
|
+
commonWireVersion &&
|
|
178
|
+
(readPreference.minWireVersion && readPreference.minWireVersion > commonWireVersion)
|
|
179
|
+
) {
|
|
180
|
+
throw new MongoError(
|
|
181
|
+
`Minimum wire version '${
|
|
182
|
+
readPreference.minWireVersion
|
|
183
|
+
}' required, but found '${commonWireVersion}'`
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (
|
|
188
|
+
topologyDescription.type === TopologyType.Single ||
|
|
189
|
+
topologyDescription.type === TopologyType.Sharded
|
|
190
|
+
) {
|
|
191
|
+
return latencyWindowReducer(topologyDescription, servers.filter(knownFilter));
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (readPreference.mode === ReadPreference.PRIMARY) {
|
|
195
|
+
return servers.filter(primaryFilter);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (readPreference.mode === ReadPreference.SECONDARY) {
|
|
199
|
+
return latencyWindowReducer(
|
|
200
|
+
topologyDescription,
|
|
201
|
+
tagSetReducer(
|
|
202
|
+
readPreference,
|
|
203
|
+
maxStalenessReducer(readPreference, topologyDescription, servers)
|
|
204
|
+
)
|
|
205
|
+
).filter(secondaryFilter);
|
|
206
|
+
} else if (readPreference.mode === ReadPreference.NEAREST) {
|
|
207
|
+
return latencyWindowReducer(
|
|
208
|
+
topologyDescription,
|
|
209
|
+
tagSetReducer(
|
|
210
|
+
readPreference,
|
|
211
|
+
maxStalenessReducer(readPreference, topologyDescription, servers)
|
|
212
|
+
)
|
|
213
|
+
).filter(nearestFilter);
|
|
214
|
+
} else if (readPreference.mode === ReadPreference.SECONDARY_PREFERRED) {
|
|
215
|
+
const result = latencyWindowReducer(
|
|
216
|
+
topologyDescription,
|
|
217
|
+
tagSetReducer(
|
|
218
|
+
readPreference,
|
|
219
|
+
maxStalenessReducer(readPreference, topologyDescription, servers)
|
|
220
|
+
)
|
|
221
|
+
).filter(secondaryFilter);
|
|
222
|
+
|
|
223
|
+
return result.length === 0 ? servers.filter(primaryFilter) : result;
|
|
224
|
+
} else if (readPreference.mode === ReadPreference.PRIMARY_PREFERRED) {
|
|
225
|
+
const result = servers.filter(primaryFilter);
|
|
226
|
+
if (result.length) {
|
|
227
|
+
return result;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return latencyWindowReducer(
|
|
231
|
+
topologyDescription,
|
|
232
|
+
tagSetReducer(
|
|
233
|
+
readPreference,
|
|
234
|
+
maxStalenessReducer(readPreference, topologyDescription, servers)
|
|
235
|
+
)
|
|
236
|
+
).filter(secondaryFilter);
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
module.exports = {
|
|
242
|
+
writableServerSelector,
|
|
243
|
+
readPreferenceServerSelector
|
|
244
|
+
};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Logger = require('../connection/logger');
|
|
4
|
+
const EventEmitter = require('events').EventEmitter;
|
|
5
|
+
const dns = require('dns');
|
|
6
|
+
/**
|
|
7
|
+
* Determines whether a provided address matches the provided parent domain in order
|
|
8
|
+
* to avoid certain attack vectors.
|
|
9
|
+
*
|
|
10
|
+
* @param {String} srvAddress The address to check against a domain
|
|
11
|
+
* @param {String} parentDomain The domain to check the provided address against
|
|
12
|
+
* @return {Boolean} Whether the provided address matches the parent domain
|
|
13
|
+
*/
|
|
14
|
+
function matchesParentDomain(srvAddress, parentDomain) {
|
|
15
|
+
const regex = /^.*?\./;
|
|
16
|
+
const srv = `.${srvAddress.replace(regex, '')}`;
|
|
17
|
+
const parent = `.${parentDomain.replace(regex, '')}`;
|
|
18
|
+
return srv.endsWith(parent);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
class SrvPollingEvent {
|
|
22
|
+
constructor(srvRecords) {
|
|
23
|
+
this.srvRecords = srvRecords;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
addresses() {
|
|
27
|
+
return new Set(this.srvRecords.map(record => `${record.name}:${record.port}`));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
class SrvPoller extends EventEmitter {
|
|
32
|
+
/**
|
|
33
|
+
* @param {object} options
|
|
34
|
+
* @param {string} options.srvHost
|
|
35
|
+
* @param {number} [options.heartbeatFrequencyMS]
|
|
36
|
+
* @param {function} [options.logger]
|
|
37
|
+
* @param {string} [options.loggerLevel]
|
|
38
|
+
*/
|
|
39
|
+
constructor(options) {
|
|
40
|
+
super();
|
|
41
|
+
|
|
42
|
+
if (!options || !options.srvHost) {
|
|
43
|
+
throw new TypeError('options for SrvPoller must exist and include srvHost');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
this.srvHost = options.srvHost;
|
|
47
|
+
this.rescanSrvIntervalMS = 60000;
|
|
48
|
+
this.heartbeatFrequencyMS = options.heartbeatFrequencyMS || 10000;
|
|
49
|
+
this.logger = Logger('srvPoller', options);
|
|
50
|
+
|
|
51
|
+
this.haMode = false;
|
|
52
|
+
this.generation = 0;
|
|
53
|
+
|
|
54
|
+
this._timeout = null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
get srvAddress() {
|
|
58
|
+
return `_mongodb._tcp.${this.srvHost}`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
get intervalMS() {
|
|
62
|
+
return this.haMode ? this.heartbeatFrequencyMS : this.rescanSrvIntervalMs;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
start() {
|
|
66
|
+
if (!this._timeout) {
|
|
67
|
+
this.schedule();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
stop() {
|
|
72
|
+
if (this._timeout) {
|
|
73
|
+
clearTimeout(this._timeout);
|
|
74
|
+
this.generation += 1;
|
|
75
|
+
this._timeout = null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
schedule() {
|
|
80
|
+
clearTimeout(this._timeout);
|
|
81
|
+
this._timeout = setTimeout(() => this._poll(), this.intervalMS);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
success(srvRecords) {
|
|
85
|
+
this.haMode = false;
|
|
86
|
+
this.schedule();
|
|
87
|
+
this.emit('srvRecordDiscovery', new SrvPollingEvent(srvRecords));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
failure(message, obj) {
|
|
91
|
+
this.logger.warn(message, obj);
|
|
92
|
+
this.haMode = true;
|
|
93
|
+
this.schedule();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
parentDomainMismatch(srvRecord) {
|
|
97
|
+
this.logger.warn(
|
|
98
|
+
`parent domain mismatch on SRV record (${srvRecord.name}:${srvRecord.port})`,
|
|
99
|
+
srvRecord
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
_poll() {
|
|
104
|
+
const generation = this.generation;
|
|
105
|
+
dns.resolveSrv(this.srvAddress, (err, srvRecords) => {
|
|
106
|
+
if (generation !== this.generation) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (err) {
|
|
111
|
+
this.failure('DNS error', err);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const finalAddresses = [];
|
|
116
|
+
srvRecords.forEach(record => {
|
|
117
|
+
if (matchesParentDomain(record.name, this.srvHost)) {
|
|
118
|
+
finalAddresses.push(record);
|
|
119
|
+
} else {
|
|
120
|
+
this.parentDomainMismatch(record);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
if (!finalAddresses.length) {
|
|
125
|
+
this.failure('No valid addresses found at host');
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
this.success(finalAddresses);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
module.exports.SrvPollingEvent = SrvPollingEvent;
|
|
135
|
+
module.exports.SrvPoller = SrvPoller;
|