Permalink
Browse files

Added functionality for when a new member randomly joins

  • Loading branch information...
1 parent d8b6b60 commit 844c63dd24d1e3caffdabf0395b45837d27da3a3 @kristinechen kristinechen committed Dec 13, 2011
Showing with 10 additions and 2 deletions.
  1. +10 −2 new_sandbox/paxos/leader_election.rb
@@ -5,24 +5,29 @@
require 'counter/sequences'
require 'delivery/delivery'
+# @abstract LeaderMembership is the module for Paxos leader election.
+# A given node in Paxos should include this module.
module LeaderMembership
include MembershipProtocol
include MulticastProtocol
include SequencesProtocol
include DeliveryProtocol
+ # Each node believes it is its own leader when it first starts up.
bootstrap do
me <= [[ip_port]]
leader <= me
add_member <= me { |m| [m.host, m.host] }
end
state do
+ # Currently known leader
table :leader, [] => [:host]
table :me, [] => [:host]
scratch :not_a_leader, leader.schema
- scratch :new_leader, leader.schema
+ scratch :new_leader, [:host]
+ scratch :temp_leader, leader.schema
scratch :leader_vote, [:src, :host]
scratch :new_member, [:host]
scratch :really_new_member, new_member.schema
@@ -58,7 +63,10 @@ module LeaderMembership
[lv.host]
end
end
- leader <+- new_leader
+
+ temp_leader <= member.group([:host], min(:host))
+ new_leader <= temp_leader.notin(leader, :host => :host)
+ leader <+- new_leader.group([:host], min(:host))
increment_count <= new_leader { |n| [:mcast_msg] }
get_count <= [[:mcast_msg]]

0 comments on commit 844c63d

Please sign in to comment.