mongodb 4.2.1 → 4.4.0
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/README.md +2 -2
- package/lib/admin.js +3 -3
- package/lib/admin.js.map +1 -1
- package/lib/bson.js +16 -14
- package/lib/bson.js.map +1 -1
- package/lib/bulk/common.js +7 -7
- package/lib/bulk/common.js.map +1 -1
- package/lib/bulk/ordered.js +1 -1
- package/lib/bulk/ordered.js.map +1 -1
- package/lib/bulk/unordered.js +1 -1
- package/lib/bulk/unordered.js.map +1 -1
- package/lib/change_stream.js +6 -6
- package/lib/change_stream.js.map +1 -1
- package/lib/cmap/auth/auth_provider.js.map +1 -1
- package/lib/cmap/auth/gssapi.js +52 -10
- package/lib/cmap/auth/gssapi.js.map +1 -1
- package/lib/cmap/auth/mongo_credentials.js +36 -27
- package/lib/cmap/auth/mongo_credentials.js.map +1 -1
- package/lib/cmap/auth/mongocr.js +2 -2
- package/lib/cmap/auth/mongocr.js.map +1 -1
- package/lib/cmap/auth/mongodb_aws.js +6 -6
- package/lib/cmap/auth/mongodb_aws.js.map +1 -1
- package/lib/cmap/auth/plain.js +1 -1
- package/lib/cmap/auth/plain.js.map +1 -1
- package/lib/cmap/auth/providers.js +21 -0
- package/lib/cmap/auth/providers.js.map +1 -0
- package/lib/cmap/auth/scram.js +4 -4
- package/lib/cmap/auth/scram.js.map +1 -1
- package/lib/cmap/auth/x509.js +1 -1
- package/lib/cmap/auth/x509.js.map +1 -1
- package/lib/cmap/command_monitoring_events.js +3 -2
- package/lib/cmap/command_monitoring_events.js.map +1 -1
- package/lib/cmap/commands.js +14 -8
- package/lib/cmap/commands.js.map +1 -1
- package/lib/cmap/connect.js +119 -37
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js +36 -35
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/connection_pool.js +19 -30
- package/lib/cmap/connection_pool.js.map +1 -1
- package/lib/cmap/message_stream.js +3 -3
- package/lib/cmap/message_stream.js.map +1 -1
- package/lib/cmap/stream_description.js +4 -4
- package/lib/cmap/stream_description.js.map +1 -1
- package/lib/cmap/wire_protocol/compression.js +2 -1
- package/lib/cmap/wire_protocol/compression.js.map +1 -1
- package/lib/cmap/wire_protocol/shared.js +4 -3
- package/lib/cmap/wire_protocol/shared.js.map +1 -1
- package/lib/collection.js +46 -47
- package/lib/collection.js.map +1 -1
- package/lib/connection_string.js +93 -54
- package/lib/connection_string.js.map +1 -1
- package/lib/constants.js +113 -1
- package/lib/constants.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +5 -5
- package/lib/cursor/abstract_cursor.js.map +1 -1
- package/lib/cursor/aggregation_cursor.js +1 -1
- package/lib/cursor/aggregation_cursor.js.map +1 -1
- package/lib/cursor/find_cursor.js +2 -1
- package/lib/cursor/find_cursor.js.map +1 -1
- package/lib/db.js +23 -13
- package/lib/db.js.map +1 -1
- package/lib/deps.js +0 -1
- package/lib/deps.js.map +1 -1
- package/lib/encrypter.js +12 -4
- package/lib/encrypter.js.map +1 -1
- package/lib/error.js +47 -24
- package/lib/error.js.map +1 -1
- package/lib/gridfs/download.js +1 -1
- package/lib/gridfs/download.js.map +1 -1
- package/lib/gridfs/index.js +3 -3
- package/lib/gridfs/index.js.map +1 -1
- package/lib/gridfs/upload.js +3 -2
- package/lib/gridfs/upload.js.map +1 -1
- package/lib/index.js +83 -81
- package/lib/index.js.map +1 -1
- package/lib/logger.js +1 -1
- package/lib/logger.js.map +1 -1
- package/lib/mongo_client.js +5 -5
- package/lib/mongo_client.js.map +1 -1
- package/lib/mongo_types.js.map +1 -1
- package/lib/operations/add_user.js +3 -3
- package/lib/operations/add_user.js.map +1 -1
- package/lib/operations/aggregate.js +1 -1
- package/lib/operations/aggregate.js.map +1 -1
- package/lib/operations/bulk_write.js.map +1 -1
- package/lib/operations/collections.js +1 -1
- package/lib/operations/collections.js.map +1 -1
- package/lib/operations/command.js +5 -6
- package/lib/operations/command.js.map +1 -1
- package/lib/operations/common_functions.js.map +1 -1
- package/lib/operations/connect.js +4 -13
- package/lib/operations/connect.js.map +1 -1
- package/lib/operations/count.js +1 -1
- package/lib/operations/count.js.map +1 -1
- package/lib/operations/count_documents.js.map +1 -1
- package/lib/operations/create_collection.js +3 -2
- package/lib/operations/create_collection.js.map +1 -1
- package/lib/operations/delete.js +3 -3
- package/lib/operations/delete.js.map +1 -1
- package/lib/operations/distinct.js +3 -3
- package/lib/operations/distinct.js.map +1 -1
- package/lib/operations/drop.js +1 -1
- package/lib/operations/drop.js.map +1 -1
- package/lib/operations/estimated_document_count.js +2 -2
- package/lib/operations/estimated_document_count.js.map +1 -1
- package/lib/operations/eval.js +2 -2
- package/lib/operations/eval.js.map +1 -1
- package/lib/operations/execute_operation.js +5 -6
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find.js +5 -5
- package/lib/operations/find.js.map +1 -1
- package/lib/operations/find_and_modify.js +2 -2
- package/lib/operations/find_and_modify.js.map +1 -1
- package/lib/operations/get_more.js.map +1 -1
- package/lib/operations/indexes.js +4 -4
- package/lib/operations/indexes.js.map +1 -1
- package/lib/operations/insert.js +3 -3
- package/lib/operations/insert.js.map +1 -1
- package/lib/operations/is_capped.js +1 -1
- package/lib/operations/is_capped.js.map +1 -1
- package/lib/operations/list_collections.js +3 -3
- package/lib/operations/list_collections.js.map +1 -1
- package/lib/operations/list_databases.js +1 -1
- package/lib/operations/list_databases.js.map +1 -1
- package/lib/operations/map_reduce.js +4 -3
- package/lib/operations/map_reduce.js.map +1 -1
- package/lib/operations/operation.js +1 -1
- package/lib/operations/operation.js.map +1 -1
- package/lib/operations/options_operation.js +1 -1
- package/lib/operations/options_operation.js.map +1 -1
- package/lib/operations/profiling_level.js +1 -1
- package/lib/operations/profiling_level.js.map +1 -1
- package/lib/operations/remove_user.js +1 -1
- package/lib/operations/remove_user.js.map +1 -1
- package/lib/operations/rename.js +3 -3
- package/lib/operations/rename.js.map +1 -1
- package/lib/operations/run_command.js +1 -1
- package/lib/operations/run_command.js.map +1 -1
- package/lib/operations/set_profiling_level.js +2 -2
- package/lib/operations/set_profiling_level.js.map +1 -1
- package/lib/operations/stats.js +1 -1
- package/lib/operations/stats.js.map +1 -1
- package/lib/operations/update.js +2 -2
- package/lib/operations/update.js.map +1 -1
- package/lib/operations/validate_collection.js +1 -1
- package/lib/operations/validate_collection.js.map +1 -1
- package/lib/read_preference.js +15 -5
- package/lib/read_preference.js.map +1 -1
- package/lib/sdam/events.js +4 -4
- package/lib/sdam/monitor.js +19 -18
- package/lib/sdam/monitor.js.map +1 -1
- package/lib/sdam/server.js +24 -31
- package/lib/sdam/server.js.map +1 -1
- package/lib/sdam/server_description.js +38 -38
- package/lib/sdam/server_description.js.map +1 -1
- package/lib/sdam/server_selection.js +2 -2
- package/lib/sdam/server_selection.js.map +1 -1
- package/lib/sdam/srv_polling.js +2 -2
- package/lib/sdam/srv_polling.js.map +1 -1
- package/lib/sdam/topology.js +32 -62
- package/lib/sdam/topology.js.map +1 -1
- package/lib/sdam/topology_description.js +3 -3
- package/lib/sdam/topology_description.js.map +1 -1
- package/lib/sessions.js +13 -28
- package/lib/sessions.js.map +1 -1
- package/lib/transactions.js +1 -1
- package/lib/transactions.js.map +1 -1
- package/lib/utils.js +46 -15
- package/lib/utils.js.map +1 -1
- package/mongodb.d.ts +205 -60
- package/mongodb.ts34.d.ts +230 -59
- package/package.json +40 -37
- package/src/admin.ts +9 -9
- package/src/bson.ts +25 -17
- package/src/bulk/common.ts +22 -23
- package/src/bulk/ordered.ts +4 -4
- package/src/bulk/unordered.ts +5 -5
- package/src/change_stream.ts +29 -28
- package/src/cmap/auth/auth_provider.ts +3 -3
- package/src/cmap/auth/gssapi.ts +65 -14
- package/src/cmap/auth/mongo_credentials.ts +28 -17
- package/src/cmap/auth/mongocr.ts +3 -2
- package/src/cmap/auth/mongodb_aws.ts +10 -11
- package/src/cmap/auth/plain.ts +1 -1
- package/src/cmap/auth/providers.ts +21 -0
- package/src/cmap/auth/scram.ts +9 -9
- package/src/cmap/auth/x509.ts +3 -3
- package/src/cmap/command_monitoring_events.ts +4 -3
- package/src/cmap/commands.ts +22 -14
- package/src/cmap/connect.ts +161 -45
- package/src/cmap/connection.ts +83 -63
- package/src/cmap/connection_pool.ts +39 -39
- package/src/cmap/connection_pool_events.ts +1 -1
- package/src/cmap/message_stream.ts +9 -8
- package/src/cmap/stream_description.ts +5 -5
- package/src/cmap/wire_protocol/compression.ts +4 -3
- package/src/cmap/wire_protocol/shared.ts +10 -9
- package/src/collection.ts +116 -93
- package/src/connection_string.ts +130 -59
- package/src/constants.ts +122 -0
- package/src/cursor/abstract_cursor.ts +14 -13
- package/src/cursor/aggregation_cursor.ts +6 -6
- package/src/cursor/find_cursor.ts +12 -4
- package/src/db.ts +44 -33
- package/src/deps.ts +44 -1
- package/src/encrypter.ts +12 -3
- package/src/error.ts +52 -24
- package/src/gridfs/download.ts +10 -8
- package/src/gridfs/index.ts +11 -11
- package/src/gridfs/upload.ts +13 -10
- package/src/index.ts +205 -199
- package/src/logger.ts +2 -1
- package/src/mongo_client.ts +46 -32
- package/src/mongo_types.ts +119 -21
- package/src/operations/add_user.ts +7 -6
- package/src/operations/aggregate.ts +5 -5
- package/src/operations/bulk_write.ts +5 -5
- package/src/operations/collections.ts +2 -2
- package/src/operations/command.ts +15 -9
- package/src/operations/common_functions.ts +4 -4
- package/src/operations/connect.ts +4 -14
- package/src/operations/count.ts +4 -4
- package/src/operations/count_documents.ts +3 -3
- package/src/operations/create_collection.ts +7 -6
- package/src/operations/delete.ts +5 -5
- package/src/operations/distinct.ts +4 -4
- package/src/operations/drop.ts +4 -4
- package/src/operations/estimated_document_count.ts +5 -5
- package/src/operations/eval.ts +5 -5
- package/src/operations/execute_operation.ts +10 -11
- package/src/operations/find.ts +14 -14
- package/src/operations/find_and_modify.ts +7 -7
- package/src/operations/get_more.ts +2 -2
- package/src/operations/indexes.ts +16 -16
- package/src/operations/insert.ts +9 -9
- package/src/operations/is_capped.ts +3 -3
- package/src/operations/list_collections.ts +6 -6
- package/src/operations/list_databases.ts +4 -4
- package/src/operations/map_reduce.ts +10 -9
- package/src/operations/operation.ts +3 -3
- package/src/operations/options_operation.ts +3 -3
- package/src/operations/profiling_level.ts +4 -4
- package/src/operations/remove_user.ts +4 -4
- package/src/operations/rename.ts +6 -6
- package/src/operations/run_command.ts +3 -3
- package/src/operations/set_profiling_level.ts +6 -5
- package/src/operations/stats.ts +4 -4
- package/src/operations/update.ts +10 -10
- package/src/operations/validate_collection.ts +4 -4
- package/src/read_preference.ts +18 -7
- package/src/sdam/common.ts +2 -2
- package/src/sdam/events.ts +5 -5
- package/src/sdam/monitor.ts +29 -32
- package/src/sdam/server.ts +64 -62
- package/src/sdam/server_description.ts +41 -48
- package/src/sdam/server_selection.ts +3 -3
- package/src/sdam/srv_polling.ts +3 -2
- package/src/sdam/topology.ts +71 -89
- package/src/sdam/topology_description.ts +5 -5
- package/src/sessions.ts +31 -48
- package/src/transactions.ts +4 -4
- package/src/utils.ts +64 -28
- package/lib/cmap/auth/defaultAuthProviders.js +0 -30
- package/lib/cmap/auth/defaultAuthProviders.js.map +0 -1
- package/src/cmap/auth/defaultAuthProviders.ts +0 -32
package/src/sdam/monitor.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Document, Long } from '../bson';
|
|
2
|
+
import { connect } from '../cmap/connect';
|
|
3
|
+
import { Connection, ConnectionOptions } from '../cmap/connection';
|
|
4
|
+
import { LEGACY_HELLO_COMMAND } from '../constants';
|
|
5
|
+
import { AnyError, MongoNetworkError } from '../error';
|
|
6
|
+
import { CancellationToken, TypedEventEmitter } from '../mongo_types';
|
|
7
|
+
import type { Callback, InterruptibleAsyncInterval } from '../utils';
|
|
2
8
|
import {
|
|
3
|
-
now,
|
|
4
|
-
makeStateMachine,
|
|
5
9
|
calculateDurationInMs,
|
|
10
|
+
EventEmitterWithState,
|
|
6
11
|
makeInterruptibleAsyncInterval,
|
|
7
|
-
|
|
8
|
-
|
|
12
|
+
makeStateMachine,
|
|
13
|
+
now,
|
|
14
|
+
ns
|
|
9
15
|
} from '../utils';
|
|
10
|
-
import {
|
|
11
|
-
import { Connection, ConnectionOptions } from '../cmap/connection';
|
|
12
|
-
import { MongoNetworkError, AnyError } from '../error';
|
|
13
|
-
import { Long, Document } from '../bson';
|
|
16
|
+
import { ServerType, STATE_CLOSED, STATE_CLOSING } from './common';
|
|
14
17
|
import {
|
|
18
|
+
ServerHeartbeatFailedEvent,
|
|
15
19
|
ServerHeartbeatStartedEvent,
|
|
16
|
-
ServerHeartbeatSucceededEvent
|
|
17
|
-
ServerHeartbeatFailedEvent
|
|
20
|
+
ServerHeartbeatSucceededEvent
|
|
18
21
|
} from './events';
|
|
19
|
-
|
|
20
22
|
import { Server } from './server';
|
|
21
|
-
import type { InterruptibleAsyncInterval, Callback } from '../utils';
|
|
22
23
|
import type { TopologyVersion } from './server_description';
|
|
23
|
-
import { CancellationToken, TypedEventEmitter } from '../mongo_types';
|
|
24
24
|
|
|
25
25
|
/** @internal */
|
|
26
26
|
const kServer = Symbol('server');
|
|
@@ -234,7 +234,7 @@ function checkServer(monitor: Monitor, callback: Callback<Document>) {
|
|
|
234
234
|
const isAwaitable = topologyVersion != null;
|
|
235
235
|
|
|
236
236
|
const cmd = {
|
|
237
|
-
[serverApi?.version || helloOk ? 'hello' :
|
|
237
|
+
[serverApi?.version || helloOk ? 'hello' : LEGACY_HELLO_COMMAND]: true,
|
|
238
238
|
...(isAwaitable && topologyVersion
|
|
239
239
|
? { maxAwaitTimeMS, topologyVersion: makeTopologyVersion(topologyVersion) }
|
|
240
240
|
: {})
|
|
@@ -257,14 +257,15 @@ function checkServer(monitor: Monitor, callback: Callback<Document>) {
|
|
|
257
257
|
);
|
|
258
258
|
}
|
|
259
259
|
|
|
260
|
-
connection.command(ns('admin.$cmd'), cmd, options, (err,
|
|
260
|
+
connection.command(ns('admin.$cmd'), cmd, options, (err, hello) => {
|
|
261
261
|
if (err) {
|
|
262
262
|
failureHandler(err);
|
|
263
263
|
return;
|
|
264
264
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
265
|
+
|
|
266
|
+
if (!('isWritablePrimary' in hello)) {
|
|
267
|
+
// Provide hello-style response document.
|
|
268
|
+
hello.isWritablePrimary = hello[LEGACY_HELLO_COMMAND];
|
|
268
269
|
}
|
|
269
270
|
|
|
270
271
|
const rttPinger = monitor[kRTTPinger];
|
|
@@ -273,12 +274,12 @@ function checkServer(monitor: Monitor, callback: Callback<Document>) {
|
|
|
273
274
|
|
|
274
275
|
monitor.emit(
|
|
275
276
|
Server.SERVER_HEARTBEAT_SUCCEEDED,
|
|
276
|
-
new ServerHeartbeatSucceededEvent(monitor.address, duration,
|
|
277
|
+
new ServerHeartbeatSucceededEvent(monitor.address, duration, hello)
|
|
277
278
|
);
|
|
278
279
|
|
|
279
280
|
// if we are using the streaming protocol then we immediately issue another `started`
|
|
280
281
|
// event, otherwise the "check" is complete and return to the main monitor loop
|
|
281
|
-
if (isAwaitable &&
|
|
282
|
+
if (isAwaitable && hello.topologyVersion) {
|
|
282
283
|
monitor.emit(
|
|
283
284
|
Server.SERVER_HEARTBEAT_STARTED,
|
|
284
285
|
new ServerHeartbeatStartedEvent(monitor.address)
|
|
@@ -288,14 +289,14 @@ function checkServer(monitor: Monitor, callback: Callback<Document>) {
|
|
|
288
289
|
monitor[kRTTPinger]?.close();
|
|
289
290
|
monitor[kRTTPinger] = undefined;
|
|
290
291
|
|
|
291
|
-
callback(undefined,
|
|
292
|
+
callback(undefined, hello);
|
|
292
293
|
}
|
|
293
294
|
});
|
|
294
295
|
|
|
295
296
|
return;
|
|
296
297
|
}
|
|
297
298
|
|
|
298
|
-
// connecting does an implicit `
|
|
299
|
+
// connecting does an implicit `hello`
|
|
299
300
|
connect(monitor.connectOptions, (err, conn) => {
|
|
300
301
|
if (err) {
|
|
301
302
|
monitor[kConnection] = undefined;
|
|
@@ -318,14 +319,10 @@ function checkServer(monitor: Monitor, callback: Callback<Document>) {
|
|
|
318
319
|
monitor[kConnection] = conn;
|
|
319
320
|
monitor.emit(
|
|
320
321
|
Server.SERVER_HEARTBEAT_SUCCEEDED,
|
|
321
|
-
new ServerHeartbeatSucceededEvent(
|
|
322
|
-
monitor.address,
|
|
323
|
-
calculateDurationInMs(start),
|
|
324
|
-
conn.ismaster
|
|
325
|
-
)
|
|
322
|
+
new ServerHeartbeatSucceededEvent(monitor.address, calculateDurationInMs(start), conn.hello)
|
|
326
323
|
);
|
|
327
324
|
|
|
328
|
-
callback(undefined, conn.
|
|
325
|
+
callback(undefined, conn.hello);
|
|
329
326
|
}
|
|
330
327
|
});
|
|
331
328
|
}
|
|
@@ -341,7 +338,7 @@ function monitorServer(monitor: Monitor) {
|
|
|
341
338
|
callback();
|
|
342
339
|
}
|
|
343
340
|
|
|
344
|
-
checkServer(monitor, (err,
|
|
341
|
+
checkServer(monitor, (err, hello) => {
|
|
345
342
|
if (err) {
|
|
346
343
|
// otherwise an error occurred on initial discovery, also bail
|
|
347
344
|
if (monitor[kServer].description.type === ServerType.Unknown) {
|
|
@@ -351,7 +348,7 @@ function monitorServer(monitor: Monitor) {
|
|
|
351
348
|
}
|
|
352
349
|
|
|
353
350
|
// if the check indicates streaming is supported, immediately reschedule monitoring
|
|
354
|
-
if (
|
|
351
|
+
if (hello && hello.topologyVersion) {
|
|
355
352
|
setTimeout(() => {
|
|
356
353
|
if (!isInCloseState(monitor)) {
|
|
357
354
|
monitor[kMonitorId]?.wake();
|
|
@@ -453,7 +450,7 @@ function measureRoundTripTime(rttPinger: RTTPinger, options: RTTPingerOptions) {
|
|
|
453
450
|
return;
|
|
454
451
|
}
|
|
455
452
|
|
|
456
|
-
connection.command(ns('admin.$cmd'), {
|
|
453
|
+
connection.command(ns('admin.$cmd'), { [LEGACY_HELLO_COMMAND]: 1 }, undefined, err => {
|
|
457
454
|
if (err) {
|
|
458
455
|
rttPinger[kConnection] = undefined;
|
|
459
456
|
rttPinger[kRoundTripTime] = 0;
|
package/src/sdam/server.ts
CHANGED
|
@@ -1,62 +1,72 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Document, Long } from '../bson';
|
|
2
|
+
import {
|
|
3
|
+
CommandOptions,
|
|
4
|
+
Connection,
|
|
5
|
+
DestroyOptions,
|
|
6
|
+
GetMoreOptions,
|
|
7
|
+
QueryOptions
|
|
8
|
+
} from '../cmap/connection';
|
|
2
9
|
import {
|
|
3
10
|
ConnectionPool,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
ConnectionPoolEvents
|
|
11
|
+
ConnectionPoolEvents,
|
|
12
|
+
ConnectionPoolOptions
|
|
7
13
|
} from '../cmap/connection_pool';
|
|
8
|
-
import {
|
|
9
|
-
|
|
14
|
+
import {
|
|
15
|
+
APM_EVENTS,
|
|
16
|
+
CLOSED,
|
|
17
|
+
CMAP_EVENTS,
|
|
18
|
+
CONNECT,
|
|
19
|
+
DESCRIPTION_RECEIVED,
|
|
20
|
+
ENDED,
|
|
21
|
+
HEARTBEAT_EVENTS,
|
|
22
|
+
SERVER_HEARTBEAT_FAILED,
|
|
23
|
+
SERVER_HEARTBEAT_STARTED,
|
|
24
|
+
SERVER_HEARTBEAT_SUCCEEDED
|
|
25
|
+
} from '../constants';
|
|
26
|
+
import type { AutoEncrypter } from '../deps';
|
|
27
|
+
import {
|
|
28
|
+
isNetworkErrorBeforeHandshake,
|
|
29
|
+
isNodeShuttingDownError,
|
|
30
|
+
isRetryableWriteError,
|
|
31
|
+
isSDAMUnrecoverableError,
|
|
32
|
+
MongoCompatibilityError,
|
|
33
|
+
MongoError,
|
|
34
|
+
MongoInvalidArgumentError,
|
|
35
|
+
MongoNetworkError,
|
|
36
|
+
MongoNetworkTimeoutError,
|
|
37
|
+
MongoServerClosedError
|
|
38
|
+
} from '../error';
|
|
39
|
+
import { Logger } from '../logger';
|
|
40
|
+
import type { ServerApi } from '../mongo_client';
|
|
41
|
+
import { TypedEventEmitter } from '../mongo_types';
|
|
42
|
+
import type { ClientSession } from '../sessions';
|
|
10
43
|
import { isTransactionCommand } from '../transactions';
|
|
11
44
|
import {
|
|
45
|
+
Callback,
|
|
46
|
+
CallbackWithType,
|
|
12
47
|
collationNotSupported,
|
|
48
|
+
EventEmitterWithState,
|
|
13
49
|
makeStateMachine,
|
|
14
50
|
maxWireVersion,
|
|
15
|
-
Callback,
|
|
16
|
-
CallbackWithType,
|
|
17
51
|
MongoDBNamespace,
|
|
18
|
-
|
|
52
|
+
supportsRetryableWrites
|
|
19
53
|
} from '../utils';
|
|
20
54
|
import {
|
|
55
|
+
ClusterTime,
|
|
21
56
|
STATE_CLOSED,
|
|
22
57
|
STATE_CLOSING,
|
|
23
|
-
STATE_CONNECTING,
|
|
24
58
|
STATE_CONNECTED,
|
|
25
|
-
|
|
59
|
+
STATE_CONNECTING,
|
|
26
60
|
TopologyType
|
|
27
61
|
} from './common';
|
|
28
|
-
import {
|
|
29
|
-
MongoError,
|
|
30
|
-
MongoNetworkError,
|
|
31
|
-
MongoNetworkTimeoutError,
|
|
32
|
-
isSDAMUnrecoverableError,
|
|
33
|
-
isRetryableWriteError,
|
|
34
|
-
isNodeShuttingDownError,
|
|
35
|
-
isNetworkErrorBeforeHandshake,
|
|
36
|
-
MongoCompatibilityError,
|
|
37
|
-
MongoInvalidArgumentError,
|
|
38
|
-
MongoServerClosedError
|
|
39
|
-
} from '../error';
|
|
40
|
-
import {
|
|
41
|
-
Connection,
|
|
42
|
-
DestroyOptions,
|
|
43
|
-
QueryOptions,
|
|
44
|
-
GetMoreOptions,
|
|
45
|
-
CommandOptions,
|
|
46
|
-
APM_EVENTS
|
|
47
|
-
} from '../cmap/connection';
|
|
48
|
-
import type { Topology } from './topology';
|
|
49
62
|
import type {
|
|
50
63
|
ServerHeartbeatFailedEvent,
|
|
51
64
|
ServerHeartbeatStartedEvent,
|
|
52
65
|
ServerHeartbeatSucceededEvent
|
|
53
66
|
} from './events';
|
|
54
|
-
import
|
|
55
|
-
import
|
|
56
|
-
import type {
|
|
57
|
-
import type { ServerApi } from '../mongo_client';
|
|
58
|
-
import { TypedEventEmitter } from '../mongo_types';
|
|
59
|
-
import { supportsRetryableWrites } from '../utils';
|
|
67
|
+
import { Monitor, MonitorOptions } from './monitor';
|
|
68
|
+
import { compareTopologyVersion, ServerDescription } from './server_description';
|
|
69
|
+
import type { Topology } from './topology';
|
|
60
70
|
|
|
61
71
|
const stateTransition = makeStateMachine({
|
|
62
72
|
[STATE_CLOSED]: [STATE_CLOSED, STATE_CONNECTING],
|
|
@@ -108,24 +118,23 @@ export class Server extends TypedEventEmitter<ServerEvents> {
|
|
|
108
118
|
/** @internal */
|
|
109
119
|
s: ServerPrivate;
|
|
110
120
|
serverApi?: ServerApi;
|
|
111
|
-
|
|
112
|
-
ismaster?: Document;
|
|
121
|
+
hello?: Document;
|
|
113
122
|
[kMonitor]: Monitor;
|
|
114
123
|
|
|
115
124
|
/** @event */
|
|
116
|
-
static readonly SERVER_HEARTBEAT_STARTED =
|
|
125
|
+
static readonly SERVER_HEARTBEAT_STARTED = SERVER_HEARTBEAT_STARTED;
|
|
117
126
|
/** @event */
|
|
118
|
-
static readonly SERVER_HEARTBEAT_SUCCEEDED =
|
|
127
|
+
static readonly SERVER_HEARTBEAT_SUCCEEDED = SERVER_HEARTBEAT_SUCCEEDED;
|
|
119
128
|
/** @event */
|
|
120
|
-
static readonly SERVER_HEARTBEAT_FAILED =
|
|
129
|
+
static readonly SERVER_HEARTBEAT_FAILED = SERVER_HEARTBEAT_FAILED;
|
|
121
130
|
/** @event */
|
|
122
|
-
static readonly CONNECT =
|
|
131
|
+
static readonly CONNECT = CONNECT;
|
|
123
132
|
/** @event */
|
|
124
|
-
static readonly DESCRIPTION_RECEIVED =
|
|
133
|
+
static readonly DESCRIPTION_RECEIVED = DESCRIPTION_RECEIVED;
|
|
125
134
|
/** @event */
|
|
126
|
-
static readonly CLOSED =
|
|
135
|
+
static readonly CLOSED = CLOSED;
|
|
127
136
|
/** @event */
|
|
128
|
-
static readonly ENDED =
|
|
137
|
+
static readonly ENDED = ENDED;
|
|
129
138
|
|
|
130
139
|
/**
|
|
131
140
|
* Create a server
|
|
@@ -184,6 +193,14 @@ export class Server extends TypedEventEmitter<ServerEvents> {
|
|
|
184
193
|
});
|
|
185
194
|
}
|
|
186
195
|
|
|
196
|
+
get clusterTime(): ClusterTime | undefined {
|
|
197
|
+
return this.s.topology.clusterTime;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
set clusterTime(clusterTime: ClusterTime | undefined) {
|
|
201
|
+
this.s.topology.clusterTime = clusterTime;
|
|
202
|
+
}
|
|
203
|
+
|
|
187
204
|
get description(): ServerDescription {
|
|
188
205
|
return this.s.description;
|
|
189
206
|
}
|
|
@@ -453,21 +470,6 @@ export class Server extends TypedEventEmitter<ServerEvents> {
|
|
|
453
470
|
}
|
|
454
471
|
}
|
|
455
472
|
|
|
456
|
-
export const HEARTBEAT_EVENTS = [
|
|
457
|
-
Server.SERVER_HEARTBEAT_STARTED,
|
|
458
|
-
Server.SERVER_HEARTBEAT_SUCCEEDED,
|
|
459
|
-
Server.SERVER_HEARTBEAT_FAILED
|
|
460
|
-
];
|
|
461
|
-
|
|
462
|
-
Object.defineProperty(Server.prototype, 'clusterTime', {
|
|
463
|
-
get() {
|
|
464
|
-
return this.s.topology.clusterTime;
|
|
465
|
-
},
|
|
466
|
-
set(clusterTime: ClusterTime) {
|
|
467
|
-
this.s.topology.clusterTime = clusterTime;
|
|
468
|
-
}
|
|
469
|
-
});
|
|
470
|
-
|
|
471
473
|
function calculateRoundTripTime(oldRtt: number, duration: number): number {
|
|
472
474
|
if (oldRtt === -1) {
|
|
473
475
|
return duration;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ServerType } from './common';
|
|
3
|
-
import { ObjectId, Long, Document } from '../bson';
|
|
4
|
-
import type { ClusterTime } from './common';
|
|
1
|
+
import { Document, Long, ObjectId } from '../bson';
|
|
5
2
|
import type { MongoError } from '../error';
|
|
3
|
+
import { arrayStrictEqual, errorStrictEqual, HostAddress, now } from '../utils';
|
|
4
|
+
import type { ClusterTime } from './common';
|
|
5
|
+
import { ServerType } from './common';
|
|
6
6
|
|
|
7
7
|
const WRITABLE_SERVER_TYPES = new Set<ServerType>([
|
|
8
8
|
ServerType.RSPrimary,
|
|
@@ -44,7 +44,7 @@ export interface ServerDescriptionOptions {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
|
-
* The client's view of a single server, based on the most recent
|
|
47
|
+
* The client's view of a single server, based on the most recent hello outcome.
|
|
48
48
|
*
|
|
49
49
|
* Internal type, not meant to be directly instantiated
|
|
50
50
|
* @public
|
|
@@ -81,13 +81,9 @@ export class ServerDescription {
|
|
|
81
81
|
* @internal
|
|
82
82
|
*
|
|
83
83
|
* @param address - The address of the server
|
|
84
|
-
* @param
|
|
84
|
+
* @param hello - An optional hello response for this server
|
|
85
85
|
*/
|
|
86
|
-
constructor(
|
|
87
|
-
address: HostAddress | string,
|
|
88
|
-
ismaster?: Document,
|
|
89
|
-
options?: ServerDescriptionOptions
|
|
90
|
-
) {
|
|
86
|
+
constructor(address: HostAddress | string, hello?: Document, options?: ServerDescriptionOptions) {
|
|
91
87
|
if (typeof address === 'string') {
|
|
92
88
|
this._hostAddress = new HostAddress(address);
|
|
93
89
|
this.address = this._hostAddress.toString();
|
|
@@ -95,53 +91,53 @@ export class ServerDescription {
|
|
|
95
91
|
this._hostAddress = address;
|
|
96
92
|
this.address = this._hostAddress.toString();
|
|
97
93
|
}
|
|
98
|
-
this.type = parseServerType(
|
|
99
|
-
this.hosts =
|
|
100
|
-
this.passives =
|
|
101
|
-
this.arbiters =
|
|
102
|
-
this.tags =
|
|
103
|
-
this.minWireVersion =
|
|
104
|
-
this.maxWireVersion =
|
|
94
|
+
this.type = parseServerType(hello, options);
|
|
95
|
+
this.hosts = hello?.hosts?.map((host: string) => host.toLowerCase()) ?? [];
|
|
96
|
+
this.passives = hello?.passives?.map((host: string) => host.toLowerCase()) ?? [];
|
|
97
|
+
this.arbiters = hello?.arbiters?.map((host: string) => host.toLowerCase()) ?? [];
|
|
98
|
+
this.tags = hello?.tags ?? {};
|
|
99
|
+
this.minWireVersion = hello?.minWireVersion ?? 0;
|
|
100
|
+
this.maxWireVersion = hello?.maxWireVersion ?? 0;
|
|
105
101
|
this.roundTripTime = options?.roundTripTime ?? -1;
|
|
106
102
|
this.lastUpdateTime = now();
|
|
107
|
-
this.lastWriteDate =
|
|
103
|
+
this.lastWriteDate = hello?.lastWrite?.lastWriteDate ?? 0;
|
|
108
104
|
|
|
109
105
|
if (options?.topologyVersion) {
|
|
110
106
|
this.topologyVersion = options.topologyVersion;
|
|
111
|
-
} else if (
|
|
112
|
-
this.topologyVersion =
|
|
107
|
+
} else if (hello?.topologyVersion) {
|
|
108
|
+
this.topologyVersion = hello.topologyVersion;
|
|
113
109
|
}
|
|
114
110
|
|
|
115
111
|
if (options?.error) {
|
|
116
112
|
this.error = options.error;
|
|
117
113
|
}
|
|
118
114
|
|
|
119
|
-
if (
|
|
120
|
-
this.primary =
|
|
115
|
+
if (hello?.primary) {
|
|
116
|
+
this.primary = hello.primary;
|
|
121
117
|
}
|
|
122
118
|
|
|
123
|
-
if (
|
|
124
|
-
this.me =
|
|
119
|
+
if (hello?.me) {
|
|
120
|
+
this.me = hello.me.toLowerCase();
|
|
125
121
|
}
|
|
126
122
|
|
|
127
|
-
if (
|
|
128
|
-
this.setName =
|
|
123
|
+
if (hello?.setName) {
|
|
124
|
+
this.setName = hello.setName;
|
|
129
125
|
}
|
|
130
126
|
|
|
131
|
-
if (
|
|
132
|
-
this.setVersion =
|
|
127
|
+
if (hello?.setVersion) {
|
|
128
|
+
this.setVersion = hello.setVersion;
|
|
133
129
|
}
|
|
134
130
|
|
|
135
|
-
if (
|
|
136
|
-
this.electionId =
|
|
131
|
+
if (hello?.electionId) {
|
|
132
|
+
this.electionId = hello.electionId;
|
|
137
133
|
}
|
|
138
134
|
|
|
139
|
-
if (
|
|
140
|
-
this.logicalSessionTimeoutMinutes =
|
|
135
|
+
if (hello?.logicalSessionTimeoutMinutes) {
|
|
136
|
+
this.logicalSessionTimeoutMinutes = hello.logicalSessionTimeoutMinutes;
|
|
141
137
|
}
|
|
142
138
|
|
|
143
|
-
if (
|
|
144
|
-
this.$clusterTime =
|
|
139
|
+
if (hello?.$clusterTime) {
|
|
140
|
+
this.$clusterTime = hello.$clusterTime;
|
|
145
141
|
}
|
|
146
142
|
}
|
|
147
143
|
|
|
@@ -210,35 +206,32 @@ export class ServerDescription {
|
|
|
210
206
|
}
|
|
211
207
|
}
|
|
212
208
|
|
|
213
|
-
// Parses
|
|
214
|
-
export function parseServerType(
|
|
215
|
-
ismaster?: Document,
|
|
216
|
-
options?: ServerDescriptionOptions
|
|
217
|
-
): ServerType {
|
|
209
|
+
// Parses a `hello` message and determines the server type
|
|
210
|
+
export function parseServerType(hello?: Document, options?: ServerDescriptionOptions): ServerType {
|
|
218
211
|
if (options?.loadBalanced) {
|
|
219
212
|
return ServerType.LoadBalancer;
|
|
220
213
|
}
|
|
221
214
|
|
|
222
|
-
if (!
|
|
215
|
+
if (!hello || !hello.ok) {
|
|
223
216
|
return ServerType.Unknown;
|
|
224
217
|
}
|
|
225
218
|
|
|
226
|
-
if (
|
|
219
|
+
if (hello.isreplicaset) {
|
|
227
220
|
return ServerType.RSGhost;
|
|
228
221
|
}
|
|
229
222
|
|
|
230
|
-
if (
|
|
223
|
+
if (hello.msg && hello.msg === 'isdbgrid') {
|
|
231
224
|
return ServerType.Mongos;
|
|
232
225
|
}
|
|
233
226
|
|
|
234
|
-
if (
|
|
235
|
-
if (
|
|
227
|
+
if (hello.setName) {
|
|
228
|
+
if (hello.hidden) {
|
|
236
229
|
return ServerType.RSOther;
|
|
237
|
-
} else if (
|
|
230
|
+
} else if (hello.isWritablePrimary) {
|
|
238
231
|
return ServerType.RSPrimary;
|
|
239
|
-
} else if (
|
|
232
|
+
} else if (hello.secondary) {
|
|
240
233
|
return ServerType.RSSecondary;
|
|
241
|
-
} else if (
|
|
234
|
+
} else if (hello.arbiterOnly) {
|
|
242
235
|
return ServerType.RSArbiter;
|
|
243
236
|
} else {
|
|
244
237
|
return ServerType.RSOther;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ServerType, TopologyType } from './common';
|
|
2
|
-
import { ReadPreference } from '../read_preference';
|
|
3
1
|
import { MongoCompatibilityError, MongoInvalidArgumentError } from '../error';
|
|
4
|
-
import
|
|
2
|
+
import { ReadPreference } from '../read_preference';
|
|
3
|
+
import { ServerType, TopologyType } from './common';
|
|
5
4
|
import type { ServerDescription, TagSet } from './server_description';
|
|
5
|
+
import type { TopologyDescription } from './topology_description';
|
|
6
6
|
|
|
7
7
|
// max staleness constants
|
|
8
8
|
const IDLE_WRITE_PERIOD = 10000;
|
package/src/sdam/srv_polling.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as dns from 'dns';
|
|
2
|
+
|
|
3
|
+
import { MongoRuntimeError } from '../error';
|
|
2
4
|
import { Logger, LoggerOptions } from '../logger';
|
|
3
|
-
import { HostAddress } from '../utils';
|
|
4
5
|
import { TypedEventEmitter } from '../mongo_types';
|
|
5
|
-
import {
|
|
6
|
+
import { HostAddress } from '../utils';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Determines whether a provided address matches the provided parent domain in order
|