Skip to content

Commit

Permalink
ok, jeez, this is harder than i thought... do checking to make sure t…
Browse files Browse the repository at this point in the history
…hings are what we think they should be
  • Loading branch information
slyphon committed Feb 16, 2011
1 parent c3daba9 commit 1212b2f
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions lib/z_k/election.rb
Expand Up @@ -31,7 +31,7 @@ def root_vote_path #:nodoc:
# that it's aware of its status as the new leader and has run its
# procedures to become master
def leader_ack_path
@leader_ack_path ||= "#{@root_election_node}/leader_ack"
@leader_ack_path ||= "#{root_vote_path}/leader_ack"
end

def cast_ballot!(data)
Expand Down Expand Up @@ -183,18 +183,29 @@ def vote!
protected
# in the situation where we disconnected from zookeeper, and we've
# called vote! again, we may still hold the acknowledgement. we test for this
# by seeing if our data is the same as the leader_ack data
#---
# TODO: should probably test to see if the stat of the current ack path
# is the same as when we acknowledged, as @data is not guaranteed to be
# unique across candidates
# by seeing if the current stat of the znode is the same as the one
# that we saved when we acked earlier
def we_already_acked?
@zk.exists?(leader_ack_path) and (leader_data == @data)
return false unless @ack_stat


end

# the inauguration, as it were
def acknowledge_win!
if we_already_acked?
stat = @zk.stat(leader_ack_path)

if (@ack_stat and stat.exists)
unless (stat.mtime == @ack_stat.mtime) and (stat.version == @ack_stat.version) and (stat.ctime == @ack_stat.ctime)

# TODO: talk to topper, if this condition happens, something is
# ROYALLY screwed up, not sure what to do in this case

bug_msg = "[ZK_BUG] This situation should never have happened, leader_ack_path exists but isn't the one we thought it should be"
logger.fatal { bug_msg }
Kernel.abort(bug_msg)
end

logger.debug { "ZK: we have already acknowledged our leadership, not re-acking" }
else
logger.debug { "ZK: creating #{leader_ack_path}, data: #{@data.inspect}" }
Expand Down

0 comments on commit 1212b2f

Please sign in to comment.