mongodb 4.1.4 → 4.3.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 +16 -15
- 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 +3 -4
- 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 -7
- package/lib/change_stream.js.map +1 -1
- package/lib/cmap/auth/auth_provider.js.map +1 -1
- package/lib/cmap/auth/gssapi.js +3 -3
- package/lib/cmap/auth/gssapi.js.map +1 -1
- package/lib/cmap/auth/mongo_credentials.js +16 -18
- 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 +1 -1
- package/lib/cmap/command_monitoring_events.js.map +1 -1
- package/lib/cmap/commands.js +20 -11
- package/lib/cmap/commands.js.map +1 -1
- package/lib/cmap/connect.js +102 -15
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js +27 -26
- 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.map +1 -1
- package/lib/cmap/wire_protocol/constants.js +4 -4
- 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 +106 -49
- package/lib/connection_string.js.map +1 -1
- package/lib/constants.js +108 -1
- package/lib/constants.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +10 -7
- 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 +1 -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 +81 -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 +2 -2
- package/lib/operations/add_user.js.map +1 -1
- package/lib/operations/aggregate.js +2 -3
- 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 +9 -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 +23 -7
- 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 +28 -0
- package/lib/operations/get_more.js.map +1 -0
- 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 +11 -6
- 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 +4 -2
- 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/monitor.js +4 -4
- package/lib/sdam/monitor.js.map +1 -1
- package/lib/sdam/server.js +31 -31
- package/lib/sdam/server.js.map +1 -1
- package/lib/sdam/server_description.js +1 -1
- package/lib/sdam/server_description.js.map +1 -1
- package/lib/sdam/server_selection.js +38 -3
- package/lib/sdam/server_selection.js.map +1 -1
- package/lib/sdam/srv_polling.js +11 -11
- package/lib/sdam/srv_polling.js.map +1 -1
- package/lib/sdam/topology.js +40 -62
- package/lib/sdam/topology.js.map +1 -1
- package/lib/sdam/topology_description.js +36 -14
- 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 +90 -23
- package/lib/utils.js.map +1 -1
- package/mongodb.d.ts +159 -65
- package/mongodb.ts34.d.ts +184 -65
- package/package.json +26 -24
- package/src/admin.ts +9 -9
- package/src/bson.ts +26 -17
- package/src/bulk/common.ts +26 -20
- package/src/bulk/ordered.ts +4 -4
- package/src/bulk/unordered.ts +5 -5
- package/src/change_stream.ts +35 -32
- package/src/cmap/auth/auth_provider.ts +3 -3
- package/src/cmap/auth/gssapi.ts +8 -8
- package/src/cmap/auth/mongo_credentials.ts +2 -6
- 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 +2 -2
- package/src/cmap/commands.ts +30 -19
- package/src/cmap/connect.ts +142 -22
- package/src/cmap/connection.ts +73 -52
- 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 +2 -2
- package/src/cmap/wire_protocol/constants.ts +4 -4
- package/src/cmap/wire_protocol/shared.ts +10 -9
- package/src/collection.ts +133 -106
- package/src/connection_string.ts +141 -60
- package/src/constants.ts +116 -0
- package/src/cursor/abstract_cursor.ts +21 -22
- package/src/cursor/aggregation_cursor.ts +6 -6
- package/src/cursor/find_cursor.ts +2 -2
- package/src/db.ts +49 -39
- package/src/deps.ts +3 -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 +204 -199
- package/src/logger.ts +2 -1
- package/src/mongo_client.ts +58 -32
- package/src/mongo_types.ts +98 -20
- package/src/operations/add_user.ts +6 -5
- package/src/operations/aggregate.ts +6 -7
- package/src/operations/bulk_write.ts +5 -5
- package/src/operations/collections.ts +2 -2
- package/src/operations/command.ts +19 -8
- 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 +8 -7
- 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 +30 -11
- package/src/operations/find.ts +14 -14
- package/src/operations/find_and_modify.ts +7 -7
- package/src/operations/get_more.ts +49 -0
- 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 +18 -10
- package/src/operations/list_databases.ts +4 -4
- package/src/operations/map_reduce.ts +10 -9
- package/src/operations/operation.ts +8 -4
- 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 +1 -1
- package/src/sdam/monitor.ts +13 -14
- package/src/sdam/server.ts +71 -61
- package/src/sdam/server_description.ts +4 -4
- package/src/sdam/server_selection.ts +46 -3
- package/src/sdam/srv_polling.ts +15 -13
- package/src/sdam/topology.ts +89 -90
- package/src/sdam/topology_description.ts +39 -15
- package/src/sessions.ts +31 -48
- package/src/transactions.ts +6 -6
- package/src/utils.ts +123 -43
- 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/read_preference.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { TagSet } from './sdam/server_description';
|
|
2
1
|
import type { Document } from './bson';
|
|
3
|
-
import type { ClientSession } from './sessions';
|
|
4
2
|
import { MongoInvalidArgumentError } from './error';
|
|
3
|
+
import type { TagSet } from './sdam/server_description';
|
|
4
|
+
import type { ClientSession } from './sessions';
|
|
5
5
|
|
|
6
6
|
/** @public */
|
|
7
7
|
export type ReadPreferenceLike = ReadPreference | ReadPreferenceMode;
|
|
@@ -156,7 +156,10 @@ export class ReadPreference {
|
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
if (typeof readPreference === 'string') {
|
|
159
|
-
return new ReadPreference(readPreference as ReadPreferenceMode, readPreferenceTags
|
|
159
|
+
return new ReadPreference(readPreference as ReadPreferenceMode, readPreferenceTags, {
|
|
160
|
+
maxStalenessSeconds: options.maxStalenessSeconds,
|
|
161
|
+
hedge: options.hedge
|
|
162
|
+
});
|
|
160
163
|
} else if (!(readPreference instanceof ReadPreference) && typeof readPreference === 'object') {
|
|
161
164
|
const mode = readPreference.mode || readPreference.preference;
|
|
162
165
|
if (mode && typeof mode === 'string') {
|
|
@@ -229,19 +232,27 @@ export class ReadPreference {
|
|
|
229
232
|
}
|
|
230
233
|
|
|
231
234
|
/**
|
|
232
|
-
* Indicates that this readPreference needs the "
|
|
233
|
-
*
|
|
235
|
+
* Indicates that this readPreference needs the "secondaryOk" bit when sent over the wire
|
|
236
|
+
* @deprecated Use secondaryOk instead
|
|
234
237
|
* @see https://docs.mongodb.com/manual/reference/mongodb-wire-protocol/#op-query
|
|
235
238
|
*/
|
|
236
239
|
slaveOk(): boolean {
|
|
237
|
-
|
|
240
|
+
return this.secondaryOk();
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Indicates that this readPreference needs the "SecondaryOk" bit when sent over the wire
|
|
245
|
+
* @see https://docs.mongodb.com/manual/reference/mongodb-wire-protocol/#op-query
|
|
246
|
+
*/
|
|
247
|
+
secondaryOk(): boolean {
|
|
248
|
+
const NEEDS_SECONDARYOK = new Set<string>([
|
|
238
249
|
ReadPreference.PRIMARY_PREFERRED,
|
|
239
250
|
ReadPreference.SECONDARY,
|
|
240
251
|
ReadPreference.SECONDARY_PREFERRED,
|
|
241
252
|
ReadPreference.NEAREST
|
|
242
253
|
]);
|
|
243
254
|
|
|
244
|
-
return
|
|
255
|
+
return NEEDS_SECONDARYOK.has(this.mode);
|
|
245
256
|
}
|
|
246
257
|
|
|
247
258
|
/**
|
package/src/sdam/common.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { Topology } from './topology';
|
|
1
|
+
import type { Binary, Long, Timestamp } from '../bson';
|
|
3
2
|
import type { ClientSession } from '../sessions';
|
|
3
|
+
import type { Topology } from './topology';
|
|
4
4
|
|
|
5
5
|
// shared state names
|
|
6
6
|
export const STATE_CLOSING = 'closing';
|
package/src/sdam/events.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { Document } from '../bson';
|
|
1
2
|
import type { ServerDescription } from './server_description';
|
|
2
3
|
import type { TopologyDescription } from './topology_description';
|
|
3
|
-
import type { Document } from '../bson';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Emitted when server description changes, but does NOT include changes to the RTT.
|
package/src/sdam/monitor.ts
CHANGED
|
@@ -1,26 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Document, Long } from '../bson';
|
|
2
|
+
import { connect } from '../cmap/connect';
|
|
3
|
+
import { Connection, ConnectionOptions } from '../cmap/connection';
|
|
4
|
+
import { AnyError, MongoNetworkError } from '../error';
|
|
5
|
+
import { CancellationToken, TypedEventEmitter } from '../mongo_types';
|
|
6
|
+
import type { Callback, InterruptibleAsyncInterval } from '../utils';
|
|
2
7
|
import {
|
|
3
|
-
now,
|
|
4
|
-
makeStateMachine,
|
|
5
8
|
calculateDurationInMs,
|
|
9
|
+
EventEmitterWithState,
|
|
6
10
|
makeInterruptibleAsyncInterval,
|
|
7
|
-
|
|
8
|
-
|
|
11
|
+
makeStateMachine,
|
|
12
|
+
now,
|
|
13
|
+
ns
|
|
9
14
|
} from '../utils';
|
|
10
|
-
import {
|
|
11
|
-
import { Connection, ConnectionOptions } from '../cmap/connection';
|
|
12
|
-
import { MongoNetworkError, AnyError } from '../error';
|
|
13
|
-
import { Long, Document } from '../bson';
|
|
15
|
+
import { ServerType, STATE_CLOSED, STATE_CLOSING } from './common';
|
|
14
16
|
import {
|
|
17
|
+
ServerHeartbeatFailedEvent,
|
|
15
18
|
ServerHeartbeatStartedEvent,
|
|
16
|
-
ServerHeartbeatSucceededEvent
|
|
17
|
-
ServerHeartbeatFailedEvent
|
|
19
|
+
ServerHeartbeatSucceededEvent
|
|
18
20
|
} from './events';
|
|
19
|
-
|
|
20
21
|
import { Server } from './server';
|
|
21
|
-
import type { InterruptibleAsyncInterval, Callback } from '../utils';
|
|
22
22
|
import type { TopologyVersion } from './server_description';
|
|
23
|
-
import { CancellationToken, TypedEventEmitter } from '../mongo_types';
|
|
24
23
|
|
|
25
24
|
/** @internal */
|
|
26
25
|
const kServer = Symbol('server');
|
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
|
-
clusterTime?: ClusterTime;
|
|
112
121
|
ismaster?: 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
|
}
|
|
@@ -299,6 +316,14 @@ export class Server extends TypedEventEmitter<ServerEvents> {
|
|
|
299
316
|
// Clone the options
|
|
300
317
|
const finalOptions = Object.assign({}, options, { wireProtocolCommand: false });
|
|
301
318
|
|
|
319
|
+
// There are cases where we need to flag the read preference not to get sent in
|
|
320
|
+
// the command, such as pre-5.0 servers attempting to perform an aggregate write
|
|
321
|
+
// with a non-primary read preference. In this case the effective read preference
|
|
322
|
+
// (primary) is not the same as the provided and must be removed completely.
|
|
323
|
+
if (finalOptions.omitReadPreference) {
|
|
324
|
+
delete finalOptions.readPreference;
|
|
325
|
+
}
|
|
326
|
+
|
|
302
327
|
// error if collation not supported
|
|
303
328
|
if (collationNotSupported(this, cmd)) {
|
|
304
329
|
callback(new MongoCompatibilityError(`Server ${this.name} does not support collation`));
|
|
@@ -445,21 +470,6 @@ export class Server extends TypedEventEmitter<ServerEvents> {
|
|
|
445
470
|
}
|
|
446
471
|
}
|
|
447
472
|
|
|
448
|
-
export const HEARTBEAT_EVENTS = [
|
|
449
|
-
Server.SERVER_HEARTBEAT_STARTED,
|
|
450
|
-
Server.SERVER_HEARTBEAT_SUCCEEDED,
|
|
451
|
-
Server.SERVER_HEARTBEAT_FAILED
|
|
452
|
-
];
|
|
453
|
-
|
|
454
|
-
Object.defineProperty(Server.prototype, 'clusterTime', {
|
|
455
|
-
get() {
|
|
456
|
-
return this.s.topology.clusterTime;
|
|
457
|
-
},
|
|
458
|
-
set(clusterTime: ClusterTime) {
|
|
459
|
-
this.s.topology.clusterTime = clusterTime;
|
|
460
|
-
}
|
|
461
|
-
});
|
|
462
|
-
|
|
463
473
|
function calculateRoundTripTime(oldRtt: number, duration: number): number {
|
|
464
474
|
if (oldRtt === -1) {
|
|
465
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,
|
|
@@ -1,13 +1,16 @@
|
|
|
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;
|
|
9
9
|
const SMALLEST_MAX_STALENESS_SECONDS = 90;
|
|
10
10
|
|
|
11
|
+
// Minimum version to try writes on secondaries.
|
|
12
|
+
export const MIN_SECONDARY_WRITE_WIRE_VERSION = 13;
|
|
13
|
+
|
|
11
14
|
/** @public */
|
|
12
15
|
export type ServerSelector = (
|
|
13
16
|
topologyDescription: TopologyDescription,
|
|
@@ -28,6 +31,46 @@ export function writableServerSelector(): ServerSelector {
|
|
|
28
31
|
);
|
|
29
32
|
}
|
|
30
33
|
|
|
34
|
+
/**
|
|
35
|
+
* The purpose of this selector is to select the same server, only
|
|
36
|
+
* if it is in a state that it can have commands sent to it.
|
|
37
|
+
*/
|
|
38
|
+
export function sameServerSelector(description?: ServerDescription): ServerSelector {
|
|
39
|
+
return (
|
|
40
|
+
topologyDescription: TopologyDescription,
|
|
41
|
+
servers: ServerDescription[]
|
|
42
|
+
): ServerDescription[] => {
|
|
43
|
+
if (!description) return [];
|
|
44
|
+
// Filter the servers to match the provided description only if
|
|
45
|
+
// the type is not unknown.
|
|
46
|
+
return servers.filter(sd => {
|
|
47
|
+
return sd.address === description.address && sd.type !== ServerType.Unknown;
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Returns a server selector that uses a read preference to select a
|
|
54
|
+
* server potentially for a write on a secondary.
|
|
55
|
+
*/
|
|
56
|
+
export function secondaryWritableServerSelector(
|
|
57
|
+
wireVersion?: number,
|
|
58
|
+
readPreference?: ReadPreference
|
|
59
|
+
): ServerSelector {
|
|
60
|
+
// If server version < 5.0, read preference always primary.
|
|
61
|
+
// If server version >= 5.0...
|
|
62
|
+
// - If read preference is supplied, use that.
|
|
63
|
+
// - If no read preference is supplied, use primary.
|
|
64
|
+
if (
|
|
65
|
+
!readPreference ||
|
|
66
|
+
!wireVersion ||
|
|
67
|
+
(wireVersion && wireVersion < MIN_SECONDARY_WRITE_WIRE_VERSION)
|
|
68
|
+
) {
|
|
69
|
+
return readPreferenceServerSelector(ReadPreference.primary);
|
|
70
|
+
}
|
|
71
|
+
return readPreferenceServerSelector(readPreference);
|
|
72
|
+
}
|
|
73
|
+
|
|
31
74
|
/**
|
|
32
75
|
* Reduces the passed in array of servers by the rules of the "Max Staleness" specification
|
|
33
76
|
* found here: https://github.com/mongodb/specifications/blob/master/source/max-staleness/max-staleness.rst
|
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
|
|
@@ -29,18 +30,15 @@ export class SrvPollingEvent {
|
|
|
29
30
|
this.srvRecords = srvRecords;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
return new
|
|
34
|
-
this.srvRecords.map(record => {
|
|
35
|
-
const host = new HostAddress(`${record.name}:${record.port}`);
|
|
36
|
-
return [host.toString(), host];
|
|
37
|
-
})
|
|
38
|
-
);
|
|
33
|
+
hostnames(): Set<string> {
|
|
34
|
+
return new Set(this.srvRecords.map(r => HostAddress.fromSrvRecord(r).toString()));
|
|
39
35
|
}
|
|
40
36
|
}
|
|
41
37
|
|
|
42
38
|
/** @internal */
|
|
43
39
|
export interface SrvPollerOptions extends LoggerOptions {
|
|
40
|
+
srvServiceName: string;
|
|
41
|
+
srvMaxHosts: number;
|
|
44
42
|
srvHost: string;
|
|
45
43
|
heartbeatFrequencyMS: number;
|
|
46
44
|
}
|
|
@@ -58,6 +56,8 @@ export class SrvPoller extends TypedEventEmitter<SrvPollerEvents> {
|
|
|
58
56
|
logger: Logger;
|
|
59
57
|
haMode: boolean;
|
|
60
58
|
generation: number;
|
|
59
|
+
srvMaxHosts: number;
|
|
60
|
+
srvServiceName: string;
|
|
61
61
|
_timeout?: NodeJS.Timeout;
|
|
62
62
|
|
|
63
63
|
/** @event */
|
|
@@ -71,8 +71,10 @@ export class SrvPoller extends TypedEventEmitter<SrvPollerEvents> {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
this.srvHost = options.srvHost;
|
|
74
|
+
this.srvMaxHosts = options.srvMaxHosts ?? 0;
|
|
75
|
+
this.srvServiceName = options.srvServiceName ?? 'mongodb';
|
|
74
76
|
this.rescanSrvIntervalMS = 60000;
|
|
75
|
-
this.heartbeatFrequencyMS = options.heartbeatFrequencyMS
|
|
77
|
+
this.heartbeatFrequencyMS = options.heartbeatFrequencyMS ?? 10000;
|
|
76
78
|
this.logger = new Logger('srvPoller', options);
|
|
77
79
|
|
|
78
80
|
this.haMode = false;
|
|
@@ -82,7 +84,7 @@ export class SrvPoller extends TypedEventEmitter<SrvPollerEvents> {
|
|
|
82
84
|
}
|
|
83
85
|
|
|
84
86
|
get srvAddress(): string {
|
|
85
|
-
return `
|
|
87
|
+
return `_${this.srvServiceName}._tcp.${this.srvHost}`;
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
get intervalMS(): number {
|
|
@@ -143,13 +145,13 @@ export class SrvPoller extends TypedEventEmitter<SrvPollerEvents> {
|
|
|
143
145
|
}
|
|
144
146
|
|
|
145
147
|
const finalAddresses: dns.SrvRecord[] = [];
|
|
146
|
-
|
|
148
|
+
for (const record of srvRecords) {
|
|
147
149
|
if (matchesParentDomain(record.name, this.srvHost)) {
|
|
148
150
|
finalAddresses.push(record);
|
|
149
151
|
} else {
|
|
150
152
|
this.parentDomainMismatch(record);
|
|
151
153
|
}
|
|
152
|
-
}
|
|
154
|
+
}
|
|
153
155
|
|
|
154
156
|
if (!finalAddresses.length) {
|
|
155
157
|
this.failure('No valid addresses found at host');
|