@@ -112,7 +112,7 @@ PingStrategy.prototype.checkoutConnection = function(tags, secondaryCandidates)
112
112
113
113
// Sort by ping time
114
114
finalCandidates . sort ( function ( a , b ) {
115
- return a . runtimeStats [ 'pingMs' ] > b . runtimeStats [ 'pingMs' ] ;
115
+ return a . runtimeStats [ 'pingMs' ] - b . runtimeStats [ 'pingMs' ] ;
116
116
} ) ;
117
117
118
118
if ( 0 === finalCandidates . length )
@@ -129,7 +129,7 @@ PingStrategy.prototype.checkoutConnection = function(tags, secondaryCandidates)
129
129
130
130
// convert to integer
131
131
var lowestPing = lowest . runtimeStats . pingMs | 0 ;
132
-
132
+
133
133
// determine acceptable latency
134
134
var acceptable = lowestPing + this . secondaryAcceptableLatencyMS ;
135
135
@@ -141,11 +141,11 @@ PingStrategy.prototype.checkoutConnection = function(tags, secondaryCandidates)
141
141
}
142
142
}
143
143
144
- if ( self . logger && self . logger . debug ) {
144
+ if ( self . logger && self . logger . debug ) {
145
145
self . logger . debug ( "Ping strategy selection order for tags" , tags ) ;
146
146
finalCandidates . forEach ( function ( c ) {
147
147
self . logger . debug ( format ( "%s:%s = %s ms" , c . host , c . port , c . runtimeStats [ 'pingMs' ] ) , null ) ;
148
- } )
148
+ } )
149
149
}
150
150
151
151
// If no candidates available return an error
@@ -154,12 +154,12 @@ PingStrategy.prototype.checkoutConnection = function(tags, secondaryCandidates)
154
154
155
155
// Ensure no we don't overflow
156
156
this . index = this . index % finalCandidates . length
157
- // Pick a random acceptable server
157
+ // Pick a random acceptable server
158
158
var connection = finalCandidates [ this . index ] . checkoutReader ( ) ;
159
159
// Point to next candidate (round robin style)
160
160
this . index = this . index + 1 ;
161
161
162
- if ( self . logger && self . logger . debug ) {
162
+ if ( self . logger && self . logger . debug ) {
163
163
if ( connection )
164
164
self . logger . debug ( format ( "picked server %s:%s" , connection . socketOptions . host , connection . socketOptions . port ) ) ;
165
165
}
@@ -252,12 +252,12 @@ PingStrategy.prototype._pingServer = function(callback) {
252
252
// Done with the pinging
253
253
done ( ) ;
254
254
} ) ;
255
- } ) ;
255
+ } ) ;
256
256
} ;
257
257
// Ping
258
258
_ping ( _db , serverInstance ) ;
259
259
} else {
260
- var connectTimeoutMS = self . replicaset . options . socketOptions
260
+ var connectTimeoutMS = self . replicaset . options . socketOptions
261
261
? self . replicaset . options . socketOptions . connectTimeoutMS : 0
262
262
263
263
// Create a new master connection
@@ -275,7 +275,7 @@ PingStrategy.prototype._pingServer = function(callback) {
275
275
sslPass : self . replicaset . options . sslPass
276
276
} ) ;
277
277
278
- // Create Db instance
278
+ // Create Db instance
279
279
var _db = new self . Db ( 'local' , _server , { safe : true } ) ;
280
280
_db . on ( "close" , function ( ) {
281
281
delete self . dbs [ this . serverConfig . host + ":" + this . serverConfig . port ] ;
@@ -287,7 +287,7 @@ PingStrategy.prototype._pingServer = function(callback) {
287
287
return ;
288
288
}
289
289
290
- __db . open ( function ( err , db ) {
290
+ __db . open ( function ( err , db ) {
291
291
// Emit ping connect
292
292
self . replicaset . emit ( "ping_connect" , err , __serverInstance ) ;
293
293
@@ -310,7 +310,7 @@ PingStrategy.prototype._pingServer = function(callback) {
310
310
// Execute ping on this connection
311
311
__db . executeDbCommand ( { ping :1 } , { failFast :true } , function ( err ) {
312
312
self . replicaset . emit ( "ping" , err , __serverInstance ) ;
313
-
313
+
314
314
if ( err ) {
315
315
delete self . dbs [ __db . serverConfig . host + ":" + __db . serverConfig . port ] ;
316
316
__db . close ( ) ;
@@ -329,7 +329,7 @@ PingStrategy.prototype._pingServer = function(callback) {
329
329
__db . close ( ) ;
330
330
return done ( ) ;
331
331
}
332
-
332
+
333
333
// Process the ismaster for the server
334
334
if ( result && result . documents && self . replicaset . processIsMaster ) {
335
335
self . replicaset . processIsMaster ( __serverInstance , result . documents [ 0 ] ) ;
@@ -339,7 +339,7 @@ PingStrategy.prototype._pingServer = function(callback) {
339
339
done ( ) ;
340
340
} ) ;
341
341
} ) ;
342
- } ) ;
342
+ } ) ;
343
343
} ;
344
344
345
345
// Ping the server
0 commit comments