Skip to content
This repository
Browse code

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...
commit 404aec42724afaf3330915dae1fa0f35683edc84 1 parent 5abc423
Sreekanth authored March 13, 2013
13  lib/redis_proxy.js
@@ -38,7 +38,7 @@ var RedisProxy = module.exports = function(o){
38 38
   }
39 39
   var onUp =  function onUp() {
40 40
     logger.debug("We have a server that went up");
41  
-    if(_.isNull(self._active) && this.client.server_info.role === 'master'){
  41
+    if(!self.active && this.client.server_info.role === 'master'){
42 42
       self._active = this;
43 43
       logger.info("setting up the active "+ self._active.options.host + ":" + self._active.options.port);
44 44
       self.readyup(this);
@@ -90,16 +90,19 @@ Object.defineProperty(RedisProxy.prototype, 'active', {
90 90
 
91 91
 // balancing strategies
92 92
 RedisProxy.prototype.readsToSlaves = function(command, id, callback) {
  93
+  var serverToSend = null;
93 94
   if(!this.active){
94 95
     return callback(new Error("Expected to have atleast one redis to proxy"));
95 96
   }
96 97
   if(redisCommand.readOnly(command)) {
97  
-    logger.info('Read only command sending to the slave');
98  
-    (this.nextSlave() || this._active).sendCommand(command, id, callback);
  98
+    logger.info('Read only command');
  99
+    serverToSend = (this.nextSlave() || this.active)
99 100
   } else {
100  
-    logger.info('mutating command sending to the active master');
101  
-    this.active.sendCommand(command, id, callback);
  101
+    logger.info('mutating command');
  102
+    serverToSend = this.active;
102 103
   }
  104
+  logger.info('server:'+ serverToSend.toString());
  105
+  return serverToSend.sendCommand(command, id, callback);
103 106
 };
104 107
 
105 108
 RedisProxy.prototype.allToMaster = function(command, id, callback) {
7  lib/server.js
@@ -94,7 +94,7 @@ Server.prototype._createConnections = function(){
94 94
   , startSize: this.options.pool_size
95 95
   , delayCreation: false
96 96
   });
97  
-}
  97
+};
98 98
 
99 99
 Server.prototype.slave = function(server){
100 100
   var self = this;
@@ -122,7 +122,7 @@ Server.prototype._master = function (){
122 122
 Server.prototype._incrErrorCount = function(){
123 123
   this.errorCount++;
124 124
   if(this.errorCount > this.options.softErrorCount){
125  
-    return this.down();
  125
+    this.down();
126 126
   }
127 127
 };
128 128
 
@@ -158,6 +158,9 @@ Server.prototype._clearConnections = function clearConnections(){
158 158
   this.connections.closeAll();
159 159
   this.connections = null;
160 160
 };
  161
+Server.prototype.toString = function  () {
  162
+  return this.host+":"+ this.port;
  163
+}
161 164
 
162 165
 Object.defineProperty(Server.prototype, 'host', {
163 166
   get: function() {return this.options.host;}

0 notes on commit 404aec4

Please sign in to comment.
Something went wrong with that request. Please try again.