Skip to content

Commit 05b8770

Browse files
committed
Introduced maxStalenessSeconds
1 parent c5e8f20 commit 05b8770

File tree

10 files changed

+36
-33
lines changed

10 files changed

+36
-33
lines changed

lib/collection.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3330,13 +3330,13 @@ var getReadPreference = function(self, options, db) {
33303330
}
33313331

33323332
if(r instanceof ReadPreference) {
3333-
options.readPreference = new CoreReadPreference(r.mode, r.tags, {maxStalenessMS: r.maxStalenessMS});
3333+
options.readPreference = new CoreReadPreference(r.mode, r.tags, {maxStalenessSeconds: r.maxStalenessSeconds});
33343334
} else if(typeof r == 'string') {
33353335
options.readPreference = new CoreReadPreference(r);
33363336
} else if(r && !(r instanceof ReadPreference) && typeof r == 'object') {
33373337
var mode = r.mode || r.preference;
33383338
if (mode && typeof mode == 'string') {
3339-
options.readPreference = new CoreReadPreference(mode, r.tags, {maxStalenessMS: r.maxStalenessMS});
3339+
options.readPreference = new CoreReadPreference(mode, r.tags, {maxStalenessSeconds: r.maxStalenessSeconds});
33403340
}
33413341
}
33423342

