Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanlecompte committed Aug 21, 2012
1 parent 889ff87 commit d3fbf69
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
6 changes: 2 additions & 4 deletions lib/redis_failover/node_manager.rb
Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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 " +
Expand Down
4 changes: 2 additions & 2 deletions lib/redis_failover/util.rb
Expand Up @@ -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
Expand Down

0 comments on commit d3fbf69

Please sign in to comment.