Method: Roma::Routing::RandomPartitioner#select_node_for_release

Defined in:
lib/roma/routing/random_partitioner.rb

#select_node_for_release(ap_str, rep_host, nids) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/roma/routing/random_partitioner.rb', line 89

def select_node_for_release(ap_str, rep_host, nids)
  buf = nodes

  unless rep_host
    deny_hosts = []
    nids.each do |nid|
      host = nid.split(/[:_]/)[0]
      deny_hosts << host if host != ap_str.split(/[:_]/)[0]
    end
    buf.delete_if { |nid| deny_hosts.include?(nid.split(/[:_]/)[0]) }
  else
    nids.each { |nid| buf.delete(nid) }
  end

  buf.delete_if { |instance| instance == ap_str }
  to_nid = buf.sample
  new_nids = nids.map { |n| n == ap_str ? to_nid : n }
  [to_nid, new_nids]
end