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/sdam/topology.ts
CHANGED
|
@@ -1,87 +1,83 @@
|
|
|
1
1
|
import Denque = require('denque');
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import type { BSONSerializeOptions, Document } from '../bson';
|
|
3
|
+
import { deserialize, serialize } from '../bson';
|
|
4
|
+
import type { MongoCredentials } from '../cmap/auth/mongo_credentials';
|
|
5
|
+
import type { ConnectionEvents, DestroyOptions } from '../cmap/connection';
|
|
6
|
+
import type { CloseOptions, ConnectionPoolEvents } from '../cmap/connection_pool';
|
|
7
|
+
import { DEFAULT_OPTIONS } from '../connection_string';
|
|
6
8
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
CLOSE,
|
|
10
|
+
CONNECT,
|
|
11
|
+
ERROR,
|
|
12
|
+
LOCAL_SERVER_EVENTS,
|
|
13
|
+
OPEN,
|
|
14
|
+
SERVER_CLOSED,
|
|
15
|
+
SERVER_DESCRIPTION_CHANGED,
|
|
16
|
+
SERVER_OPENING,
|
|
17
|
+
SERVER_RELAY_EVENTS,
|
|
18
|
+
TIMEOUT,
|
|
19
|
+
TOPOLOGY_CLOSED,
|
|
20
|
+
TOPOLOGY_DESCRIPTION_CHANGED,
|
|
21
|
+
TOPOLOGY_OPENING
|
|
22
|
+
} from '../constants';
|
|
14
23
|
import {
|
|
15
|
-
MongoServerSelectionError,
|
|
16
24
|
MongoCompatibilityError,
|
|
17
25
|
MongoDriverError,
|
|
18
|
-
|
|
19
|
-
|
|
26
|
+
MongoRuntimeError,
|
|
27
|
+
MongoServerSelectionError,
|
|
28
|
+
MongoTopologyClosedError
|
|
20
29
|
} from '../error';
|
|
21
|
-
import {
|
|
30
|
+
import type { MongoOptions, ServerApi } from '../mongo_client';
|
|
31
|
+
import { TypedEventEmitter } from '../mongo_types';
|
|
32
|
+
import { ReadPreference, ReadPreferenceLike } from '../read_preference';
|
|
33
|
+
import {
|
|
34
|
+
ClientSession,
|
|
35
|
+
ClientSessionOptions,
|
|
36
|
+
ServerSessionId,
|
|
37
|
+
ServerSessionPool
|
|
38
|
+
} from '../sessions';
|
|
39
|
+
import type { Transaction } from '../transactions';
|
|
22
40
|
import {
|
|
23
|
-
makeStateMachine,
|
|
24
|
-
eachAsync,
|
|
25
|
-
ClientMetadata,
|
|
26
41
|
Callback,
|
|
42
|
+
ClientMetadata,
|
|
43
|
+
eachAsync,
|
|
44
|
+
emitWarning,
|
|
45
|
+
EventEmitterWithState,
|
|
27
46
|
HostAddress,
|
|
47
|
+
makeStateMachine,
|
|
28
48
|
ns,
|
|
29
|
-
|
|
30
|
-
EventEmitterWithState
|
|
49
|
+
shuffle
|
|
31
50
|
} from '../utils';
|
|
32
51
|
import {
|
|
33
|
-
TopologyType,
|
|
34
|
-
ServerType,
|
|
35
|
-
ClusterTime,
|
|
36
|
-
TimerQueue,
|
|
37
52
|
_advanceClusterTime,
|
|
38
|
-
drainTimerQueue,
|
|
39
53
|
clearAndRemoveTimerFrom,
|
|
54
|
+
ClusterTime,
|
|
55
|
+
drainTimerQueue,
|
|
56
|
+
ServerType,
|
|
40
57
|
STATE_CLOSED,
|
|
41
58
|
STATE_CLOSING,
|
|
59
|
+
STATE_CONNECTED,
|
|
42
60
|
STATE_CONNECTING,
|
|
43
|
-
|
|
61
|
+
TimerQueue,
|
|
62
|
+
TopologyType
|
|
44
63
|
} from './common';
|
|
45
64
|
import {
|
|
46
|
-
ServerOpeningEvent,
|
|
47
65
|
ServerClosedEvent,
|
|
48
66
|
ServerDescriptionChangedEvent,
|
|
49
|
-
|
|
67
|
+
ServerOpeningEvent,
|
|
50
68
|
TopologyClosedEvent,
|
|
51
|
-
TopologyDescriptionChangedEvent
|
|
69
|
+
TopologyDescriptionChangedEvent,
|
|
70
|
+
TopologyOpeningEvent
|
|
52
71
|
} from './events';
|
|
53
|
-
import
|
|
54
|
-
import
|
|
55
|
-
import
|
|
56
|
-
import
|
|
57
|
-
import {
|
|
58
|
-
import type { MongoOptions, ServerApi } from '../mongo_client';
|
|
59
|
-
import { DEFAULT_OPTIONS } from '../connection_string';
|
|
60
|
-
import { serialize, deserialize } from '../bson';
|
|
61
|
-
import { TypedEventEmitter } from '../mongo_types';
|
|
72
|
+
import { Server, ServerEvents, ServerOptions } from './server';
|
|
73
|
+
import { compareTopologyVersion, ServerDescription } from './server_description';
|
|
74
|
+
import { readPreferenceServerSelector, ServerSelector } from './server_selection';
|
|
75
|
+
import { SrvPoller, SrvPollingEvent } from './srv_polling';
|
|
76
|
+
import { TopologyDescription } from './topology_description';
|
|
62
77
|
|
|
63
78
|
// Global state
|
|
64
79
|
let globalTopologyCounter = 0;
|
|
65
80
|
|
|
66
|
-
// events that we relay to the `Topology`
|
|
67
|
-
const SERVER_RELAY_EVENTS = [
|
|
68
|
-
Server.SERVER_HEARTBEAT_STARTED,
|
|
69
|
-
Server.SERVER_HEARTBEAT_SUCCEEDED,
|
|
70
|
-
Server.SERVER_HEARTBEAT_FAILED,
|
|
71
|
-
Connection.COMMAND_STARTED,
|
|
72
|
-
Connection.COMMAND_SUCCEEDED,
|
|
73
|
-
Connection.COMMAND_FAILED,
|
|
74
|
-
...CMAP_EVENTS
|
|
75
|
-
];
|
|
76
|
-
|
|
77
|
-
// all events we listen to from `Server` instances
|
|
78
|
-
const LOCAL_SERVER_EVENTS = [
|
|
79
|
-
Server.CONNECT,
|
|
80
|
-
Server.DESCRIPTION_RECEIVED,
|
|
81
|
-
Server.CLOSED,
|
|
82
|
-
Server.ENDED
|
|
83
|
-
];
|
|
84
|
-
|
|
85
81
|
const stateTransition = makeStateMachine({
|
|
86
82
|
[STATE_CLOSED]: [STATE_CLOSED, STATE_CONNECTING],
|
|
87
83
|
[STATE_CONNECTING]: [STATE_CONNECTING, STATE_CLOSING, STATE_CONNECTED, STATE_CLOSED],
|
|
@@ -140,6 +136,8 @@ export interface TopologyPrivate {
|
|
|
140
136
|
|
|
141
137
|
/** @public */
|
|
142
138
|
export interface TopologyOptions extends BSONSerializeOptions, ServerOptions {
|
|
139
|
+
srvMaxHosts: number;
|
|
140
|
+
srvServiceName: string;
|
|
143
141
|
hosts: HostAddress[];
|
|
144
142
|
retryWrites: boolean;
|
|
145
143
|
retryReads: boolean;
|
|
@@ -182,8 +180,8 @@ export type TopologyEvents = {
|
|
|
182
180
|
topologyOpening(event: TopologyOpeningEvent): void;
|
|
183
181
|
topologyDescriptionChanged(event: TopologyDescriptionChangedEvent): void;
|
|
184
182
|
error(error: Error): void;
|
|
185
|
-
/**
|
|
186
|
-
open(
|
|
183
|
+
/** @internal */
|
|
184
|
+
open(topology: Topology): void;
|
|
187
185
|
close(): void;
|
|
188
186
|
timeout(): void;
|
|
189
187
|
} & Omit<ServerEvents, 'connect'> &
|
|
@@ -205,27 +203,27 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
|
|
|
205
203
|
_type?: string;
|
|
206
204
|
|
|
207
205
|
/** @event */
|
|
208
|
-
static readonly SERVER_OPENING =
|
|
206
|
+
static readonly SERVER_OPENING = SERVER_OPENING;
|
|
209
207
|
/** @event */
|
|
210
|
-
static readonly SERVER_CLOSED =
|
|
208
|
+
static readonly SERVER_CLOSED = SERVER_CLOSED;
|
|
211
209
|
/** @event */
|
|
212
|
-
static readonly SERVER_DESCRIPTION_CHANGED =
|
|
210
|
+
static readonly SERVER_DESCRIPTION_CHANGED = SERVER_DESCRIPTION_CHANGED;
|
|
213
211
|
/** @event */
|
|
214
|
-
static readonly TOPOLOGY_OPENING =
|
|
212
|
+
static readonly TOPOLOGY_OPENING = TOPOLOGY_OPENING;
|
|
215
213
|
/** @event */
|
|
216
|
-
static readonly TOPOLOGY_CLOSED =
|
|
214
|
+
static readonly TOPOLOGY_CLOSED = TOPOLOGY_CLOSED;
|
|
217
215
|
/** @event */
|
|
218
|
-
static readonly TOPOLOGY_DESCRIPTION_CHANGED =
|
|
216
|
+
static readonly TOPOLOGY_DESCRIPTION_CHANGED = TOPOLOGY_DESCRIPTION_CHANGED;
|
|
219
217
|
/** @event */
|
|
220
|
-
static readonly ERROR =
|
|
218
|
+
static readonly ERROR = ERROR;
|
|
221
219
|
/** @event */
|
|
222
|
-
static readonly OPEN =
|
|
220
|
+
static readonly OPEN = OPEN;
|
|
223
221
|
/** @event */
|
|
224
|
-
static readonly CONNECT =
|
|
222
|
+
static readonly CONNECT = CONNECT;
|
|
225
223
|
/** @event */
|
|
226
|
-
static readonly CLOSE =
|
|
224
|
+
static readonly CLOSE = CLOSE;
|
|
227
225
|
/** @event */
|
|
228
|
-
static readonly TIMEOUT =
|
|
226
|
+
static readonly TIMEOUT = TIMEOUT;
|
|
229
227
|
|
|
230
228
|
/**
|
|
231
229
|
* @internal
|
|
@@ -290,8 +288,15 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
|
|
|
290
288
|
const topologyType = topologyTypeFromOptions(options);
|
|
291
289
|
const topologyId = globalTopologyCounter++;
|
|
292
290
|
|
|
291
|
+
const selectedHosts =
|
|
292
|
+
options.srvMaxHosts == null ||
|
|
293
|
+
options.srvMaxHosts === 0 ||
|
|
294
|
+
options.srvMaxHosts >= seedlist.length
|
|
295
|
+
? seedlist
|
|
296
|
+
: shuffle(seedlist, options.srvMaxHosts);
|
|
297
|
+
|
|
293
298
|
const serverDescriptions = new Map();
|
|
294
|
-
for (const hostAddress of
|
|
299
|
+
for (const hostAddress of selectedHosts) {
|
|
295
300
|
serverDescriptions.set(hostAddress.toString(), new ServerDescription(hostAddress));
|
|
296
301
|
}
|
|
297
302
|
|
|
@@ -339,7 +344,9 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
|
|
|
339
344
|
options.srvPoller ??
|
|
340
345
|
new SrvPoller({
|
|
341
346
|
heartbeatFrequencyMS: this.s.heartbeatFrequencyMS,
|
|
342
|
-
srvHost: options.srvHost
|
|
347
|
+
srvHost: options.srvHost,
|
|
348
|
+
srvMaxHosts: options.srvMaxHosts,
|
|
349
|
+
srvServiceName: options.srvServiceName
|
|
343
350
|
});
|
|
344
351
|
|
|
345
352
|
this.on(Topology.TOPOLOGY_DESCRIPTION_CHANGED, this.s.detectShardedTopology);
|
|
@@ -363,7 +370,10 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
|
|
|
363
370
|
|
|
364
371
|
private detectSrvRecords(ev: SrvPollingEvent) {
|
|
365
372
|
const previousTopologyDescription = this.s.description;
|
|
366
|
-
this.s.description = this.s.description.updateFromSrvPollingEvent(
|
|
373
|
+
this.s.description = this.s.description.updateFromSrvPollingEvent(
|
|
374
|
+
ev,
|
|
375
|
+
this.s.options.srvMaxHosts
|
|
376
|
+
);
|
|
367
377
|
if (this.s.description === previousTopologyDescription) {
|
|
368
378
|
// Nothing changed, so return
|
|
369
379
|
return;
|
|
@@ -456,8 +466,7 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
|
|
|
456
466
|
}
|
|
457
467
|
|
|
458
468
|
stateTransition(this, STATE_CONNECTED);
|
|
459
|
-
|
|
460
|
-
this.emit(Topology.OPEN, err, this);
|
|
469
|
+
this.emit(Topology.OPEN, this);
|
|
461
470
|
this.emit(Topology.CONNECT, this);
|
|
462
471
|
|
|
463
472
|
if (typeof callback === 'function') callback(undefined, this);
|
|
@@ -467,8 +476,7 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
|
|
|
467
476
|
}
|
|
468
477
|
|
|
469
478
|
stateTransition(this, STATE_CONNECTED);
|
|
470
|
-
|
|
471
|
-
this.emit(Topology.OPEN, err, this);
|
|
479
|
+
this.emit(Topology.OPEN, this);
|
|
472
480
|
this.emit(Topology.CONNECT, this);
|
|
473
481
|
|
|
474
482
|
if (typeof callback === 'function') callback(undefined, this);
|
|
@@ -797,6 +805,10 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
|
|
|
797
805
|
return result;
|
|
798
806
|
}
|
|
799
807
|
|
|
808
|
+
get commonWireVersion(): number | undefined {
|
|
809
|
+
return this.description.commonWireVersion;
|
|
810
|
+
}
|
|
811
|
+
|
|
800
812
|
get logicalSessionTimeoutMinutes(): number | undefined {
|
|
801
813
|
return this.description.logicalSessionTimeoutMinutes;
|
|
802
814
|
}
|
|
@@ -810,19 +822,6 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
|
|
|
810
822
|
}
|
|
811
823
|
}
|
|
812
824
|
|
|
813
|
-
/** @public */
|
|
814
|
-
export const TOPOLOGY_EVENTS = [
|
|
815
|
-
Topology.SERVER_OPENING,
|
|
816
|
-
Topology.SERVER_CLOSED,
|
|
817
|
-
Topology.SERVER_DESCRIPTION_CHANGED,
|
|
818
|
-
Topology.TOPOLOGY_OPENING,
|
|
819
|
-
Topology.TOPOLOGY_CLOSED,
|
|
820
|
-
Topology.TOPOLOGY_DESCRIPTION_CHANGED,
|
|
821
|
-
Topology.ERROR,
|
|
822
|
-
Topology.TIMEOUT,
|
|
823
|
-
Topology.CLOSE
|
|
824
|
-
];
|
|
825
|
-
|
|
826
825
|
/** Destroys a server, and removes all event listeners from the instance */
|
|
827
826
|
function destroyServer(
|
|
828
827
|
server: Server,
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Document, ObjectId } from '../bson';
|
|
2
2
|
import * as WIRE_CONSTANTS from '../cmap/wire_protocol/constants';
|
|
3
|
-
import { TopologyType, ServerType } from './common';
|
|
4
|
-
import type { ObjectId, Document } from '../bson';
|
|
5
|
-
import type { SrvPollingEvent } from './srv_polling';
|
|
6
3
|
import { MongoError, MongoRuntimeError } from '../error';
|
|
4
|
+
import { shuffle } from '../utils';
|
|
5
|
+
import { ServerType, TopologyType } from './common';
|
|
6
|
+
import { ServerDescription } from './server_description';
|
|
7
|
+
import type { SrvPollingEvent } from './srv_polling';
|
|
7
8
|
|
|
8
9
|
// constants related to compatibility checks
|
|
9
10
|
const MIN_SUPPORTED_SERVER_VERSION = WIRE_CONSTANTS.MIN_SUPPORTED_SERVER_VERSION;
|
|
@@ -139,23 +140,46 @@ export class TopologyDescription {
|
|
|
139
140
|
* Returns a new TopologyDescription based on the SrvPollingEvent
|
|
140
141
|
* @internal
|
|
141
142
|
*/
|
|
142
|
-
updateFromSrvPollingEvent(ev: SrvPollingEvent): TopologyDescription {
|
|
143
|
-
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
143
|
+
updateFromSrvPollingEvent(ev: SrvPollingEvent, srvMaxHosts = 0): TopologyDescription {
|
|
144
|
+
/** The SRV addresses defines the set of addresses we should be using */
|
|
145
|
+
const incomingHostnames = ev.hostnames();
|
|
146
|
+
const currentHostnames = new Set(this.servers.keys());
|
|
147
|
+
|
|
148
|
+
const hostnamesToAdd = new Set<string>(incomingHostnames);
|
|
149
|
+
const hostnamesToRemove = new Set<string>();
|
|
150
|
+
for (const hostname of currentHostnames) {
|
|
151
|
+
// filter hostnamesToAdd (made from incomingHostnames) down to what is *not* present in currentHostnames
|
|
152
|
+
hostnamesToAdd.delete(hostname);
|
|
153
|
+
if (!incomingHostnames.has(hostname)) {
|
|
154
|
+
// If the SRV Records no longer include this hostname
|
|
155
|
+
// we have to stop using it
|
|
156
|
+
hostnamesToRemove.add(hostname);
|
|
150
157
|
}
|
|
151
158
|
}
|
|
152
159
|
|
|
153
|
-
if (
|
|
160
|
+
if (hostnamesToAdd.size === 0 && hostnamesToRemove.size === 0) {
|
|
161
|
+
// No new hosts to add and none to remove
|
|
154
162
|
return this;
|
|
155
163
|
}
|
|
156
164
|
|
|
157
|
-
|
|
158
|
-
|
|
165
|
+
const serverDescriptions = new Map(this.servers);
|
|
166
|
+
for (const removedHost of hostnamesToRemove) {
|
|
167
|
+
serverDescriptions.delete(removedHost);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (hostnamesToAdd.size > 0) {
|
|
171
|
+
if (srvMaxHosts === 0) {
|
|
172
|
+
// Add all!
|
|
173
|
+
for (const hostToAdd of hostnamesToAdd) {
|
|
174
|
+
serverDescriptions.set(hostToAdd, new ServerDescription(hostToAdd));
|
|
175
|
+
}
|
|
176
|
+
} else if (serverDescriptions.size < srvMaxHosts) {
|
|
177
|
+
// Add only the amount needed to get us back to srvMaxHosts
|
|
178
|
+
const selectedHosts = shuffle(hostnamesToAdd, srvMaxHosts - serverDescriptions.size);
|
|
179
|
+
for (const selectedHostToAdd of selectedHosts) {
|
|
180
|
+
serverDescriptions.set(selectedHostToAdd, new ServerDescription(selectedHostToAdd));
|
|
181
|
+
}
|
|
182
|
+
}
|
|
159
183
|
}
|
|
160
184
|
|
|
161
185
|
return new TopologyDescription(
|
package/src/sessions.ts
CHANGED
|
@@ -1,45 +1,47 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { isTransactionCommand, TxnState, Transaction, TransactionOptions } from './transactions';
|
|
5
|
-
import { _advanceClusterTime, ClusterTime, TopologyType } from './sdam/common';
|
|
1
|
+
import { Binary, Document, Long, Timestamp } from './bson';
|
|
2
|
+
import type { CommandOptions, Connection } from './cmap/connection';
|
|
3
|
+
import { ConnectionPoolMetrics } from './cmap/metrics';
|
|
6
4
|
import { isSharded } from './cmap/wire_protocol/shared';
|
|
5
|
+
import { PINNED, UNPINNED } from './constants';
|
|
6
|
+
import type { AbstractCursor } from './cursor/abstract_cursor';
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
AnyError,
|
|
9
|
+
isRetryableEndTransactionError,
|
|
10
10
|
isRetryableError,
|
|
11
|
+
MongoAPIError,
|
|
11
12
|
MongoCompatibilityError,
|
|
12
|
-
MongoNetworkError,
|
|
13
|
-
MongoWriteConcernError,
|
|
14
13
|
MONGODB_ERROR_CODES,
|
|
15
|
-
MongoServerError,
|
|
16
14
|
MongoDriverError,
|
|
17
|
-
|
|
18
|
-
AnyError,
|
|
15
|
+
MongoError,
|
|
19
16
|
MongoExpiredSessionError,
|
|
17
|
+
MongoInvalidArgumentError,
|
|
18
|
+
MongoNetworkError,
|
|
19
|
+
MongoRuntimeError,
|
|
20
|
+
MongoServerError,
|
|
20
21
|
MongoTransactionError,
|
|
21
|
-
|
|
22
|
+
MongoWriteConcernError
|
|
22
23
|
} from './error';
|
|
24
|
+
import type { MongoOptions } from './mongo_client';
|
|
25
|
+
import { TypedEventEmitter } from './mongo_types';
|
|
26
|
+
import { executeOperation } from './operations/execute_operation';
|
|
27
|
+
import { RunAdminCommandOperation } from './operations/run_command';
|
|
28
|
+
import { PromiseProvider } from './promise_provider';
|
|
29
|
+
import { ReadConcernLevel } from './read_concern';
|
|
30
|
+
import { ReadPreference } from './read_preference';
|
|
31
|
+
import { _advanceClusterTime, ClusterTime, TopologyType } from './sdam/common';
|
|
32
|
+
import type { Topology } from './sdam/topology';
|
|
33
|
+
import { isTransactionCommand, Transaction, TransactionOptions, TxnState } from './transactions';
|
|
23
34
|
import {
|
|
24
|
-
now,
|
|
25
35
|
calculateDurationInMs,
|
|
26
36
|
Callback,
|
|
37
|
+
commandSupportsReadConcern,
|
|
27
38
|
isPromiseLike,
|
|
28
|
-
uuidV4,
|
|
29
39
|
maxWireVersion,
|
|
30
|
-
maybePromise
|
|
40
|
+
maybePromise,
|
|
41
|
+
now,
|
|
42
|
+
uuidV4
|
|
31
43
|
} from './utils';
|
|
32
|
-
import type { Topology } from './sdam/topology';
|
|
33
|
-
import type { MongoOptions } from './mongo_client';
|
|
34
|
-
import { executeOperation } from './operations/execute_operation';
|
|
35
|
-
import { RunAdminCommandOperation } from './operations/run_command';
|
|
36
|
-
import type { AbstractCursor } from './cursor/abstract_cursor';
|
|
37
|
-
import type { CommandOptions } from './cmap/connection';
|
|
38
|
-
import { Connection } from './cmap/connection';
|
|
39
|
-
import { ConnectionPoolMetrics } from './cmap/metrics';
|
|
40
44
|
import type { WriteConcern } from './write_concern';
|
|
41
|
-
import { TypedEventEmitter } from './mongo_types';
|
|
42
|
-
import { ReadConcernLevel } from './read_concern';
|
|
43
45
|
|
|
44
46
|
const minWireVersionForShardedTransactions = 8;
|
|
45
47
|
|
|
@@ -224,7 +226,7 @@ export class ClientSession extends TypedEventEmitter<ClientSessionEvents> {
|
|
|
224
226
|
|
|
225
227
|
this[kPinnedConnection] = conn;
|
|
226
228
|
conn.emit(
|
|
227
|
-
|
|
229
|
+
PINNED,
|
|
228
230
|
this.inTransaction() ? ConnectionPoolMetrics.TXN : ConnectionPoolMetrics.CURSOR
|
|
229
231
|
);
|
|
230
232
|
}
|
|
@@ -519,7 +521,7 @@ export function maybeClearPinnedConnection(
|
|
|
519
521
|
if (options?.error == null || options?.force) {
|
|
520
522
|
loadBalancer.s.pool.checkIn(conn);
|
|
521
523
|
conn.emit(
|
|
522
|
-
|
|
524
|
+
UNPINNED,
|
|
523
525
|
session.transaction.state !== TxnState.NO_TRANSACTION
|
|
524
526
|
? ConnectionPoolMetrics.TXN
|
|
525
527
|
: ConnectionPoolMetrics.CURSOR
|
|
@@ -767,7 +769,7 @@ function endTransaction(session: ClientSession, commandName: string, callback: C
|
|
|
767
769
|
session.unpin();
|
|
768
770
|
}
|
|
769
771
|
|
|
770
|
-
if (err &&
|
|
772
|
+
if (err && isRetryableEndTransactionError(err as MongoError)) {
|
|
771
773
|
// SPEC-1185: apply majority write concern when retrying commitTransaction
|
|
772
774
|
if (command.commitTransaction) {
|
|
773
775
|
// per txns spec, must unpin session in this case
|
|
@@ -928,25 +930,6 @@ export class ServerSessionPool {
|
|
|
928
930
|
}
|
|
929
931
|
}
|
|
930
932
|
|
|
931
|
-
// TODO: this should be codified in command construction
|
|
932
|
-
// @see https://github.com/mongodb/specifications/blob/master/source/read-write-concern/read-write-concern.rst#read-concern
|
|
933
|
-
export function commandSupportsReadConcern(command: Document, options?: Document): boolean {
|
|
934
|
-
if (command.aggregate || command.count || command.distinct || command.find || command.geoNear) {
|
|
935
|
-
return true;
|
|
936
|
-
}
|
|
937
|
-
|
|
938
|
-
if (
|
|
939
|
-
command.mapReduce &&
|
|
940
|
-
options &&
|
|
941
|
-
options.out &&
|
|
942
|
-
(options.out.inline === 1 || options.out === 'inline')
|
|
943
|
-
) {
|
|
944
|
-
return true;
|
|
945
|
-
}
|
|
946
|
-
|
|
947
|
-
return false;
|
|
948
|
-
}
|
|
949
|
-
|
|
950
933
|
/**
|
|
951
934
|
* Optionally decorate a command with sessions specific keys
|
|
952
935
|
*
|
package/src/transactions.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Document } from './bson';
|
|
2
2
|
import { MongoRuntimeError, MongoTransactionError } from './error';
|
|
3
|
-
import { ReadConcern } from './read_concern';
|
|
4
|
-
import { WriteConcern } from './write_concern';
|
|
5
|
-
import type { Server } from './sdam/server';
|
|
6
3
|
import type { CommandOperationOptions } from './operations/command';
|
|
7
|
-
import
|
|
4
|
+
import { ReadConcern, ReadConcernLike } from './read_concern';
|
|
5
|
+
import { ReadPreference } from './read_preference';
|
|
6
|
+
import type { Server } from './sdam/server';
|
|
7
|
+
import { WriteConcern } from './write_concern';
|
|
8
8
|
|
|
9
9
|
/** @internal */
|
|
10
10
|
export const TxnState = Object.freeze({
|
|
@@ -63,7 +63,7 @@ const COMMITTED_STATES: Set<TxnState> = new Set([
|
|
|
63
63
|
export interface TransactionOptions extends CommandOperationOptions {
|
|
64
64
|
// TODO(NODE-3344): These options use the proper class forms of these settings, it should accept the basic enum values too
|
|
65
65
|
/** A default read concern for commands in this transaction */
|
|
66
|
-
readConcern?:
|
|
66
|
+
readConcern?: ReadConcernLike;
|
|
67
67
|
/** A default writeConcern for commands in this transaction */
|
|
68
68
|
writeConcern?: WriteConcern;
|
|
69
69
|
/** A default read preference for commands in this transaction */
|