Permalink
Browse files

etter handling of ZK session expirations in Node Manager

  • Loading branch information...
1 parent 6dce7f1 commit 97a9930ee038d0189fe51bdcf705fab8e87eab65 @ryanlecompte committed Aug 13, 2012
Showing with 9 additions and 2 deletions.
  1. +1 −0 Changes.md
  2. +4 −0 lib/redis_failover/errors.rb
  3. +4 −2 lib/redis_failover/node_manager.rb
View
@@ -7,6 +7,7 @@ HEAD
- Introduce RedisFailover::Client#on_node_change callback notification for when the currently known list of master/slave redis nodes changes.
- Added #current_master and #current_slaves to RedisFailover::Client. This is useful for programmatically doing things based on the current master/slaves.
- redis_node_manager should start if no redis servers are available (#29)
+- Better handling of ZK session expirations in Node Manager.
0.8.9
-----------
@@ -44,4 +44,8 @@ def initialize(operation)
super("Operation `#{operation}` is currently unsupported")
end
end
+
+ # Raised when we detect an expired ZK session.
+ class ZKDisconnectedError < Error
+ end
end
@@ -52,7 +52,7 @@ def start
spawn_watchers
handle_state_reports
end
- rescue ZK::Exceptions::InterruptedSession => ex
+ rescue ZK::Exceptions::InterruptedSession, ZKDisconnectedError => ex
logger.error("ZK error while attempting to manage nodes: #{ex.inspect}")
logger.error(ex.backtrace.join("\n"))
shutdown
@@ -83,6 +83,7 @@ def shutdown
def setup_zk
@zk.close! if @zk
@zk = ZK.new("#{@options[:zkservers]}#{@options[:chroot] || ''}")
+ @zk.on_expired_session { notify_state(:zk_disconnected, nil) }
@zk.register(@manual_znode) do |event|
@mutex.synchronize do
@@ -106,12 +107,13 @@ def handle_state_reports
when :available then handle_available(node)
when :syncing then handle_syncing(node)
when :manual_failover then handle_manual_failover(node)
+ when :zk_disconnected then raise ZKDisconnectedError
else raise InvalidNodeStateError.new(node, state)
end
# flush current state
write_state
- rescue ZK::Exceptions::InterruptedSession
+ rescue ZK::Exceptions::InterruptedSession, ZKDisconnectedError
# fail hard if this is a ZK connection-related error
raise
rescue => ex

0 comments on commit 97a9930

Please sign in to comment.