Skip to content

Commit

Permalink
Fixing issue with new redis startup being ignored.
Browse files Browse the repository at this point in the history
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
sreeix committed Mar 13, 2013
1 parent 5abc423 commit 404aec4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
13 changes: 8 additions & 5 deletions lib/redis_proxy.js
Expand Up @@ -38,7 +38,7 @@ var RedisProxy = module.exports = function(o){
} }
var onUp = function onUp() { var onUp = function onUp() {
logger.debug("We have a server that went up"); 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; self._active = this;
logger.info("setting up the active "+ self._active.options.host + ":" + self._active.options.port); logger.info("setting up the active "+ self._active.options.host + ":" + self._active.options.port);
self.readyup(this); self.readyup(this);
Expand Down Expand Up @@ -90,16 +90,19 @@ Object.defineProperty(RedisProxy.prototype, 'active', {


// balancing strategies // balancing strategies
RedisProxy.prototype.readsToSlaves = function(command, id, callback) { RedisProxy.prototype.readsToSlaves = function(command, id, callback) {
var serverToSend = null;
if(!this.active){ if(!this.active){
return callback(new Error("Expected to have atleast one redis to proxy")); return callback(new Error("Expected to have atleast one redis to proxy"));
} }
if(redisCommand.readOnly(command)) { if(redisCommand.readOnly(command)) {
logger.info('Read only command sending to the slave'); logger.info('Read only command');
(this.nextSlave() || this._active).sendCommand(command, id, callback); serverToSend = (this.nextSlave() || this.active)
} else { } else {
logger.info('mutating command sending to the active master'); logger.info('mutating command');
this.active.sendCommand(command, id, callback); serverToSend = this.active;
} }
logger.info('server:'+ serverToSend.toString());
return serverToSend.sendCommand(command, id, callback);
}; };


RedisProxy.prototype.allToMaster = function(command, id, callback) { RedisProxy.prototype.allToMaster = function(command, id, callback) {
Expand Down
7 changes: 5 additions & 2 deletions lib/server.js
Expand Up @@ -94,7 +94,7 @@ Server.prototype._createConnections = function(){
, startSize: this.options.pool_size , startSize: this.options.pool_size
, delayCreation: false , delayCreation: false
}); });
} };


Server.prototype.slave = function(server){ Server.prototype.slave = function(server){
var self = this; var self = this;
Expand Down Expand Up @@ -122,7 +122,7 @@ Server.prototype._master = function (){
Server.prototype._incrErrorCount = function(){ Server.prototype._incrErrorCount = function(){
this.errorCount++; this.errorCount++;
if(this.errorCount > this.options.softErrorCount){ if(this.errorCount > this.options.softErrorCount){
return this.down(); this.down();
} }
}; };


Expand Down Expand Up @@ -158,6 +158,9 @@ Server.prototype._clearConnections = function clearConnections(){
this.connections.closeAll(); this.connections.closeAll();
this.connections = null; this.connections = null;
}; };
Server.prototype.toString = function () {
return this.host+":"+ this.port;
}


Object.defineProperty(Server.prototype, 'host', { Object.defineProperty(Server.prototype, 'host', {
get: function() {return this.options.host;} get: function() {return this.options.host;}
Expand Down

0 comments on commit 404aec4

Please sign in to comment.