From 552d7244ac8919f6c1634aff38323ea7fd2417c1 Mon Sep 17 00:00:00 2001 From: Simeon Zaharici Date: Fri, 25 Apr 2014 22:08:33 -0400 Subject: [PATCH 1/2] Added check in write_state to avoid unnecessary updates of nodes znode --- lib/redis_failover/node_manager.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/redis_failover/node_manager.rb b/lib/redis_failover/node_manager.rb index eb3c569..6e8ddef 100644 --- a/lib/redis_failover/node_manager.rb +++ b/lib/redis_failover/node_manager.rb @@ -17,7 +17,7 @@ class NodeManager MAX_PROMOTION_ATTEMPTS = 3 # Latency threshold for recording node state. LATENCY_THRESHOLD = 0.5 - + $previous_value="" # Errors that can happen during the node discovery process. NODE_DISCOVERY_ERRORS = [ InvalidNodeRoleError, @@ -404,7 +404,18 @@ def create_path(path, options = {}) # @note the path will be created if it doesn't exist def write_state(path, value, options = {}) create_path(path, options.merge(:initial_value => value)) - @zk.set(path, value) + logger.info("[Debug] Now writing at path #{path}\n") + if ( path =~ /nodes/ ) + logger.info("[Debug] Now I am trying to write node info must be careful\n") + if ( $previous_value != value ) then + logger.info("[Debug] Now I am publishing the node info #{value}\n") + @zk.set(path, value) + $previous_value = value + end + else + logger.info("[Debug] Now I write my own status\n") + @zk.set(path, value) + end end # Handles a manual failover znode update. From 7b7289d120535bca5b9c394e3a2d080112ba5815 Mon Sep 17 00:00:00 2001 From: Simeon Zaharici Date: Fri, 25 Apr 2014 22:12:39 -0400 Subject: [PATCH 2/2] Removed logger lines --- lib/redis_failover/node_manager.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/redis_failover/node_manager.rb b/lib/redis_failover/node_manager.rb index 6e8ddef..04360c4 100644 --- a/lib/redis_failover/node_manager.rb +++ b/lib/redis_failover/node_manager.rb @@ -404,16 +404,12 @@ def create_path(path, options = {}) # @note the path will be created if it doesn't exist def write_state(path, value, options = {}) create_path(path, options.merge(:initial_value => value)) - logger.info("[Debug] Now writing at path #{path}\n") if ( path =~ /nodes/ ) - logger.info("[Debug] Now I am trying to write node info must be careful\n") if ( $previous_value != value ) then - logger.info("[Debug] Now I am publishing the node info #{value}\n") @zk.set(path, value) $previous_value = value end else - logger.info("[Debug] Now I write my own status\n") @zk.set(path, value) end end