Permalink
Browse files

Fixing issue with new redis startup being ignored.

There was an issue in which after going down once the up notification
would be ignored. So even though redis was up we'd detect that redis
as still down.
  • Loading branch information...
1 parent 5abc423 commit 404aec42724afaf3330915dae1fa0f35683edc84 @sreeix committed Mar 13, 2013
Showing with 13 additions and 7 deletions.
  1. +8 −5 lib/redis_proxy.js
  2. +5 −2 lib/server.js
View
@@ -38,7 +38,7 @@ var RedisProxy = module.exports = function(o){
}
var onUp = function onUp() {
logger.debug("We have a server that went up");
- if(_.isNull(self._active) && this.client.server_info.role === 'master'){
+ if(!self.active && this.client.server_info.role === 'master'){
self._active = this;
logger.info("setting up the active "+ self._active.options.host + ":" + self._active.options.port);
self.readyup(this);
@@ -90,16 +90,19 @@ Object.defineProperty(RedisProxy.prototype, 'active', {
// balancing strategies
RedisProxy.prototype.readsToSlaves = function(command, id, callback) {
+ var serverToSend = null;
if(!this.active){
return callback(new Error("Expected to have atleast one redis to proxy"));
}
if(redisCommand.readOnly(command)) {
- logger.info('Read only command sending to the slave');
- (this.nextSlave() || this._active).sendCommand(command, id, callback);
+ logger.info('Read only command');
+ serverToSend = (this.nextSlave() || this.active)
} else {
- logger.info('mutating command sending to the active master');
- this.active.sendCommand(command, id, callback);
+ logger.info('mutating command');
+ serverToSend = this.active;
}
+ logger.info('server:'+ serverToSend.toString());
+ return serverToSend.sendCommand(command, id, callback);
};
RedisProxy.prototype.allToMaster = function(command, id, callback) {
View
@@ -94,7 +94,7 @@ Server.prototype._createConnections = function(){
, startSize: this.options.pool_size
, delayCreation: false
});
-}
+};
Server.prototype.slave = function(server){
var self = this;
@@ -122,7 +122,7 @@ Server.prototype._master = function (){
Server.prototype._incrErrorCount = function(){
this.errorCount++;
if(this.errorCount > this.options.softErrorCount){
- return this.down();
+ this.down();
}
};
@@ -158,6 +158,9 @@ Server.prototype._clearConnections = function clearConnections(){
this.connections.closeAll();
this.connections = null;
};
+Server.prototype.toString = function () {
+ return this.host+":"+ this.port;
+}
Object.defineProperty(Server.prototype, 'host', {
get: function() {return this.options.host;}

0 comments on commit 404aec4

Please sign in to comment.