From 404aec42724afaf3330915dae1fa0f35683edc84 Mon Sep 17 00:00:00 2001 From: V Sreekanth Date: Wed, 13 Mar 2013 14:29:39 +0530 Subject: [PATCH] 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. --- lib/redis_proxy.js | 13 ++++++++----- lib/server.js | 7 +++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/redis_proxy.js b/lib/redis_proxy.js index 97968cb..0dfa535 100644 --- a/lib/redis_proxy.js +++ b/lib/redis_proxy.js @@ -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) { diff --git a/lib/server.js b/lib/server.js index db57777..d9b9d44 100644 --- a/lib/server.js +++ b/lib/server.js @@ -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;}