Browse files

Merge remote-tracking branch 'aheckmann/replset'

  • Loading branch information...
2 parents 65c115c + d1c6a93 commit 58b735e3a0b4cd66499a4928ac3b12b0964a3ff5 @christkv committed Mar 30, 2012
Showing with 41 additions and 35 deletions.
  1. +1 −1 .gitignore
  2. +24 −24 lib/mongodb/connection/{repl_set_servers.js → repl_set.js}
  3. +8 −8 lib/mongodb/db.js
  4. +8 −2 lib/mongodb/index.js
View
2 .gitignore
@@ -1,5 +1,5 @@
.DS_Store
-*.swp
+*.sw*
*.seed
*.tmp
.project
View
48 lib/mongodb/connection/repl_set_servers.js → lib/mongodb/connection/repl_set.js
@@ -21,20 +21,20 @@ const STATE_DOWN = 8;
const STATE_ROLLBACK = 9;
/**
-* ReplSetServers constructor provides master-slave functionality
+* ReplSet constructor provides master-slave functionality
*
* @param serverArr{Array of type Server}
* @return constructor of ServerCluster
*
*/
-var ReplSetServers = exports.ReplSetServers = function(servers, options) {
+var ReplSet = exports.ReplSet = function(servers, options) {
// Set up basic
- if(!(this instanceof ReplSetServers)) return new ReplSetServers(server, options);
+ if(!(this instanceof ReplSet))
+ return new ReplSet(servers, options);
+
// Set up event emitter
- EventEmitter.call(this);
- // Set up basic
- if(!(this instanceof ReplSetServers)) return new ReplSetServers(server, options);
-
+ EventEmitter.call(this);
+
var self = this;
// Contains the master server entry
this.options = options == null ? {} : options;
@@ -222,10 +222,10 @@ var ReplSetServers = exports.ReplSetServers = function(servers, options) {
});
};
-inherits(ReplSetServers, EventEmitter);
+inherits(ReplSet, EventEmitter);
// Allow setting the read preference at the replicaset level
-ReplSetServers.prototype.setReadPreference = function(preference) {
+ReplSet.prototype.setReadPreference = function(preference) {
// Set read preference
this._readPreference = preference;
// Ensure slaveOk is correct for secodnaries read preference and tags
@@ -236,15 +236,15 @@ ReplSetServers.prototype.setReadPreference = function(preference) {
}
// Return the used state
-ReplSetServers.prototype._isUsed = function() {
+ReplSet.prototype._isUsed = function() {
return this._used;
}
-ReplSetServers.prototype.setTarget = function(target) {
+ReplSet.prototype.setTarget = function(target) {
this.target = target;
};
-ReplSetServers.prototype.isConnected = function() {
+ReplSet.prototype.isConnected = function() {
// Return the state of the replicaset server
return this.primary != null && this._state.master != null && this._state.master.isConnected();
}
@@ -253,14 +253,14 @@ Server.prototype.isSetMember = function() {
return false;
}
-ReplSetServers.prototype.isPrimary = function(config) {
+ReplSet.prototype.isPrimary = function(config) {
return this.readSecondary && this.secondaries.length > 0 ? false : true;
}
-ReplSetServers.prototype.isReadPrimary = ReplSetServers.prototype.isPrimary;
+ReplSet.prototype.isReadPrimary = ReplSet.prototype.isPrimary;
// Clean up dead connections
-var cleanupConnections = ReplSetServers.cleanupConnections = function(connections, addresses, byTags) {
+var cleanupConnections = ReplSet.cleanupConnections = function(connections, addresses, byTags) {
// Ensure we don't have entries in our set with dead connections
var keys = Object.keys(connections);
for(var i = 0; i < keys.length; i++) {
@@ -278,7 +278,7 @@ var cleanupConnections = ReplSetServers.cleanupConnections = function(connection
}
}
-var cleanupTags = ReplSetServers._cleanupTags = function(server, byTags) {
+var cleanupTags = ReplSet._cleanupTags = function(server, byTags) {
var serverTagKeys = Object.keys(server.tags);
// Iterate over all server tags and remove any instances for that tag that matches the current
// server
@@ -308,7 +308,7 @@ var cleanupTags = ReplSetServers._cleanupTags = function(server, byTags) {
}
}
-ReplSetServers.prototype.allServerInstances = function() {
+ReplSet.prototype.allServerInstances = function() {
var self = this;
// Close all the servers (concatenate entire list of servers first for ease)
var allServers = self._state.master != null ? [self._state.master] : [];
@@ -350,7 +350,7 @@ var __executeAllCallbacksWithError = function(dbInstance, error) {
}
}
-ReplSetServers.prototype.connect = function(parent, options, callback) {
+ReplSet.prototype.connect = function(parent, options, callback) {
var self = this;
var dateStamp = new Date().getTime();
if('function' === typeof options) callback = options, options = {};
@@ -820,14 +820,14 @@ ReplSetServers.prototype.connect = function(parent, options, callback) {
}
}
-ReplSetServers.prototype.checkoutWriter = function() {
+ReplSet.prototype.checkoutWriter = function() {
// Establish connection
var connection = this._state.master != null ? this._state.master.checkoutWriter() : null;
// Return the connection
return connection;
}
-ReplSetServers.prototype.checkoutReader = function() {
+ReplSet.prototype.checkoutReader = function() {
var connection = null;
// If we have specified to read from a secondary server grab a random one and read
// from it, otherwise just pass the primary connection
@@ -875,7 +875,7 @@ ReplSetServers.prototype.checkoutReader = function() {
return connection;
}
-ReplSetServers.prototype.allRawConnections = function() {
+ReplSet.prototype.allRawConnections = function() {
// Neeed to build a complete list of all raw connections, start with master server
var allConnections = [];
// Get connection object
@@ -900,7 +900,7 @@ ReplSetServers.prototype.allRawConnections = function() {
return allConnections;
}
-ReplSetServers.prototype.enableRecordQueryStats = function(enable) {
+ReplSet.prototype.enableRecordQueryStats = function(enable) {
// Set the global enable record query stats
this.recordQueryStats = enable;
// Ensure all existing servers already have the flag set, even if the
@@ -918,11 +918,11 @@ ReplSetServers.prototype.enableRecordQueryStats = function(enable) {
}
}
-ReplSetServers.prototype.disconnect = function(callback) {
+ReplSet.prototype.disconnect = function(callback) {
this.close(callback);
}
-ReplSetServers.prototype.close = function(callback) {
+ReplSet.prototype.close = function(callback) {
var self = this;
// Set server status as disconnected
this._serverState = 'disconnected';
View
16 lib/mongodb/db.js
@@ -8,7 +8,7 @@ var QueryCommand = require('./commands/query_command').QueryCommand,
Admin = require('./admin').Admin,
Collection = require('./collection').Collection,
Server = require('./connection/server').Server,
- ReplSetServers = require('./connection/repl_set_servers').ReplSetServers,
+ ReplSet = require('./connection/repl_set').ReplSet,
Cursor = require('./cursor').Cursor,
EventEmitter = require('events').EventEmitter,
inherits = require('util').inherits,
@@ -67,7 +67,7 @@ function Db(databaseName, serverConfig, options) {
var overrideUsedFlag = this.options['override_used_flag'] == null ? false : this.options['override_used_flag'];
// Verify that nobody is using this config
if(!overrideUsedFlag && typeof this.serverConfig == 'object' && this.serverConfig._isUsed()) {
- throw new Error("A Server or ReplSetServers instance cannot be shared across multiple Db instances");
+ throw new Error("A Server or ReplSet instance cannot be shared across multiple Db instances");
} else if(!overrideUsedFlag && typeof this.serverConfig == 'object'){
// Set being used
this.serverConfig._used = true;
@@ -246,7 +246,7 @@ Db.prototype.open = function(callback) {
// Set the status of the server
self._state = 'connecting';
// Set up connections
- if(self.serverConfig instanceof Server || self.serverConfig instanceof ReplSetServers) {
+ if(self.serverConfig instanceof Server || self.serverConfig instanceof ReplSet) {
self.serverConfig.connect(self, {firstCall: true}, function(err, result) {
if(err != null) {
// Return error from connection
@@ -258,7 +258,7 @@ Db.prototype.open = function(callback) {
return callback(null, self);
});
} else {
- return callback(Error("Server parameter must be of type Server or ReplSetServers"), null);
+ return callback(Error("Server parameter must be of type Server or ReplSet"), null);
}
};
@@ -1684,7 +1684,7 @@ Db.connect = function(url, options, callback) {
options = args.length ? args.shift() : null;
options = options || {};
var serverOptions = options.server || {};
- var replSetServersOptions = options.replSetServers || {};
+ var replSetServersOptions = options.replSet || options.replSetServers || {};
var dbOptions = options.db || {};
var urlRE = new RegExp('^mongo(?:db)?://(?:|([^@/]*)@)([^@/]*)(?:|/([^?]*)(?:|\\?([^?]*)))$');
@@ -1711,9 +1711,9 @@ Db.connect = function(url, options, callback) {
if (name == 'autoReconnect' || name == 'auto_reconnect')
serverOptions.auto_reconnect = (value == 'true');
if (name == 'ssl' || name == 'ssl')
- serverOptions.ssl = (value == 'true');
+ serverOptions.ssl = (value == 'true');
- // ReplSetServers options:
+ // ReplSet options:
if (name == 'replicaSet' || name == 'rs_name')
replSetServersOptions.rs_name = value;
if (name == 'reconnectWait')
@@ -1742,7 +1742,7 @@ Db.connect = function(url, options, callback) {
if (servers.length == 1) {
server = servers[0];
} else {
- server = new ReplSetServers(servers, replSetServersOptions);
+ server = new ReplSet(servers, replSetServersOptions);
}
var db = new Db(dbname, server, dbOptions);
View
10 lib/mongodb/index.js
@@ -18,7 +18,7 @@ try {
, 'collection'
, 'connection/connection'
, 'connection/server'
- , 'connection/repl_set_servers'
+ , 'connection/repl_set'
, 'cursor'
, 'db'
, 'gridfs/grid'
@@ -28,6 +28,9 @@ try {
for (var i in module) {
exports[i] = module[i];
}
+
+ // backwards compat
+ exports.ReplSetServers = exports.ReplSet;
// Add BSON Classes
exports.Binary = require('bson').Binary;
@@ -62,7 +65,7 @@ exports.pure = function() {
, 'collection'
, 'connection/connection'
, 'connection/server'
- , 'connection/repl_set_servers'
+ , 'connection/repl_set'
, 'cursor'
, 'db'
, 'gridfs/grid'
@@ -74,6 +77,9 @@ exports.pure = function() {
}
});
+ // backwards compat
+ exports.ReplSetServers = exports.ReplSet;
+
// Add BSON Classes
classes.Binary = require('bson').Binary;
classes.Code = require('bson').Code;

0 comments on commit 58b735e

Please sign in to comment.