Skip to content
This repository
Browse code

Cleaning up the code/adding comments. Haven't touched the major bits …

…yet though
  • Loading branch information...
commit 213ee5f09c6dfecc1ba4cf9de9ef361d462f0c22 1 parent 844c63d
Kristine Chen kristinechen authored

Showing 1 changed file with 21 additions and 9 deletions. Show diff stats Hide diff stats

  1. +21 9 new_sandbox/paxos/leader_election.rb
30 new_sandbox/paxos/leader_election.rb
@@ -23,19 +23,29 @@ module LeaderMembership
23 23 state do
24 24 # Currently known leader
25 25 table :leader, [] => [:host]
  26 + # My own address
26 27 table :me, [] => [:host]
27 28
28   - scratch :not_a_leader, leader.schema
29 29 scratch :new_leader, [:host]
30 30 scratch :temp_leader, leader.schema
  31 +
  32 + # Scratches for potential new members
  33 + scratch :potential_member, [:host]
  34 + scratch :potential_member_temp, potential_member.schema
  35 +
  36 + # Scratches to maintain if we received a leader vote message or
  37 + # a list of members
31 38 scratch :leader_vote, [:src, :host]
32   - scratch :new_member, [:host]
33   - scratch :really_new_member, new_member.schema
34 39 scratch :member_list, [:src, :members]
35 40
36 41 scratch :members_to_send, [:host]
37 42 end
38 43
  44 + # Each node, when receiving a message from pipe_out, needs to determine
  45 + # the type of message. Messages are determined by the following: the
  46 + # payload looks like [:vote, :host] or [:members, [:mem1, :mem2, ...]]
  47 + # Because of the different types of messages, we need to demultiplex
  48 + # the messages into the appropriate scratches.
39 49 bloom :demux do
40 50 leader_vote <= pipe_out do |p|
41 51 if p.payload[0] == :vote
@@ -49,15 +59,17 @@ module LeaderMembership
49 59 end
50 60 end
51 61
  62 + # From leader_vote messages, add the source and the host to a scratch of
  63 + # potential members. Those who are not in the member list should be
  64 + # added.
52 65 bloom :add_member do
53   - really_new_member <= new_member.notin(member, :host => :host)
54   - add_member <= really_new_member { |n| [n.host, n.host] }
  66 + potential_member <= leader_vote { |u| [u.src] }
  67 + potential_member <= leader_vote { |u| [u.host] }
  68 + potential_member_temp <= potential_member.notin(member, :host => :host)
  69 + add_member <= potential_member_temp { |n| [n.host, n.host] }
55 70 end
56 71
57 72 bloom :node_elect do
58   - new_member <= leader_vote { |u| [u.src] }
59   - new_member <= leader_vote { |u| [u.host] }
60   -
61 73 new_leader <= (leader_vote * leader).pairs do |lv, l|
62 74 if lv.host < l.host
63 75 [lv.host]
@@ -87,7 +99,7 @@ module LeaderMembership
87 99 end
88 100 end
89 101
90   - new_member <= member_list { |m| m.members.map { |mem| [mem] } }
  102 + potential_member <= member_list { |m| m.members.map { |mem| [mem] } }
91 103 end
92 104
93 105 bloom :leader do

0 comments on commit 213ee5f

Please sign in to comment.
Something went wrong with that request. Please try again.