Skip to content

Commit c4add7b

Browse files
committed
Merge branch '3.5'
2 parents 2d607fa + 582d3e2 commit c4add7b

26 files changed

+356
-384
lines changed

.evergreen/config.yml

+12-12
Original file line numberDiff line numberDiff line change
@@ -1027,9 +1027,9 @@ buildvariants:
10271027
expansions:
10281028
NODE_LTS_NAME: argon
10291029
tasks: *ref_0
1030-
- name: macos-1012-dubnium
1031-
display_name: macOS 10.12 Node Dubnium
1032-
run_on: macos-1012
1030+
- name: macos-1014-dubnium
1031+
display_name: macOS 10.14 Node Dubnium
1032+
run_on: macos-1014
10331033
expansions:
10341034
NODE_LTS_NAME: dubnium
10351035
tasks: &ref_2
@@ -1082,21 +1082,21 @@ buildvariants:
10821082
- test-2.6-replica_set-unified
10831083
- test-2.6-sharded_cluster-unified
10841084
- test-atlas-connectivity
1085-
- name: macos-1012-carbon
1086-
display_name: macOS 10.12 Node Carbon
1087-
run_on: macos-1012
1085+
- name: macos-1014-carbon
1086+
display_name: macOS 10.14 Node Carbon
1087+
run_on: macos-1014
10881088
expansions:
10891089
NODE_LTS_NAME: carbon
10901090
tasks: *ref_2
1091-
- name: macos-1012-boron
1092-
display_name: macOS 10.12 Node Boron
1093-
run_on: macos-1012
1091+
- name: macos-1014-boron
1092+
display_name: macOS 10.14 Node Boron
1093+
run_on: macos-1014
10941094
expansions:
10951095
NODE_LTS_NAME: boron
10961096
tasks: *ref_2
1097-
- name: macos-1012-argon
1098-
display_name: macOS 10.12 Node Argon
1099-
run_on: macos-1012
1097+
- name: macos-1014-argon
1098+
display_name: macOS 10.14 Node Argon
1099+
run_on: macos-1014
11001100
expansions:
11011101
NODE_LTS_NAME: argon
11021102
tasks: *ref_2

.evergreen/generate_evergreen_tasks.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ const OPERATING_SYSTEMS = [
4545
},
4646
// macos
4747
{
48-
name: 'macos-1012',
49-
display_name: 'macOS 10.12',
50-
run_on: 'macos-1012',
48+
name: 'macos-1014',
49+
display_name: 'macOS 10.14',
50+
run_on: 'macos-1014',
5151
auth: false
5252
},
5353
// rhel

HISTORY.md

+35
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,41 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com./conventional-changelog/standard-version) for commit guidelines.
44

