mongodb-core
Advanced tools
Comparing version 1.1.13 to 1.1.14
@@ -0,1 +1,5 @@ | ||
1.1.14 02-26-2015 | ||
----------------- | ||
- NODE-374 correctly adding passive secondaries to the list of eligable servers for reads | ||
1.1.13 02-24-2015 | ||
@@ -2,0 +6,0 @@ ----------------- |
@@ -43,3 +43,3 @@ "use strict"; | ||
*/ | ||
State.prototype.isSecondaryConnected = function() { | ||
State.prototype.isSecondaryConnected = function() { | ||
for(var i = 0; i < this.secondaries.length; i++) { | ||
@@ -185,4 +185,13 @@ if(this.secondaries[i].isConnected()) return true; | ||
}); | ||
if(this.passives.length < length) return 'passive'; | ||
// We have removed a passive | ||
if(this.passives.length < length) { | ||
// Ensure we removed it from the list of secondaries as well if it exists | ||
this.secondaries = this.secondaries.filter(function(s) { | ||
return !s.equals(server); | ||
}); | ||
return 'passive'; | ||
} | ||
// Filter out the server from the secondaries | ||
@@ -293,3 +302,3 @@ this.secondaries = this.secondaries.filter(function(s) { | ||
list.push(server); | ||
return true; | ||
return true; | ||
} | ||
@@ -338,3 +347,3 @@ | ||
if(self.logger.isInfo()) self.logger.info(f('[%s] removing %s from set', self.id, ismaster.me)); | ||
self.replSet.emit('left', self.remove(server), server); | ||
self.replSet.emit('left', self.remove(server), server); | ||
} | ||
@@ -360,3 +369,3 @@ | ||
// Log information | ||
if(self.logger.isInfo()) self.logger.info(f('[%s] updating replicaset state %s', self.id, JSON.stringify(this))); | ||
if(self.logger.isInfo()) self.logger.info(f('[%s] updating replicaset state %s', self.id, JSON.stringify(this))); | ||
@@ -376,3 +385,3 @@ // It's a master set it | ||
self.state = CONNECTED; | ||
self.replSet.emit('reconnect', server); | ||
self.replSet.emit('reconnect', server); | ||
} | ||
@@ -390,3 +399,3 @@ } else if(!ismaster.ismaster && self.setName == ismaster.setName | ||
&& ismaster.secondary && ismaster.passive) { | ||
if(self.addPassive(server)) { | ||
if(self.addPassive(server) && self.addSecondary(server)) { | ||
if(self.logger.isInfo()) self.logger.info(f('[%s] promoting %s to passive', self.id, ismaster.me)); | ||
@@ -403,3 +412,3 @@ self.replSet.emit('joined', 'passive', server); | ||
self.replSet.emit('joined', 'secondary', server); | ||
if(self.secondaryOnlyConnectionAllowed && self.state == CONNECTING) { | ||
@@ -420,2 +429,2 @@ self.state = CONNECTED; | ||
module.exports = State; | ||
module.exports = State; |
@@ -22,3 +22,3 @@ "use strict"; | ||
* used to construct connections. | ||
* | ||
* | ||
* @example | ||
@@ -28,3 +28,3 @@ * var ReplSet = require('mongodb-core').ReplSet | ||
* , assert = require('assert'); | ||
* | ||
* | ||
* var server = new ReplSet([{host: 'localhost', port: 30000}], {setName: 'rs'}); | ||
@@ -35,3 +35,3 @@ * // Wait for the connection event | ||
* }); | ||
* | ||
* | ||
* // Start connecting | ||
@@ -46,3 +46,3 @@ * server.connect(); | ||
// | ||
// | ||
// ReplSet instance id | ||
@@ -107,3 +107,3 @@ var replSetId = 1; | ||
seedlist.forEach(function(e) { | ||
if(typeof e.host != 'string' || typeof e.port != 'number') | ||
if(typeof e.host != 'string' || typeof e.port != 'number') | ||
throw new MongoError("seedlist entry must contain a host and port"); | ||
@@ -133,3 +133,3 @@ }); | ||
, Cursor: options.cursorFactory || BasicCursor | ||
// BSON Parser, ensure we have a single instance | ||
// BSON Parser, ensure we have a single instance | ||
, bsonInstance: bsonInstance | ||
@@ -193,3 +193,3 @@ // Pick the right bson parser | ||
Object.defineProperty(this, 'bson', { | ||
enumerable: true, get: function() { | ||
enumerable: true, get: function() { | ||
var servers = self.s.replState.getAll(); | ||
@@ -224,5 +224,5 @@ return servers.length > 0 ? servers[0].bson : null; | ||
}); | ||
// Add the ping strategy for nearest | ||
this.addReadPreferenceStrategy('nearest', new Ping(options)); | ||
this.addReadPreferenceStrategy('nearest', new Ping(options)); | ||
} | ||
@@ -234,3 +234,3 @@ | ||
// Plugin methods | ||
// | ||
// | ||
@@ -256,3 +256,3 @@ /** | ||
this.s.authProviders[name] = provider; | ||
} | ||
} | ||
@@ -287,3 +287,3 @@ /** | ||
this.s.options.bson = new nBSON(bsonTypes); | ||
} | ||
} | ||
@@ -322,3 +322,3 @@ /** | ||
return this.s.replState.getAllConnections(); | ||
} | ||
} | ||
@@ -365,3 +365,3 @@ /** | ||
options = options || {}; | ||
// Get a primary | ||
// Get a primary | ||
try { | ||
@@ -376,3 +376,3 @@ server = pickServer(self, self.s, ReadPreference.primary); | ||
if(server == null) return callback(new MongoError("no server found")); | ||
// Execute the command | ||
@@ -425,3 +425,3 @@ server[op](ns, ops, options, function(err, r) { | ||
if(count == 0) { | ||
// Was it a logout command clear any credentials | ||
// Was it a logout command clear any credentials | ||
if(cmd.logout) clearCredentials(self.s, ns); | ||
@@ -442,3 +442,3 @@ // We have a no master error, immediately refresh the view of the replicaset | ||
server = pickServer(self, self.s, options.writeConcern ? ReadPreference.primary : options.readPreference); | ||
if(self.s.debug) self.emit('pickedServer', options.writeConcern ? ReadPreference.primary : options.readPreference, server); | ||
if(self.s.debug) self.emit('pickedServer', options.writeConcern ? ReadPreference.primary : options.readPreference, server); | ||
} catch(err) { | ||
@@ -452,3 +452,3 @@ return callback(err); | ||
server.command(ns, cmd, options, function(err, r) { | ||
// Was it a logout command clear any credentials | ||
// Was it a logout command clear any credentials | ||
if(cmd.logout) clearCredentials(self.s, ns); | ||
@@ -461,3 +461,3 @@ // We have a no master error, immediately refresh the view of the replicaset | ||
callback(err, r); | ||
}); | ||
}); | ||
} | ||
@@ -483,3 +483,3 @@ | ||
executeWriteOperation(this, 'remove', ns, ops, options, callback); | ||
} | ||
} | ||
@@ -541,3 +541,3 @@ /** | ||
// If we don't have the mechanism fail | ||
if(this.s.authProviders[mechanism] == null && mechanism != 'default') | ||
if(this.s.authProviders[mechanism] == null && mechanism != 'default') | ||
throw new MongoError(f("auth provider %s does not exist", mechanism)); | ||
@@ -557,3 +557,3 @@ | ||
var server = servers.shift(); | ||
// Arguments without a callback | ||
@@ -585,3 +585,3 @@ var argsWithoutCallback = [mechanism, db].concat(args.slice(0)); | ||
}]); | ||
// Execute the auth | ||
@@ -644,3 +644,3 @@ server.auth.apply(server, finalArguments); | ||
server.once('connect', connectHandler(this, this.s)); | ||
// Attempt to connect | ||
@@ -660,7 +660,7 @@ server.connect(); | ||
// than can satisfy this | ||
if(options.readPreference | ||
if(options.readPreference | ||
&& options.readPreference.equals(ReadPreference.secondary)) | ||
return this.s.replState.isSecondaryConnected(); | ||
if(options.readPreference | ||
if(options.readPreference | ||
&& options.readPreference.equals(ReadPreference.primary)) | ||
@@ -761,3 +761,3 @@ return this.s.replState.isSecondaryConnected() || this.s.replState.isPrimaryConnected(); | ||
var pickServer = function(self, s, readPreference) { | ||
if(!(readPreference instanceof ReadPreference) | ||
if(!(readPreference instanceof ReadPreference) | ||
&& readPreference != null) throw new MongoError(f("readPreference %s must be an instance of ReadPreference", readPreference)); | ||
@@ -776,6 +776,6 @@ // If no read Preference set to primary by default | ||
// Check if we can satisfy and of the basic read Preferences | ||
if(readPreference.equals(ReadPreference.secondary) | ||
if(readPreference.equals(ReadPreference.secondary) | ||
&& s.replState.secondaries.length == 0) | ||
throw new MongoError("no secondary server available"); | ||
if(readPreference.equals(ReadPreference.secondaryPreferred) | ||
@@ -895,3 +895,3 @@ && s.replState.secondaries.length == 0 | ||
// If we have an error but still outstanding server request return | ||
if(err && serversLeft > 0) return; | ||
if(err && serversLeft > 0) return; | ||
// We had an error and have no more servers to inspect, schedule a new check | ||
@@ -950,4 +950,4 @@ if(err && serversLeft == 0) { | ||
// Add any new servers in primary ismaster | ||
if(err == null | ||
&& ismaster.ismaster | ||
if(err == null | ||
&& ismaster.ismaster | ||
&& Array.isArray(ismaster.hosts)) { | ||
@@ -984,3 +984,3 @@ processHosts(self, state, ismaster.hosts); | ||
// If all servers are accounted for and we have not sent the all event | ||
if(state.replState.primary != null && self.lastIsMaster() | ||
if(state.replState.primary != null && self.lastIsMaster() | ||
&& Array.isArray(self.lastIsMaster().hosts) && !state.all) { | ||
@@ -990,3 +990,3 @@ var length = 1 + state.replState.secondaries.length; | ||
state.all = true; | ||
self.emit('all', self); | ||
self.emit('all', self); | ||
} | ||
@@ -1020,3 +1020,3 @@ } | ||
if(state.initialConnectionServers == 0 && state.replState.state == CONNECTING) { | ||
if((state.secondaryOnlyConnectionAllowed && !state.replState.isSecondaryConnected() && !state.replState.isPrimaryConnected()) | ||
if((state.secondaryOnlyConnectionAllowed && !state.replState.isSecondaryConnected() && !state.replState.isPrimaryConnected()) | ||
|| (!state.secondaryOnlyConnectionAllowed && !state.replState.isPrimaryConnected())) { | ||
@@ -1030,3 +1030,3 @@ if(state.logger.isInfo()) state.logger.info(f('[%s] no valid seed servers in list', state.id)); | ||
// If the number of disconnected servers is equal to | ||
// If the number of disconnected servers is equal to | ||
// the number of seed servers we cannot connect | ||
@@ -1039,3 +1039,3 @@ if(state.disconnectedServers.length == state.seedlist.length && state.replState.state == CONNECTING) { | ||
self.emit('error', new MongoError('no valid seed servers in list')); | ||
} | ||
} | ||
} | ||
@@ -1072,3 +1072,3 @@ } | ||
return server.destroy(); | ||
} | ||
} | ||
@@ -1092,7 +1092,7 @@ // Add the server handling code | ||
// If have the server instance already destroy it | ||
if(state.initialConnectionServers.length == 0 && Object.keys(state.connectingServers).length == 0 | ||
if(state.initialConnectionServers.length == 0 && Object.keys(state.connectingServers).length == 0 | ||
&& !state.replState.isPrimaryConnected() && !state.secondaryOnlyConnectionAllowed && state.replState.state == CONNECTING) { | ||
if(state.logger.isInfo()) state.logger.info(f('[%s] no primary found in replicaset', state.id)); | ||
self.emit('error', new MongoError("no primary found in replicaset")); | ||
return self.destroy(); | ||
return self.destroy(); | ||
} | ||
@@ -1118,3 +1118,3 @@ | ||
for(var i = 0; i < state.credentials.length; i++) { | ||
server.auth.apply(server, state.credentials[i].concat([function(err, r) { | ||
server.auth.apply(server, state.credentials[i].concat([function(err, r) { | ||
count = count - 1; | ||
@@ -1138,4 +1138,4 @@ if(count == 0) processNewServer(); | ||
if(state.logger.isInfo()) state.logger.info(f('[%s] scheduled server %s for connection', state.id, hosts[i])); | ||
// Make sure we know what is trying to connect | ||
state.connectingServers[hosts[i]] = hosts[i]; | ||
// Make sure we know what is trying to connect | ||
state.connectingServers[hosts[i]] = hosts[i]; | ||
// Connect the server | ||
@@ -1175,3 +1175,3 @@ connectToServer(self, state, hosts[i].split(':')[0], parseInt(hosts[i].split(':')[1], 10)); | ||
// Attempt to connect | ||
server.connect(); | ||
server.connect(); | ||
} | ||
@@ -1246,2 +1246,2 @@ | ||
module.exports = ReplSet; | ||
module.exports = ReplSet; |
{ | ||
"name": "mongodb-core", | ||
"version": "1.1.13", | ||
"version": "1.1.14", | ||
"description": "Core MongoDB driver functionality, no bells and whistles and meant for integration not end applications", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
306199
7579