From d3fbf69fd851ce8224f33eef119066da0ba36fa4 Mon Sep 17 00:00:00 2001 From: Ryan LeCompte Date: Tue, 21 Aug 2012 09:38:37 -0700 Subject: [PATCH] cleanup --- lib/redis_failover/node_manager.rb | 6 ++---- lib/redis_failover/util.rb | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/redis_failover/node_manager.rb b/lib/redis_failover/node_manager.rb index ca4b953..5274010 100644 --- a/lib/redis_failover/node_manager.rb +++ b/lib/redis_failover/node_manager.rb @@ -208,13 +208,10 @@ def handle_manual_failover(node) # @param [Node] node the optional node to promote # @note if no node is specified, a random slave will be used def promote_new_master(node = nil) - clients_lock = Mutex.new presence_group = ZK::Group.new(@zk, CLIENT_PRESENCE_GROUP) presence_group.create - ack_group = ZK::Group.new(@zk, CLIENT_FAILOVER_ACK_GROUP) ack_group.create - clients = presence_group.member_names(:watch => true) delete_path @@ -223,6 +220,7 @@ def promote_new_master(node = nil) # clients that appear, because we've already deleted the znode and # they will automatically see the new master once we write out the # new config. + clients_lock = Mutex.new presence_group.on_membership_change do |old_members, current_members| clients_lock.synchronize do clients -= diff(clients, current_members) @@ -237,7 +235,7 @@ def promote_new_master(node = nil) end end logger.info('Waiting for ACK from clients to begin failover ...') - if sleep_until(deadline, &condition) + if wait_until(deadline, &condition) logger.info('Received failover ACK from all clients') else logger.info("Failed to receive failover ACK from all clients " + diff --git a/lib/redis_failover/util.rb b/lib/redis_failover/util.rb index 2967620..af12c78 100644 --- a/lib/redis_failover/util.rb +++ b/lib/redis_failover/util.rb @@ -141,12 +141,12 @@ def decode(data) MultiJson.decode(data) end - # Sleeps until the deadline or the condition evaluates to true. + # Waits until the deadline or the condition evaluates to true. # # @param [Time] deadline the deadline time # @param [Proc] condition the condition at which to stop sleeping # @return [Boolean] true if condition met before deadline, false otherwise - def sleep_until(deadline, &condition) + def wait_until(deadline, &condition) remaining = deadline - Time.now while remaining > 0 return true if condition.call