Class: Roma::Routing::RoutingTable
- Inherits:
-
Object
- Object
- Roma::Routing::RoutingTable
- Defined in:
- lib/roma/routing/rttable.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#div_bits ⇒ Object
readonly
Returns the value of attribute div_bits.
-
#fail_cnt ⇒ Object
readonly
Returns the value of attribute fail_cnt.
-
#fail_cnt_gap ⇒ Object
Returns the value of attribute fail_cnt_gap.
-
#fail_cnt_threshold ⇒ Object
Returns the value of attribute fail_cnt_threshold.
-
#hbits ⇒ Object
readonly
Returns the value of attribute hbits.
-
#mtree ⇒ Object
readonly
Returns the value of attribute mtree.
-
#rd ⇒ Object
readonly
Returns the value of attribute rd.
-
#rn ⇒ Object
readonly
Returns the value of attribute rn.
-
#search_mask ⇒ Object
readonly
Returns the value of attribute search_mask.
-
#sub_nid ⇒ Object
Returns the value of attribute sub_nid.
Instance Method Summary collapse
- #check_repetition_in_routing ⇒ Object
-
#create_nodes_from_v_idx ⇒ Object
Reconstruct vnodes from v_idx.
- #dump ⇒ Object
- #dump_binary ⇒ Object
- #dump_json ⇒ Object
- #dump_yaml ⇒ Object
- #get_stat(ap) ⇒ Object
-
#get_vnode_id(d) ⇒ Object
get vnode id from hash value.
- #init_mtree ⇒ Object
-
#initialize(rd) ⇒ RoutingTable
constructor
A new instance of RoutingTable.
-
#leave(nid) ⇒ Object
delete dropping node from list
nid
: dropping node. - #nodes ⇒ Object
- #num_of_vn(ap) ⇒ Object
- #proc_failed(nid) ⇒ Object
- #proc_succeed(nid) ⇒ Object
-
#search_nodes(vn) ⇒ Object
get array of node ID which have vnode
vn
: vnode id. -
#sub_nid_rd(addr) ⇒ Object
Returns a new RoutingData object which replaced host name by the sub_nid attribute.
- #vnodes ⇒ Object
Constructor Details
#initialize(rd) ⇒ RoutingTable
Returns a new instance of RoutingTable.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/roma/routing/rttable.rb', line 23 def initialize(rd) @log = Roma::Logging::RLogger.instance @rd = rd @rn = @rd.rn @div_bits=@rd.div_bits @hbits = 2**@rd.dgst_bits @search_mask = @rd.search_mask @fail_cnt = Hash.new(0) @fail_cnt_threshold = 5 @fail_cnt_gap = 0 @fail_time = Time.now @sub_nid = {} init_mtree end |
Instance Attribute Details
#div_bits ⇒ Object (readonly)
Returns the value of attribute div_bits.
18 19 20 |
# File 'lib/roma/routing/rttable.rb', line 18 def div_bits @div_bits end |
#fail_cnt ⇒ Object (readonly)
Returns the value of attribute fail_cnt.
14 15 16 |
# File 'lib/roma/routing/rttable.rb', line 14 def fail_cnt @fail_cnt end |
#fail_cnt_gap ⇒ Object
Returns the value of attribute fail_cnt_gap.
20 21 22 |
# File 'lib/roma/routing/rttable.rb', line 20 def fail_cnt_gap @fail_cnt_gap end |
#fail_cnt_threshold ⇒ Object
Returns the value of attribute fail_cnt_threshold.
19 20 21 |
# File 'lib/roma/routing/rttable.rb', line 19 def fail_cnt_threshold @fail_cnt_threshold end |
#hbits ⇒ Object (readonly)
Returns the value of attribute hbits.
16 17 18 |
# File 'lib/roma/routing/rttable.rb', line 16 def hbits @hbits end |
#mtree ⇒ Object (readonly)
Returns the value of attribute mtree.
15 16 17 |
# File 'lib/roma/routing/rttable.rb', line 15 def mtree @mtree end |
#rd ⇒ Object (readonly)
Returns the value of attribute rd.
12 13 14 |
# File 'lib/roma/routing/rttable.rb', line 12 def rd @rd end |
#rn ⇒ Object (readonly)
Returns the value of attribute rn.
17 18 19 |
# File 'lib/roma/routing/rttable.rb', line 17 def rn @rn end |
#search_mask ⇒ Object (readonly)
Returns the value of attribute search_mask.
13 14 15 |
# File 'lib/roma/routing/rttable.rb', line 13 def search_mask @search_mask end |
#sub_nid ⇒ Object
Returns the value of attribute sub_nid.
21 22 23 |
# File 'lib/roma/routing/rttable.rb', line 21 def sub_nid @sub_nid end |
Instance Method Details
#check_repetition_in_routing ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/roma/routing/rttable.rb', line 136 def check_repetition_in_routing @rd.v_idx.each_value{|value| host = [] value.each{|instance| host << instance.split("_")[0] } if host.uniq! return true end } false end |
#create_nodes_from_v_idx ⇒ Object
Reconstruct vnodes from v_idx
166 167 168 |
# File 'lib/roma/routing/rttable.rb', line 166 def create_nodes_from_v_idx @rd.create_nodes_from_v_idx end |
#dump ⇒ Object
118 119 120 |
# File 'lib/roma/routing/rttable.rb', line 118 def dump Marshal.dump(@rd) end |
#dump_binary ⇒ Object
132 133 134 |
# File 'lib/roma/routing/rttable.rb', line 132 def dump_binary @rd.dump_binary end |
#dump_json ⇒ Object
126 127 128 129 130 |
# File 'lib/roma/routing/rttable.rb', line 126 def dump_json JSON.generate( [{:dgst_bits=>@rd.dgst_bits,:div_bits=>@rd.div_bits,:rn=>@rd.rn}, @rd.nodes,@rd.v_idx]) end |
#dump_yaml ⇒ Object
122 123 124 |
# File 'lib/roma/routing/rttable.rb', line 122 def dump_yaml YAML.dump(@rd) end |
#get_stat(ap) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/roma/routing/rttable.rb', line 56 def get_stat(ap) pn, sn, short, lost = num_of_vn(ap) ret = {} ret['routing.redundant'] = @rn ret['routing.nodes.length'] = nodes.length ret['routing.nodes'] = nodes.inspect ret['routing.dgst_bits'] = @rd.dgst_bits ret['routing.div_bits'] = @div_bits ret['routing.vnodes.length'] = vnodes.length ret['routing.primary'] = pn (@rn-1).times{|i| ret["routing.secondary#{i+1}"] = sn[i]} ret['routing.short_vnodes'] = short ret['routing.lost_vnodes'] = lost ret['routing.fail_cnt_threshold'] = @fail_cnt_threshold ret['routing.fail_cnt_gap'] = @fail_cnt_gap ret['routing.sub_nid'] = @sub_nid.inspect ret end |
#get_vnode_id(d) ⇒ Object
get vnode id from hash value
91 92 93 |
# File 'lib/roma/routing/rttable.rb', line 91 def get_vnode_id(d) d & @search_mask end |
#init_mtree ⇒ Object
75 76 77 78 79 80 |
# File 'lib/roma/routing/rttable.rb', line 75 def init_mtree @mtree = MerkleTree.new(@rd.dgst_bits,@rd.div_bits) @rd.v_idx.each_pair{ |vn, nids| @mtree.set(vn,nids) } end |
#leave(nid) ⇒ Object
delete dropping node from list nid
: dropping node
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/roma/routing/rttable.rb', line 105 def leave(nid) @rd.nodes.delete(nid) # delet nid from list @rd.v_idx.each_pair{ |vn, nids| nids.delete_if{ |nid2| nid2 == nid} if nids.length == 0 @log.error("Vnode data is lost.(Vnode=#{vn})") end @mtree.set(vn,nids) } @fail_cnt.delete(nid) end |
#nodes ⇒ Object
82 83 84 |
# File 'lib/roma/routing/rttable.rb', line 82 def nodes @rd.nodes.clone end |
#num_of_vn(ap) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/roma/routing/rttable.rb', line 38 def num_of_vn(ap) pn = short = lost = 0 sn = Array.new(@rd.rn - 1, 0) @rd.v_idx.each_pair do |vn, nids| if nids == nil || nids.length == 0 lost += 1 next elsif nids[0] == ap pn += 1 elsif nids.include?(ap) i = nids.index(ap) - 1 sn[i] += 1 end short += 1 if nids.length < @rd.rn end [pn, sn, short, lost] end |
#proc_failed(nid) ⇒ Object
150 151 152 153 154 155 156 157 158 159 |
# File 'lib/roma/routing/rttable.rb', line 150 def proc_failed(nid) t = Time.now if t - @fail_time > @fail_cnt_gap @fail_cnt[nid] += 1 if @fail_cnt[nid] >= @fail_cnt_threshold leave(nid) end end @fail_time = t end |
#proc_succeed(nid) ⇒ Object
161 162 163 |
# File 'lib/roma/routing/rttable.rb', line 161 def proc_succeed(nid) @fail_cnt.delete(nid) end |
#search_nodes(vn) ⇒ Object
get array of node ID which have vnode vn
: vnode id
97 98 99 100 101 |
# File 'lib/roma/routing/rttable.rb', line 97 def search_nodes(vn) @rd.v_idx[vn].clone rescue nil end |
#sub_nid_rd(addr) ⇒ Object
Returns a new RoutingData object which replaced host name by the sub_nid attribute.
171 172 173 174 175 176 177 178 |
# File 'lib/roma/routing/rttable.rb', line 171 def sub_nid_rd(addr) sub_nid.each do |mask, sub| if check_netmask?(addr, mask) return get_replaced_rd(sub[:regexp], sub[:replace]) end end nil end |
#vnodes ⇒ Object
86 87 88 |
# File 'lib/roma/routing/rttable.rb', line 86 def vnodes @rd.v_idx.keys end |