Skip to content

Commit

Permalink
Moved the structs into PaxosRole so that they can be shared by all, r…
Browse files Browse the repository at this point in the history
…ather than redefined in each. Also added 'require' goodness to RPCExporter and Supervisor. Also added replica ids to supervisor for (potentially) easier interaction in client. Last time I hadn't git add'd them, and this time I did, so there.
  • Loading branch information
Daniel Otero committed Dec 14, 2009
1 parent 463fa92 commit 87ceb0c
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
3 changes: 0 additions & 3 deletions acceptor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,4 @@ def request_accept(proposal)
end
end
end

private
Response = Struct.new :highest_accepted, :acceptor
end
4 changes: 4 additions & 0 deletions paxos_role.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
class PaxosRole
protected

Response = Struct.new :highest_accepted, :acceptor
Proposal = Struct.new :number, :value, :proposer
end
3 changes: 0 additions & 3 deletions proposer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,4 @@ def value_learned!
end

alias_method :value_learned!, :kill_thread

private
Proposal = Struct.new :number, :value, :proposer
end
11 changes: 11 additions & 0 deletions rpc_exporter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# Add the current file's directory (i.e. p551-assignment3) to Ruby's
# internal 'require' load path.
$LOAD_PATH.unshift(File.dirname(__FILE__))

# Require all our paxos stuff
require 'paxos_role'
require 'proposer'
require 'acceptor'
require 'learner'
require 'supervisor'

class RPCExporter < PaxosRole
attr_reader :proposer, :acceptor, :learner

Expand Down
26 changes: 23 additions & 3 deletions supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,34 @@ class Supervisor
attr_reader :replicas

def initialize
@next_id = 1
@replicas = Set.new
@id_map = {}
end

def add_replica(replica)
@replicas.add(replica)
def add_replica(replica, id=@next_id)
if @replicas.add?(replica)
@id_map[id]
@next_id += 1
end
end

def remove_replica(replica)
@replicas.remove(replica)
if @replicas.delete?(replica)
@id_map.each do |k,v|
if v == replica
@id_map.delete(k)
break
end
end
end
end

def replica_by_id(id)
@id_map[id]
end

def [](id)
replica_by_id(id)
end
end

0 comments on commit 87ceb0c

Please sign in to comment.