class Aggro::NodeList
Public: Computes which nodes are responsible for a given aggregate ID.
Constants
- DEFAULT_REPLICATION_FACTOR
Attributes
state[R]
Public Instance Methods
add(node)
click to toggle source
# File lib/aggro/node_list.rb, line 8 def add(node) hash_ring << node update_state end
nodes()
click to toggle source
# File lib/aggro/node_list.rb, line 21 def nodes hash_ring.nodes.sort_by(&:id) end
nodes_for(id, replication_factor = default_replication_factor)
click to toggle source
# File lib/aggro/node_list.rb, line 14 def nodes_for(id, replication_factor = default_replication_factor) nodes .cycle .take(nodes.index(hash_ring.node_for(id)) + replication_factor) .last(replication_factor) end
Private Instance Methods
default_replication_factor()
click to toggle source
# File lib/aggro/node_list.rb, line 27 def default_replication_factor [nodes.length, DEFAULT_REPLICATION_FACTOR].min end
hash_ring()
click to toggle source
# File lib/aggro/node_list.rb, line 31 def hash_ring @hash_ring ||= ConsistentHashing::Ring.new end
update_state()
click to toggle source
# File lib/aggro/node_list.rb, line 35 def update_state @state = Digest::MD5.hexdigest(nodes.map(&:to_s).join)[0..16].hex end