lib/redis_failover/client.rb in redis_failover-0.5.0 vs lib/redis_failover/client.rb in redis_failover-0.5.1
- old
+ new
@@ -108,24 +108,31 @@
private
def setup_zookeeper_client
@zkclient = ZkClient.new(@zkservers)
- # when session expires / we are disconnected, purge client list
+ # when session expires, purge client list
@zkclient.on_session_expiration do
@lock.synchronize { purge_clients }
end
+
+ # when we are disconnected, purge client list
@zkclient.event_handler.register_state_handler(:connecting) do
@lock.synchronize { purge_clients }
end
+ # when session is recovered, watch again
+ @zkclient.on_session_recovered do
+ @zkclient.stat(@znode, :watch => true)
+ end
+
# register a watcher for future changes
@zkclient.watcher.register(@znode) do |event|
if event.node_created? || event.node_changed?
build_clients
elsif event.node_deleted?
- @zkclient.stat( @znode, :watch => true)
+ @zkclient.stat(@znode, :watch => true)
@lock.synchronize { purge_clients }
else
logger.error("Unknown ZK node event: #{event.inspect}")
end
end
@@ -147,9 +154,11 @@
# direct everything else to master
master.send(method, *args, &block)
end
rescue *ALL_ERRORS => ex
logger.error("Error while handling operation `#{method}` - #{ex.message}")
+ logger.error(ex.backtrace.join("\n"))
+
if tries < @max_retries
tries += 1
build_clients
sleep(RETRY_WAIT_TIME) && retry
end