lib/command_cursor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ CommandCursor.prototype.setReadPreference = function(r) {
154154
if(this.s.state != CommandCursor.INIT) throw MongoError.create({message: 'cannot change cursor readPreference after cursor has been accessed', driver:true});
155155

156156
if(r instanceof ReadPreference) {
157-
this.s.options.readPreference = new CoreReadPreference(r.mode, r.tags, {maxStalenessMS: r.maxStalenessMS});
157+
this.s.options.readPreference = new CoreReadPreference(r.mode, r.tags, {maxStalenessSeconds: r.maxStalenessSeconds});
158158
} else if(typeof r == 'string') {
159159
this.s.options.readPreference = new CoreReadPreference(r);
160160
} else if(r instanceof CoreReadPreference) {

lib/cursor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ define.classMethod('forEach', {callback: true, promise:false});
791791
Cursor.prototype.setReadPreference = function(r) {
792792
if(this.s.state != Cursor.INIT) throw MongoError.create({message: 'cannot change cursor readPreference after cursor has been accessed', driver:true});
793793
if(r instanceof ReadPreference) {
794-
this.s.options.readPreference = new CoreReadPreference(r.mode, r.tags, {maxStalenessMS: r.maxStalenessMS});
794+
this.s.options.readPreference = new CoreReadPreference(r.mode, r.tags, {maxStalenessSeconds: r.maxStalenessSeconds});
795795
} else if(typeof r == 'string'){
796796
this.s.options.readPreference = new CoreReadPreference(r);
797797
} else if(r instanceof CoreReadPreference) {

lib/db.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,11 @@ var convertReadPreference = function(readPreference) {
267267
if(readPreference && typeof readPreference == 'string') {
268268
return new CoreReadPreference(readPreference);
269269
} else if(readPreference instanceof ReadPreference) {
270-
return new CoreReadPreference(readPreference.mode, readPreference.tags, {maxStalenessMS: readPreference.maxStalenessMS});
270+
return new CoreReadPreference(readPreference.mode, readPreference.tags, {maxStalenessSeconds: readPreference.maxStalenessSeconds});
271271
} else if(readPreference && typeof readPreference == 'object') {
272272
var mode = readPreference.mode || readPreference.preference;
273273
if (mode && typeof mode == 'string') {
274-
readPreference = new CoreReadPreference(mode, readPreference.tags, {maxStalenessMS: readPreference.maxStalenessMS});
274+
readPreference = new CoreReadPreference(mode, readPreference.tags, {maxStalenessSeconds: readPreference.maxStalenessSeconds});
275275
}
276276
}
277277
return readPreference;

lib/mongo_client.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ function translateOptions(options) {
160160
options.readPreference.tags = options.readPreferenceTags || options.read_preference_tags;
161161
}
162162

163-
// Do we have maxStalenessMS
164-
if(options.maxStalenessMS) {
165-
options.readPreference.maxStalenessMS = options.maxStalenessMS;
163+
// Do we have maxStalenessSeconds
164+
if(options.maxStalenessSeconds) {
165+
options.readPreference.maxStalenessSeconds = options.maxStalenessSeconds;
166166
}
167167

168168
// Set the socket and connection timeouts
@@ -292,8 +292,8 @@ var connect = function(url, options, callback) {
292292
_finalOptions = createUnifiedOptions(_finalOptions, options);
293293

294294
// Check if we have connection and socket timeout set
295-
if(_finalOptions.socketTimeoutMS == null) _finalOptions.socketTimeoutMS = 120000;
296-
if(_finalOptions.connectTimeoutMS == null) _finalOptions.connectTimeoutMS = 120000;
295+
if(_finalOptions.socketTimeoutMS == null) _finalOptions.socketTimeoutMS = 30000;
296+
if(_finalOptions.connectTimeoutMS == null) _finalOptions.connectTimeoutMS = 30000;
297297

298298
// Failure modes
299299
if(object.servers.length == 0) {

lib/read_preference.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
* @param {string} mode The ReadPreference mode as listed above.
4040
* @param {array|object} tags An object representing read preference tags.
4141
* @param {object} [options] Additional read preference options
42-
* @param {number} [options.maxStalenessMS] Max Secondary Read Stalleness in Miliseconds
42+
* @param {number} [options.maxStalenessSeconds] Max Secondary Read Stalleness in Seconds
4343
* @return {ReadPreference} a ReadPreference instance.
4444
*/
4545
var ReadPreference = function(mode, tags, options) {
@@ -54,15 +54,15 @@ var ReadPreference = function(mode, tags, options) {
5454

5555
// If no tags were passed in
5656
if(tags && typeof tags == 'object' && !Array.isArray(tags)) {
57-
if(tags.maxStalenessMS) {
57+
if(tags.maxStalenessSeconds) {
5858
this.options = tags;
5959
this.tags = null;
6060
}
6161
}
6262

63-
// Add the maxStalenessMS value to the read Preference
64-
if(this.options && this.options.maxStalenessMS) {
65-
this.maxStalenessMS = this.options.maxStalenessMS;
63+
// Add the maxStalenessSeconds value to the read Preference
64+
if(this.options && this.options.maxStalenessSeconds) {
65+
this.maxStalenessSeconds = this.options.maxStalenessSeconds;
6666
}
6767
}
6868

@@ -102,8 +102,8 @@ ReadPreference.prototype.toObject = function() {
102102
object['tags'] = this.tags;
103103
}
104104

105-
if(this.maxStalenessMS) {
106-
object['maxStalenessMS'] = this.maxStalenessMS;
105+
if(this.maxStalenessSeconds) {
106+
object['maxStalenessSeconds'] = this.maxStalenessSeconds;
107107
}
108108

109109
return object;

lib/replset.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ var translateReadPreference = function(options) {
234234
options.readPreference = new CoreReadPreference(options.readPreference);
235235
} else if(options.readPreference instanceof ReadPreference) {
236236
options.readPreference = new CoreReadPreference(options.readPreference.mode
237-
, options.readPreference.tags, {maxStalenessMS: options.readPreference.maxStalenessMS});
237+
, options.readPreference.tags, {maxStalenessSeconds: options.readPreference.maxStalenessSeconds});
238238
}
239239

240240
return options;

lib/url_parser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,8 @@ module.exports = function(url) {
354354
if(!ReadPreference.isValid(value)) throw new Error("readPreference must be either primary/primaryPreferred/secondary/secondaryPreferred/nearest");
355355
dbOptions.readPreference = value;
356356
break;
357-
case 'maxStalenessMS':
358-
dbOptions.maxStalenessMS = parseInt(value, 10);
357+
case 'maxStalenessSeconds':
358+
dbOptions.maxStalenessSeconds = parseInt(value, 10);
359359
break;
360360
case 'readPreferenceTags':
361361
// Decode the value

test/functional/max_staleness_tests.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var extend = function(template, fields) {
1414
return object;
1515
}
1616

17-
exports['Should correctly set maxStalenessMS on Mongos query using MongoClient.connect'] = {
17+
exports['Should correctly set maxStalenessSeconds on Mongos query using MongoClient.connect'] = {
1818
metadata: {
1919
requires: {
2020
generators: true,
@@ -92,14 +92,14 @@ exports['Should correctly set maxStalenessMS on Mongos query using MongoClient.c
9292
}
9393
});
9494

95-
MongoClient.connect('mongodb://localhost:52000/test?readPreference=secondary&maxStalenessMS=25000', function(err, db) {
95+
MongoClient.connect('mongodb://localhost:52000/test?readPreference=secondary&maxStalenessSeconds=250', function(err, db) {
9696
test.equal(null, err);
9797

9898
db.collection('test').find({}).toArray(function(err, r) {
9999
test.equal(null, err);
100100
test.deepEqual({
101101
'$query': { find: 'test', filter: {} },
102-
'$readPreference': { mode: 'secondary', maxStalenessMS: 25000 }
102+
'$readPreference': { mode: 'secondary', maxStalenessSeconds: 250 }
103103
}, command);
104104

105105
db.close();
@@ -112,7 +112,7 @@ exports['Should correctly set maxStalenessMS on Mongos query using MongoClient.c
112112
}
113113
}
114114

115-
exports['Should correctly set maxStalenessMS on Mongos query using db level readPreference'] = {
115+
exports['Should correctly set maxStalenessSeconds on Mongos query using db level readPreference'] = {
116116
metadata: {
117117
requires: {
118118
generators: true,
@@ -194,12 +194,12 @@ exports['Should correctly set maxStalenessMS on Mongos query using db level read
194194
test.equal(null, err);
195195

196196
// Get a db with a new readPreference
197-
var db1 = db.db('test', {readPreference: new ReadPreference('secondary', {maxStalenessMS: 25000})})
197+
var db1 = db.db('test', {readPreference: new ReadPreference('secondary', {maxStalenessSeconds: 250})})
198198
db1.collection('test').find({}).toArray(function(err, r) {
199199
test.equal(null, err);
200200
test.deepEqual({
201201
'$query': { find: 'test', filter: {} },
202-
'$readPreference': { mode: 'secondary', maxStalenessMS: 25000 }
202+
'$readPreference': { mode: 'secondary', maxStalenessSeconds: 250 }
203203
}, command);
204204

205205
db.close();
@@ -212,7 +212,7 @@ exports['Should correctly set maxStalenessMS on Mongos query using db level read
212212
}
213213
}
214214

215-
exports['Should correctly set maxStalenessMS on Mongos query using collection level readPreference'] = {
215+
exports['Should correctly set maxStalenessSeconds on Mongos query using collection level readPreference'] = {
216216
metadata: {
217217
requires: {
218218
generators: true,
@@ -294,11 +294,11 @@ exports['Should correctly set maxStalenessMS on Mongos query using collection le
294294
test.equal(null, err);
295295

296296
// Get a db with a new readPreference
297-
db.collection('test', {readPreference: new ReadPreference('secondary', {maxStalenessMS: 25000})}).find({}).toArray(function(err, r) {
297+
db.collection('test', {readPreference: new ReadPreference('secondary', {maxStalenessSeconds: 250})}).find({}).toArray(function(err, r) {
298298
test.equal(null, err);
299299
test.deepEqual({
300300
'$query': { find: 'test', filter: {} },
301-
'$readPreference': { mode: 'secondary', maxStalenessMS: 25000 }
301+
'$readPreference': { mode: 'secondary', maxStalenessSeconds: 250 }
302302
}, command);
303303

304304
db.close();
@@ -311,7 +311,7 @@ exports['Should correctly set maxStalenessMS on Mongos query using collection le
311311
}
312312
}
313313

314-
exports['Should correctly set maxStalenessMS on Mongos query using cursor level readPreference'] = {
314+
exports['Should correctly set maxStalenessSeconds on Mongos query using cursor level readPreference'] = {
315315
metadata: {
316316
requires: {
317317
generators: true,
@@ -393,11 +393,11 @@ exports['Should correctly set maxStalenessMS on Mongos query using cursor level
393393
test.equal(null, err);
394394

395395
// Get a db with a new readPreference
396-
db.collection('test').find({}).setReadPreference(new ReadPreference('secondary', {maxStalenessMS: 25000})).toArray(function(err, r) {
396+
db.collection('test').find({}).setReadPreference(new ReadPreference('secondary', {maxStalenessSeconds: 250})).toArray(function(err, r) {
397397
test.equal(null, err);
398398
test.deepEqual({
399399
'$query': { find: 'test', filter: {} },
400-
'$readPreference': { mode: 'secondary', maxStalenessMS: 25000 }
400+
'$readPreference': { mode: 'secondary', maxStalenessSeconds: 250 }
401401
}, command);
402402

403403
db.close();

test/functional/mongo_client_tests.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@ exports['Should correctly set MaxPoolSize on replicaset server'] = {
317317
var connections = db.serverConfig.connections();
318318

319319
for(var i = 0; i < connections.length; i++) {
320+
// console.log("=============================================")
321+
// console.log(`connections[i].connectionTimeout = ${connections[i].connectionTimeout}`)
322+
// console.log(`connections[i].socketTimeout = ${connections[i].socketTimeout}`)
320323
test.equal(30000, connections[i].connectionTimeout);
321324
test.equal(30000, connections[i].socketTimeout);
322325
}

0 commit comments

Comments
 (0)