5+
<a name="3.5.4"></a>
6+
## [3.5.4](https://github.com./mongodb/node-mongodb-native/compare/v3.5.3...v3.5.4) (2020-02-25)
7+
8+
9+
### Bug Fixes
10+
11+
* **cmap:** don't run min connection thread if no minimum specified ([2d1b713](https://github.com./mongodb/node-mongodb-native/commit/2d1b713))
12+
* **sdam:** use ObjectId comparison to track maxElectionId ([a1e0849](https://github.com./mongodb/node-mongodb-native/commit/a1e0849))
13+
* **topology:** ensure selection wait queue is always processed ([bf701d6](https://github.com./mongodb/node-mongodb-native/commit/bf701d6))
14+
* **topology:** enter `STATE_CLOSING` before draining waitQueue ([494dffb](https://github.com./mongodb/node-mongodb-native/commit/494dffb))
15+
* don't consume first document when calling `hasNext` on cursor ([bb359a1](https://github.com./mongodb/node-mongodb-native/commit/bb359a1))
16+
17+
18+
### Features
19+
20+
* add utility helper for returning promises or using callbacks ([ac9e4c9](https://github.com./mongodb/node-mongodb-native/commit/ac9e4c9))
21+
22+
23+
24+
<a name="3.5.3"></a>
25+
## [3.5.3](https://github.com./mongodb/node-mongodb-native/compare/v3.5.2...v3.5.3) (2020-02-12)
26+
27+
28+
### Bug Fixes
29+
30+
* **message-stream:** support multiple inbound message packets ([8388443](https://github.com./mongodb/node-mongodb-native/commit/8388443))
31+
* **server:** non-timeout network errors transition to Unknown state ([fa4b01b](https://github.com./mongodb/node-mongodb-native/commit/fa4b01b))
32+
33+
34+
### Features
35+
36+
* **connection:** support exhaust behavior at the transport level ([9ccf268](https://github.com./mongodb/node-mongodb-native/commit/9ccf268))
37+
38+
39+
540
<a name="3.5.2"></a>
641
## [3.5.2](https://github.com./mongodb/node-mongodb-native/compare/v3.5.1...v3.5.2) (2020-01-20)
742

lib/cmap/connection_pool.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ class ConnectionPool extends EventEmitter {
362362
}
363363

364364
function ensureMinPoolSize(pool) {
365-
if (pool.closed) {
365+
if (pool.closed || pool.options.minPoolSize === 0) {
366366
return;
367367
}
368368

lib/core/sdam/topology.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -319,14 +319,16 @@ class Topology extends EventEmitter {
319319
}
320320

321321
options = options || {};
322-
if (this.s.state === STATE_CLOSED) {
322+
if (this.s.state === STATE_CLOSED || this.s.state === STATE_CLOSING) {
323323
if (typeof callback === 'function') {
324324
callback();
325325
}
326326

327327
return;
328328
}
329329

330+
stateTransition(this, STATE_CLOSING);
331+
330332
drainWaitQueue(this[kWaitQueue], new MongoError('Topology closed'));
331333
drainTimerQueue(this.s.connectionTimers);
332334

@@ -343,8 +345,6 @@ class Topology extends EventEmitter {
343345
delete this.s.detectTopologyDescriptionChange;
344346
}
345347

346-
stateTransition(this, STATE_CLOSING);
347-
348348
this.s.sessions.forEach(session => session.endSession());
349349
this.s.sessionPool.endAllPooledSessions(() => {
350350
eachAsync(
@@ -441,8 +441,7 @@ class Topology extends EventEmitter {
441441
}, serverSelectionTimeoutMS);
442442
}
443443

444-
// place the member at the front of the wait queue
445-
this[kWaitQueue].unshift(waitQueueMember);
444+
this[kWaitQueue].push(waitQueueMember);
446445
processWaitQueue(this);
447446
}
448447

@@ -991,7 +990,7 @@ function srvPollingHandler(topology) {
991990

992991
function drainWaitQueue(queue, err) {
993992
while (queue.length) {
994-
const waitQueueMember = queue.pop();
993+
const waitQueueMember = queue.shift();
995994
clearTimeout(waitQueueMember.timer);
996995
if (!waitQueueMember[kCancelled]) {
997996
waitQueueMember.callback(err);
@@ -1007,7 +1006,8 @@ function processWaitQueue(topology) {
10071006

10081007
const isSharded = topology.description.type === TopologyType.Sharded;
10091008
const serverDescriptions = Array.from(topology.description.servers.values());
1010-
for (let i = 0; i < topology[kWaitQueue].length; ++i) {
1009+
const membersToProcess = topology[kWaitQueue].length;
1010+
for (let i = 0; i < membersToProcess; ++i) {
10111011
const waitQueueMember = topology[kWaitQueue].shift();
10121012
if (waitQueueMember[kCancelled]) {
10131013
continue;
@@ -1022,12 +1022,12 @@ function processWaitQueue(topology) {
10221022
} catch (e) {
10231023
clearTimeout(waitQueueMember.timer);
10241024
waitQueueMember.callback(e);
1025-
break;
1025+
continue;
10261026
}
10271027

10281028
if (selectedDescriptions.length === 0) {
10291029
topology[kWaitQueue].push(waitQueueMember);
1030-
break;
1030+
continue;
10311031
}
10321032

10331033
const selectedServerDescription = randomSelection(selectedDescriptions);

lib/core/utils.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ function makeClientMetadata(options) {
255255
return metadata;
256256
}
257257

258+
const noop = () => {};
259+
258260
module.exports = {
259261
uuidV4,
260262
calculateDurationInMs,
@@ -270,5 +272,6 @@ module.exports = {
270272
tagsStrictEqual,
271273
errorStrictEqual,
272274
makeStateMachine,
273-
makeClientMetadata
275+
makeClientMetadata,
276+
noop
274277
};

lib/cursor.js

+88-18
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,12 @@ const MongoError = require('./core').MongoError;
99
const CoreCursor = require('./core/cursor').CoreCursor;
1010
const CursorState = require('./core/cursor').CursorState;
1111
const Map = require('./core').BSON.Map;
12+
const maybePromise = require('./utils').maybePromise;
13+
const executeOperation = require('./operations/execute_operation');
14+
const formattedOrderClause = require('./utils').formattedOrderClause;
1215

1316
const each = require('./operations/cursor_ops').each;
14-
1517
const CountOperation = require('./operations/count');
16-
const ExplainOperation = require('./operations/explain');
17-
const HasNextOperation = require('./operations/has_next');
18-
const NextOperation = require('./operations/next');
19-
const ToArrayOperation = require('./operations/to_array');
20-
21-
const executeOperation = require('./operations/execute_operation');
2218

2319
/**
2420
* @fileOverview The **Cursor** class is an internal class that embodies a cursor on MongoDB
@@ -127,8 +123,6 @@ class Cursor extends CoreCursor {
127123
state: CursorState.INIT,
128124
// Promise library
129125
promiseLibrary,
130-
// Current doc
131-
currentDoc: null,
132126
// explicitlyIgnoreSession
133127
explicitlyIgnoreSession: !!options.explicitlyIgnoreSession
134128
};
@@ -198,9 +192,27 @@ class Cursor extends CoreCursor {
198192
* @return {Promise} returns Promise if no callback passed
199193
*/
200194
hasNext(callback) {
201-
const hasNextOperation = new HasNextOperation(this);
195+
if (this.s.state === CursorState.CLOSED || (this.isDead && this.isDead())) {
196+
throw MongoError.create({ message: 'Cursor is closed', driver: true });
197+
}
198+
199+
return maybePromise(callback, cb => {
200+
const cursor = this;
201+
if (cursor.isNotified()) {
202+
return cb(null, false);
203+
}
202204

203-
return executeOperation(this.topology, hasNextOperation, callback);
205+
cursor._next((err, doc) => {
206+
if (err) return cb(err);
207+
if (doc == null || cursor.s.state === Cursor.CLOSED || cursor.isDead()) {
208+
return cb(null, false);
209+
}
210+
211+
cursor.s.state = CursorState.OPEN;
212+
cursor.cursorState.cursorIndex--;
213+
cb(null, true);
214+
});
215+
});
204216
}
205217

206218
/**
@@ -211,9 +223,27 @@ class Cursor extends CoreCursor {
211223
* @return {Promise} returns Promise if no callback passed
212224
*/
213225
next(callback) {
214-
const nextOperation = new NextOperation(this);
226+
return maybePromise(callback, cb => {
227+
const cursor = this;
228+
if (cursor.s.state === CursorState.CLOSED || (cursor.isDead && cursor.isDead())) {
229+
cb(MongoError.create({ message: 'Cursor is closed', driver: true }));
230+
return;
231+
}
215232

216-
return executeOperation(this.topology, nextOperation, callback);
233+
if (cursor.s.state === CursorState.INIT && cursor.cmd.sort) {
234+
try {
235+
cursor.cmd.sort = formattedOrderClause(cursor.cmd.sort);
236+
} catch (err) {
237+
return cb(err);
238+
}
239+
}
240+
241+
cursor._next((err, doc) => {
242+
if (err) return cb(err);
243+
cursor.s.state = CursorState.OPEN;
244+
cb(null, doc);
245+
});
246+
});
217247
}
218248

219249
/**
@@ -783,9 +813,49 @@ class Cursor extends CoreCursor {
783813
});
784814
}
785815

786-
const toArrayOperation = new ToArrayOperation(this);
816+
return maybePromise(callback, cb => {
817+
const cursor = this;
818+
const items = [];
787819

788-
return executeOperation(this.topology, toArrayOperation, callback);
820+
// Reset cursor
821+
cursor.rewind();
822+
cursor.s.state = CursorState.INIT;
823+
824+
// Fetch all the documents
825+
const fetchDocs = () => {
826+
cursor._next((err, doc) => {
827+
if (err) {
828+
return cursor._endSession
829+
? cursor._endSession(() => handleCallback(cb, err))
830+
: handleCallback(cb, err);
831+
}
832+
833+
if (doc == null) {
834+
return cursor.close({ skipKillCursors: true }, () => handleCallback(cb, null, items));
835+
}
836+
837+
// Add doc to items
838+
items.push(doc);
839+
840+
// Get all buffered objects
841+
if (cursor.bufferedCount() > 0) {
842+
let docs = cursor.readBufferedDocuments(cursor.bufferedCount());
843+
844+
// Transform the doc if transform method added
845+
if (cursor.s.transforms && typeof cursor.s.transforms.doc === 'function') {
846+
docs = docs.map(cursor.s.transforms.doc);
847+
}
848+
849+
Array.prototype.push.apply(items, docs);
850+
}
851+
852+
// Attempt a fetch
853+
fetchDocs();
854+
});
855+
};
856+
857+
fetchDocs();
858+
});
789859
}
790860

791861
/**
@@ -971,9 +1041,9 @@ class Cursor extends CoreCursor {
9711041
delete this.cmd['readConcern'];
9721042
}
9731043

974-
const explainOperation = new ExplainOperation(this);
975-
976-
return executeOperation(this.topology, explainOperation, callback);
1044+
return maybePromise(callback, cb => {
1045+
CoreCursor.prototype._next.apply(this, [cb]);
1046+
});
9771047
}
9781048

9791049
/**

0 commit comments

Comments
 (0)