Skip to content

Commit

Permalink
node-manager: reduce the number of access to the registry on node lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
niamster committed Feb 28, 2015
1 parent a950b49 commit 8e38d75
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/dcell/node_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ class NodeCache

class << self
# Finds a node by its node ID and adds to the cache
def register(id)
def register(id, addr)
return DCell.me if id == DCell.id
addr = Directory[id].address
return nil unless addr
loop do
begin
Expand Down Expand Up @@ -40,14 +39,16 @@ def each
Directory.each do |node|
# skip dead nodes and nodes w/o an address, those might not be operational yet
next unless node.alive? and node.address
remote = find node.id
remote = NodeCache.register node.id, node.address
yield remote
end
end

# Find a node by its node ID
def find(id)
NodeCache.register id
node = Directory[id]
return nil unless node.alive? and node.address
NodeCache.register id, node.address
end
alias_method :[], :find
end
Expand Down

0 comments on commit 8e38d75

Please sign in to comment.