Skip to content

Commit 2b33f67

Browse files
committed
fix strategy sort compare function
1 parent 62514af commit 2b33f67

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

lib/mongodb/connection/repl_set/strategies/ping_strategy.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ PingStrategy.prototype.checkoutConnection = function(tags, secondaryCandidates)
112112

113113
// Sort by ping time
114114
finalCandidates.sort(function(a, b) {
115-
return a.runtimeStats['pingMs'] > b.runtimeStats['pingMs'];
115+
return a.runtimeStats['pingMs'] - b.runtimeStats['pingMs'];
116116
});
117117

118118
if(0 === finalCandidates.length)
@@ -129,7 +129,7 @@ PingStrategy.prototype.checkoutConnection = function(tags, secondaryCandidates)
129129

130130
// convert to integer
131131
var lowestPing = lowest.runtimeStats.pingMs | 0;
132-
132+
133133
// determine acceptable latency
134134
var acceptable = lowestPing + this.secondaryAcceptableLatencyMS;
135135

@@ -141,11 +141,11 @@ PingStrategy.prototype.checkoutConnection = function(tags, secondaryCandidates)
141141
}
142142
}
143143

144-
if(self.logger && self.logger.debug) {
144+
if(self.logger && self.logger.debug) {
145145
self.logger.debug("Ping strategy selection order for tags", tags);
146146
finalCandidates.forEach(function(c) {
147147
self.logger.debug(format("%s:%s = %s ms", c.host, c.port, c.runtimeStats['pingMs']), null);
148-
})
148+
})
149149
}
150150

151151
// If no candidates available return an error
@@ -154,12 +154,12 @@ PingStrategy.prototype.checkoutConnection = function(tags, secondaryCandidates)
154154

155155
// Ensure no we don't overflow
156156
this.index = this.index % finalCandidates.length
157-
// Pick a random acceptable server
157+
// Pick a random acceptable server
158158
var connection = finalCandidates[this.index].checkoutReader();
159159
// Point to next candidate (round robin style)
160160
this.index = this.index + 1;
161161

162-
if(self.logger && self.logger.debug) {
162+
if(self.logger && self.logger.debug) {
163163
if(connection)
164164
self.logger.debug(format("picked server %s:%s", connection.socketOptions.host, connection.socketOptions.port));
165165
}
@@ -252,12 +252,12 @@ PingStrategy.prototype._pingServer = function(callback) {
252252
// Done with the pinging
253253
done();
254254
});
255-
});
255+
});
256256
};
257257
// Ping
258258
_ping(_db, serverInstance);
259259
} else {
260-
var connectTimeoutMS = self.replicaset.options.socketOptions
260+
var connectTimeoutMS = self.replicaset.options.socketOptions
261261
? self.replicaset.options.socketOptions.connectTimeoutMS : 0
262262

263263
// Create a new master connection
@@ -275,7 +275,7 @@ PingStrategy.prototype._pingServer = function(callback) {
275275
sslPass: self.replicaset.options.sslPass
276276
});
277277

278-
// Create Db instance
278+
// Create Db instance
279279
var _db = new self.Db('local', _server, { safe: true });
280280
_db.on("close", function() {
281281
delete self.dbs[this.serverConfig.host + ":" + this.serverConfig.port];
@@ -287,7 +287,7 @@ PingStrategy.prototype._pingServer = function(callback) {
287287
return;
288288
}
289289

290-
__db.open(function(err, db) {
290+
__db.open(function(err, db) {
291291
// Emit ping connect
292292
self.replicaset.emit("ping_connect", err, __serverInstance);
293293

@@ -310,7 +310,7 @@ PingStrategy.prototype._pingServer = function(callback) {
310310
// Execute ping on this connection
311311
__db.executeDbCommand({ping:1}, {failFast:true}, function(err) {
312312
self.replicaset.emit("ping", err, __serverInstance);
313-
313+
314314
if(err) {
315315
delete self.dbs[__db.serverConfig.host + ":" + __db.serverConfig.port];
316316
__db.close();
@@ -329,7 +329,7 @@ PingStrategy.prototype._pingServer = function(callback) {
329329
__db.close();
330330
return done();
331331
}
332-
332+
333333
// Process the ismaster for the server
334334
if(result && result.documents && self.replicaset.processIsMaster) {
335335
self.replicaset.processIsMaster(__serverInstance, result.documents[0]);
@@ -339,7 +339,7 @@ PingStrategy.prototype._pingServer = function(callback) {
339339
done();
340340
});
341341
});
342-
});
342+
});
343343
};
344344

345345
// Ping the server

lib/mongodb/connection/repl_set/strategies/statistics_strategy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
var StatisticsStrategy = exports.StatisticsStrategy = function(replicaset) {
55
this.replicaset = replicaset;
66
// Logger api
7-
this.Logger = null;
7+
this.Logger = null;
88
}
99

1010
// Starts any needed code
@@ -74,7 +74,7 @@ StatisticsStrategy.prototype.checkoutConnection = function(tags, secondaryCandid
7474
}
7575

7676
finalCandidates.sort(function(a, b) {
77-
return a.runtimeStats.queryStats.sScore > b.runtimeStats.queryStats.sScore;
77+
return a.runtimeStats.queryStats.sScore - b.runtimeStats.queryStats.sScore;
7878
});
7979

8080
// If no candidates available return an error

0 commit comments

Comments
 (0)