Skip to content

Commit

Permalink
Auth tests passing for replicaset
Browse files Browse the repository at this point in the history
  • Loading branch information
christkv committed Nov 6, 2011
1 parent 6eaf7b2 commit 2d4102a
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 33 deletions.
13 changes: 9 additions & 4 deletions lib/mongodb/connection/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,26 @@ Connection.prototype.write = function(command, callback) {
try {
// If we have a list off commands to be executed on the same socket
if(Array.isArray(command)) {
// console.log(" +++++++++++ Connection.prototype.write :: 1")
// console.log(" +++++++++++ Connection.prototype.write :: 1")
for(var i = 0; i < command.length; i++) {
var t = this.connection.write(command[i].toBinary());
}
} else {
// console.log(" +++++++++++ Connection.prototype.write :: 2")

// If we have a callback defined
// if(typeof callback === 'function') callback(null, null);
// console.log(" +++++++++++ Connection.prototype.write :: 3")
} else {
// console.log(" +++++++++++ Connection.prototype.write :: 4")
// console.dir(this.connection)
// console.dir(command.toBinary())
var r = this.connection.write(command.toBinary());

// console.log(" +++++++++++ Connection.prototype.write :: 3 :: " + r)
// if(typeof callback === 'function') callback(null, null);
}
} catch (err) {
// console.log(" +++++++++++ Connection.prototype.write :: 5")
if(typeof callback === 'function') callback(err);
// console.log(" +++++++++++ Connection.prototype.write :: 4")
}
}

Expand Down
35 changes: 28 additions & 7 deletions lib/mongodb/connections/repl_set_servers.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,15 +404,36 @@ ReplSetServers.prototype.checkoutReader = function() {
}

ReplSetServers.prototype.allRawConnections = function() {
var connections = this.checkoutWriter().pool.slice(0);
// Add all the pool connections
if(this.readSecondary && this.secondaries.length > 0) {
for(var i = 0; i < this.secondaries.length; i++) {
connections = connections.concat(this.secondaries[i].connection.pool);
// Neeed to build a complete list of all raw connections, start with master server
var allConnections = [];
// Get connection object
var allConnectionsObject = this._state.master.connectionPool.getAllConnections();
// Get the keys for the object
var keys = Object.keys(allConnectionsObject);
// For each connection entry add it to the list of connections
for(var i = 0; i < keys.length; i++) {
allConnections.push(allConnectionsObject[keys[i]]);
}

// If we have read secondary let's add all secondary servers
if(this.readSecondary && Object.keys(this._state.secondaries).length > 0) {
// Get all the keys
keys = Object.keys(this._state.secondaries);
// For each of the secondaries grab the connections
for(var i = 0; i < keys.length; i++) {
// Get connection object
var secondaryConnectionObject = this._state.secondaries[keys[i]].connectionPool.getAllConnections();
// Get the keys for the object
var secondaryKeys = Object.keys(secondaryConnectionObject);
// For each connection entry add it to the list of connections
for(var i = 0; i < keys.length; i++) {
allConnections.push(secondaryConnectionObject[secondaryKeys[i]]);
}
}
}
// Return the server connections
return connections;

// Return all the conections
return allConnections;
}

ReplSetServers.prototype.disconnect = function(callback) {
Expand Down
22 changes: 15 additions & 7 deletions lib/mongodb/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -820,24 +820,24 @@ var __executeQueryCommand = function(self, db_command, options, callback) {
}

var __retryCommandOnFailure = function(self, retryInMilliseconds, numberOfTimes, command, db_command, options, callback) {
// console.log("####################################################################################")
console.log("####################################################################################")
// Number of retries done
var numberOfRetriesDone = numberOfTimes;
// The interval function triggers retries
var intervalId = setInterval(function() {
// Attemp a reconnect
self.serverConfig.connect(self, {firstCall: false}, function(err, result) {
// console.log("################################################################# :: 0")
console.log("################################################################# :: 0")
// Adjust the number of retries done
numberOfRetriesDone = numberOfRetriesDone - 1;
// If we have no error, we are done
if(err != null && numberOfRetriesDone <= 0) {
// console.log("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ :: 1")
console.log("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ :: 1")
// No more retries, clear interval retries and fire an error
clearInterval(intervalId);
callback(err, null);
} else if(err == null) {
// console.log("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ :: 2")
console.log("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ :: 2")
// console.dir(self.auths)
// Clear retries and fire message
clearInterval(intervalId);
Expand Down Expand Up @@ -876,7 +876,7 @@ var __retryCommandOnFailure = function(self, retryInMilliseconds, numberOfTimes,
})
}
} else {
// console.log("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ :: 3")
console.log("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ :: 3")
command(self, db_command, options, callback);
}
}
Expand Down Expand Up @@ -907,35 +907,43 @@ Db.prototype._executeQueryCommand = function(db_command, options, callback) {
};

var __executeInsertCommand = function(self, db_command, options, callback) {
// console.log("================================================ __executeInsertCommand")
// console.log("================================================ __executeInsertCommand : 0")
// Always checkout a writer for this kind of operations
var connection = self.serverConfig.checkoutWriter();
// console.log("================================================ __executeInsertCommand : 1")
var safe = options['safe'] != null ? options['safe'] : false;
var raw = options['raw'] != null ? options['raw'] : false;
var specifiedConnection = options['connection'] != null ? options['connection'] : null;
// console.log("================================================ __executeInsertCommand : 2")
// Override connection if needed
connection = specifiedConnection != null ? specifiedConnection : connection;
// console.log("================================================ __executeInsertCommand : 3")
// Ensure we have a valid connection
if(callback instanceof Function) {
// console.log("================================================ __executeInsertCommand : 4")
// Ensure we have a valid connection
if(connection == null) return callback(new Error("no open connections"));

// We are expecting a check right after the actual operation
if(safe != null && safe != false) {
// console.log("================================================ __executeInsertCommand : 5")
// db command is now an array of commands (original command + lastError)
db_command = [db_command, DbCommand.createGetLastErrorCommand(safe, self)];

// Register the handler in the data structure
self._registerHandler(db_command[1], raw, connection, callback);
// console.log("================================================ __executeInsertCommand : 6")
}
}

// console.log("================================================ __executeInsertCommand : 7")
// console.log(connection)
// If we have no callback and there is no connection
if(connection == null) return null;

// Write the message out
connection.write(db_command, function(err) {
// console.log("================================================ __executeInsertCommand")
// console.log("================================================ __executeInsertCommand : 8")
// console.dir(err)
// console.dir(safe)

Expand Down
Loading

0 comments on commit 2d4102a

Please sign in to comment.