Module: Roma::Routing::RandomPartitioner
- Included in:
- ChurnbasedRoutingTable
- Defined in:
- lib/roma/routing/random_partitioner.rb
Instance Method Summary collapse
- #exclude_nodes(ap_str, rep_host) ⇒ Object (also: #exclude_nodes_for_recover, #exclude_nodes_for_balance)
- #exclude_nodes_for_join(ap_str, _rep_host) ⇒ Object
- #select_node_for_release(ap_str, rep_host, nids) ⇒ Object
-
#select_vn_for_balance(exclude_nodes, _rep_host) ⇒ Object
vnode sampling exclude
exclude_nodes. -
#select_vn_for_join(exclude_nodes, rep_host) ⇒ Object
vnode sampling exclude
exclude_nodes. -
#select_vn_for_recover(exclude_nodes, _rep_host) ⇒ Object
select a vnodes where short of redundancy.
Instance Method Details
#exclude_nodes(ap_str, rep_host) ⇒ Object Also known as: exclude_nodes_for_recover, exclude_nodes_for_balance
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/roma/routing/random_partitioner.rb', line 4 def exclude_nodes(ap_str, rep_host) exclude_nodes = nodes if rep_host exclude_nodes = [ap_str] else myhost = ap_str.split(/[:_]/)[0] exclude_nodes.delete_if { |nid| nid.split(/[:_]/)[0] != myhost } end exclude_nodes end |
#exclude_nodes_for_join(ap_str, _rep_host) ⇒ Object
15 16 17 |
# File 'lib/roma/routing/random_partitioner.rb', line 15 def exclude_nodes_for_join(ap_str, _rep_host) [ap_str] end |
#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 |
#select_vn_for_balance(exclude_nodes, _rep_host) ⇒ Object
vnode sampling exclude exclude_nodes
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/roma/routing/random_partitioner.rb', line 110 def select_vn_for_balance(exclude_nodes, _rep_host) short_idx = {} idx = {} @rd.v_idx.each_pair do |vn, nids| unless list_include?(nids, exclude_nodes) idx[vn] = nids short_idx[vn] = nids if nids.length < @rd.rn end end idx = short_idx if short_idx.length > 0 ks = idx.keys return nil if ks.length == 0 vn = ks[rand(ks.length)] nids = idx[vn] [vn, nids, rand(@rd.rn) == 0] end |
#select_vn_for_join(exclude_nodes, rep_host) ⇒ Object
vnode sampling exclude exclude_nodes
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/roma/routing/random_partitioner.rb', line 31 def select_vn_for_join(exclude_nodes, rep_host) short_idx = {} myhost_idx = {} idx = {} myhost = exclude_nodes[0].split(/[:_]/)[0] @rd.v_idx.each_pair do |vn, nids| unless list_include?(nids, exclude_nodes) if myhost_include?(nids, myhost) myhost_idx[vn] = nids else idx[vn] = nids # other hosts end short_idx[vn] = nids if nids.length < @rd.rn end end # vnodes sampling priority: # 1. Short vnodes # 2. Other hosts vnodes # 3. My host vnodes if short_idx.length > 0 idx = short_idx elsif idx.length == 0 idx = myhost_idx end return nil if idx.length == 0 ks = idx.keys vn = ks[rand(ks.length)] nids = idx[vn] if !rep_host && nids[0].split(/[:_]/)[0] == myhost is_primary = true else is_primary = rand(@rd.rn) == 0 end [vn, nids, is_primary] end |
#select_vn_for_recover(exclude_nodes, _rep_host) ⇒ Object
select a vnodes where short of redundancy.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/roma/routing/random_partitioner.rb', line 74 def select_vn_for_recover(exclude_nodes, _rep_host) ret = [] @rd.v_idx.each_pair do |vn, nids| if nids.length < @rd.rn && list_include?(nids, exclude_nodes) == false ret << [vn, nids] end end if ret.length == 0 nil else n = rand(ret.length) [ret[n][0], ret[n][1], (rand(@rd.rn) == 0)] end end |