Comparing version 1.2.11 to 1.2.12
@@ -35,3 +35,3 @@ var Connection = require('./connection').Connection, | ||
* - **readPreference** {String}, the prefered read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST). | ||
* - **strategy** {String, default:null}, selection strategy for reads choose between (ping and statistical, default is round-robin) | ||
* - **strategy** {String, default:'ping'}, selection strategy for reads choose between (ping and statistical, default is ping) | ||
* - **secondaryAcceptableLatencyMS** {Number, default:15}, sets the range of servers to pick when using NEAREST (lowest ping ms + the latency fence, ex: range of 1 to (1 + 15) ms) | ||
@@ -145,2 +145,3 @@ * - **connectArbiter** {Boolean, default:false}, sets if the driver should connect to arbiters or not. | ||
if(this.strategy != null && (this.strategy != 'ping' && this.strategy != 'statistical')) throw new Error("Only ping or statistical strategies allowed"); | ||
if(this.strategy == null) this.strategy = 'ping'; | ||
// Let's set up our strategy object for picking secodaries | ||
@@ -1032,3 +1033,3 @@ if(this.strategy == 'ping') { | ||
if(candidateServers.length > 0) { | ||
if(this.strategyInstance) return this.strategyInstance.checkoutSecondary(tags, candidateServers); | ||
if(this.strategyInstance) return this.strategyInstance.checkoutConnection(tags, candidateServers); | ||
// Set instance to return | ||
@@ -1085,3 +1086,25 @@ return candidateServers[Math.floor(Math.random() * candidateServers.length)].checkoutReader(); | ||
// If we have tags, look for servers matching the specific tag | ||
if(tags != null && typeof tags == 'object') { | ||
if(this.strategyInstance != null) { | ||
// Only pick from secondaries | ||
var _secondaries = []; | ||
for(var key in this._state.secondaries) { | ||
_secondaries.push(this._state.secondaries[key]); | ||
} | ||
if(finalReadPreference == ReadPreference.SECONDARY) { | ||
// Check out the nearest from only the secondaries | ||
connection = this.strategyInstance.checkoutConnection(tags, _secondaries); | ||
} else { | ||
connection = this.strategyInstance.checkoutConnection(tags, _secondaries); | ||
// No candidate servers that match the tags, error | ||
if(connection == null || connection instanceof Error) { | ||
// No secondary server avilable, attemp to checkout a primary server | ||
connection = this.checkoutWriter(); | ||
// If no connection return an error | ||
if(connection == null) { | ||
return new Error("No replica set members available for query"); | ||
} | ||
} | ||
} | ||
} else if(tags != null && typeof tags == 'object') { | ||
// Get connection | ||
@@ -1113,12 +1136,18 @@ connection = _pickFromTags(this, tags);// = function(self, readPreference, tags) { | ||
} | ||
} else if(finalReadPreference == ReadPreference.SECONDARY_PREFERRED && tags == null && Object.keys(this._state.secondaries).length == 0) { | ||
connection = this.checkoutWriter(); | ||
// If no connection return an error | ||
if(connection == null) { | ||
var preferenceName = finalReadPreference == ReadPreference.SECONDARY ? 'secondary' : finalReadPreference; | ||
connection = new Error("No replica set member available for query with ReadPreference " + preferenceName + " and tags " + JSON.stringify(tags)); | ||
} | ||
} else if(finalReadPreference == ReadPreference.SECONDARY_PREFERRED) { | ||
// If we have tags, look for servers matching the specific tag | ||
if(tags != null && typeof tags == 'object') { | ||
if(this.strategyInstance != null) { | ||
connection = this.strategyInstance.checkoutConnection(tags); | ||
// No candidate servers that match the tags, error | ||
if(connection == null || connection instanceof Error) { | ||
// No secondary server avilable, attemp to checkout a primary server | ||
connection = this.checkoutWriter(); | ||
// If no connection return an error | ||
if(connection == null) { | ||
var preferenceName = finalReadPreference == ReadPreference.SECONDARY ? 'secondary' : finalReadPreference; | ||
connection = new Error("No replica set member available for query with ReadPreference " + preferenceName + " and tags " + JSON.stringify(tags)); | ||
// return new Error("No replica set members available for query"); | ||
} | ||
} | ||
} else if(tags != null && typeof tags == 'object') { | ||
// Get connection | ||
@@ -1132,10 +1161,10 @@ connection = _pickFromTags(this, tags);// = function(self, readPreference, tags) { | ||
if(connection == null) { | ||
return new Error("No replica set members available for query"); | ||
var preferenceName = finalReadPreference == ReadPreference.SECONDARY ? 'secondary' : finalReadPreference; | ||
connection = new Error("No replica set member available for query with ReadPreference " + preferenceName + " and tags " + JSON.stringify(tags)); | ||
// return new Error("No replica set members available for query"); | ||
} | ||
} | ||
} else if(this.strategyInstance != null) { | ||
connection = this.strategyInstance.checkoutReader(tags); | ||
} | ||
} else if(finalReadPreference == ReadPreference.NEAREST && this.strategyInstance != null) { | ||
connection = this.strategyInstance.checkoutSecondary(tags); | ||
connection = this.strategyInstance.checkoutConnection(tags); | ||
} else if(finalReadPreference == ReadPreference.NEAREST && this.strategyInstance == null) { | ||
@@ -1253,2 +1282,4 @@ return new Error("A strategy for calculating nearness must be enabled such as ping or statistical"); | ||
if(this.strategyInstance) this.strategyInstance.stop(); | ||
// Shut down HA if running connection | ||
if(this._haServer) this._haServer.close(); | ||
@@ -1255,0 +1286,0 @@ // If it's a callback |
@@ -33,2 +33,7 @@ var Server = require("../server").Server; | ||
// Stop all the server instances | ||
for(var key in this.dbs) { | ||
this.dbs[key].close(); | ||
} | ||
// optional callback | ||
@@ -38,3 +43,3 @@ callback && callback(null, null); | ||
PingStrategy.prototype.checkoutSecondary = function(tags, secondaryCandidates) { | ||
PingStrategy.prototype.checkoutConnection = function(tags, secondaryCandidates) { | ||
// Servers are picked based on the lowest ping time and then servers that lower than that + secondaryAcceptableLatencyMS | ||
@@ -104,5 +109,14 @@ // Create a list of candidat servers, containing the primary if available | ||
// handle undefined pingMs | ||
var lowestPing = finalCandidates[0].runtimeStats['pingMs'] | 0; | ||
// find lowest server with a ping time | ||
var lowest = finalCandidates.filter(function (server) { | ||
return undefined != server.runtimeStats.pingMs; | ||
})[0]; | ||
if(!lowest) { | ||
lowest = finalCandidates[0]; | ||
} | ||
// convert to integer | ||
var lowestPing = lowest.runtimeStats.pingMs | 0; | ||
// determine acceptable latency | ||
@@ -204,3 +218,9 @@ var acceptable = lowestPing + this.secondaryAcceptableLatencyMS; | ||
var _ping = function(__db, __serverInstance) { | ||
if(self.state == 'disconnected') return; | ||
__db.open(function(err, db) { | ||
if(self.state == 'disconnected') { | ||
return db.close(); | ||
} | ||
if(err) { | ||
@@ -252,3 +272,2 @@ delete self.dbs[__db.serverConfig.host + ":" + __db.serverConfig.port]; | ||
// Start pingFunction | ||
// setTimeout(pingFunction, 1000); | ||
pingFunction(); | ||
@@ -255,0 +274,0 @@ |
@@ -17,3 +17,3 @@ // The Statistics strategy uses the measure of each end-start time for each | ||
StatisticsStrategy.prototype.checkoutSecondary = function(tags, secondaryCandidates) { | ||
StatisticsStrategy.prototype.checkoutConnection = function(tags, secondaryCandidates) { | ||
// Servers are picked based on the lowest ping time and then servers that lower than that + secondaryAcceptableLatencyMS | ||
@@ -20,0 +20,0 @@ // Create a list of candidat servers, containing the primary if available |
@@ -12,3 +12,3 @@ var QueryCommand = require('./commands/query_command').QueryCommand, | ||
* using find. This cursor object is unidirectional and cannot traverse backwards. Clients should not be creating a cursor directly, | ||
* but use find to acquire a cursor. | ||
* but use find to acquire a cursor. (INTERNAL TYPE) | ||
* | ||
@@ -286,2 +286,3 @@ * Options | ||
* | ||
* @param {Boolean} applySkipLimit if set to true will apply the skip and limits set on the cursor. Defaults to false. | ||
* @param {Function} callback this will be called after executing this method. The first parameter will contain the Error object if an error occured, or null otherwise. While the second parameter will contain the number of results or null if an error occured. | ||
@@ -291,4 +292,16 @@ * @return {null} | ||
*/ | ||
Cursor.prototype.count = function(callback) { | ||
this.collection.count(this.selector, callback); | ||
Cursor.prototype.count = function(applySkipLimit, callback) { | ||
if(typeof applySkipLimit == 'function') { | ||
callback = applySkipLimit; | ||
applySkipLimit = false; | ||
} | ||
var options = {}; | ||
if(applySkipLimit) { | ||
if(typeof this.skipValue == 'number') options.skip = this.skipValue; | ||
if(typeof this.limitValue == 'number') options.limit = this.limitValue; | ||
} | ||
// Call count command | ||
this.collection.count(this.selector, options, callback); | ||
}; | ||
@@ -295,0 +308,0 @@ |
{ "name" : "mongodb" | ||
, "description" : "A node.js driver for MongoDB" | ||
, "keywords" : ["mongodb", "mongo", "driver", "db"] | ||
, "version" : "1.2.11" | ||
, "version" : "1.2.12" | ||
, "author" : "Christian Amor Kvalheim <christkv@gmail.com>" | ||
@@ -64,3 +64,3 @@ , "contributors" : [ "Aaron Heckmann", | ||
, "dependencies" : { | ||
"bson": "0.1.6" | ||
"bson": "0.1.7" | ||
} | ||
@@ -67,0 +67,0 @@ , "devDependencies": { |
Sorry, the diff of this file is too big to display
598905
13818
+ Addedbson@0.1.7(transitive)
- Removedbson@0.1.6(transitive)
Updatedbson@0.1.7