Skip to content

Commit

Permalink
Added learning to the acceptor, fixed some problems in proposer
Browse files Browse the repository at this point in the history
  • Loading branch information
robhanlon22 committed Dec 10, 2009
1 parent 7e24897 commit 5df3379
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.sw?
7 changes: 4 additions & 3 deletions acceptor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ def request_accept(proposal)
@propose_mutex.synchronize do
if proposal.number >= @highest_prepare
@highest_accepted = proposal
return true
@supervisor.replicas.each do |replica|
replica.learner.learn(proposal.value)
end
end
end
end

private
Response = Struct.new :highest_accepted, :acceptor

Proposal = Struct.new :number, :value, :proposer
end
6 changes: 3 additions & 3 deletions proposer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def propose(value)
@propose_thread = Thread.new do
loop do
@propose_mutex.synchronize do
@n += 1

replicas = @supervisor.replicas

responses = replicas.inject([]) do |memo, replica|
Expand All @@ -30,14 +32,12 @@ def propose(value)
end
end

number = @n unless number
number and @n = number or number = @n

responses.each do |response|
response.acceptor.request_accept(Proposal.new(number, value, self))
end
end

@n += 1
end
end
end
Expand Down

0 comments on commit 5df3379

Please sign in to comment.