Class: Roma::Client::ClientRoutingTable
- Inherits:
-
Object
- Object
- Roma::Client::ClientRoutingTable
- Defined in:
- lib/roma/client/client_rttable.rb
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.
-
#hbits ⇒ Object
readonly
Returns the value of attribute hbits.
-
#mklhash ⇒ Object
Returns the value of attribute mklhash.
-
#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.
Instance Method Summary collapse
-
#get_vnode_id(d) ⇒ Object
Returns a vnode-id from digest.
-
#initialize(rd) ⇒ ClientRoutingTable
constructor
A new instance of ClientRoutingTable.
- #nodes ⇒ Object
- #proc_failed(nid) ⇒ Object
- #search_node(key) ⇒ Object
-
#search_nodes(vn) ⇒ Object
Returns a node-is list at the vnode.
- #vnodes ⇒ Object
Constructor Details
#initialize(rd) ⇒ ClientRoutingTable
Returns a new instance of ClientRoutingTable.
17 18 19 20 21 22 23 24 25 |
# File 'lib/roma/client/client_rttable.rb', line 17 def initialize(rd) @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) @mklhash = nil end |
Instance Attribute Details
#div_bits ⇒ Object (readonly)
Returns the value of attribute div_bits.
14 15 16 |
# File 'lib/roma/client/client_rttable.rb', line 14 def div_bits @div_bits end |
#fail_cnt ⇒ Object (readonly)
Returns the value of attribute fail_cnt.
11 12 13 |
# File 'lib/roma/client/client_rttable.rb', line 11 def fail_cnt @fail_cnt end |
#hbits ⇒ Object (readonly)
Returns the value of attribute hbits.
12 13 14 |
# File 'lib/roma/client/client_rttable.rb', line 12 def hbits @hbits end |
#mklhash ⇒ Object
Returns the value of attribute mklhash.
15 16 17 |
# File 'lib/roma/client/client_rttable.rb', line 15 def mklhash @mklhash end |
#rd ⇒ Object (readonly)
Returns the value of attribute rd.
9 10 11 |
# File 'lib/roma/client/client_rttable.rb', line 9 def rd @rd end |
#rn ⇒ Object (readonly)
Returns the value of attribute rn.
13 14 15 |
# File 'lib/roma/client/client_rttable.rb', line 13 def rn @rn end |
#search_mask ⇒ Object (readonly)
Returns the value of attribute search_mask.
10 11 12 |
# File 'lib/roma/client/client_rttable.rb', line 10 def search_mask @search_mask end |
Instance Method Details
#get_vnode_id(d) ⇒ Object
Returns a vnode-id from digest.
36 37 38 |
# File 'lib/roma/client/client_rttable.rb', line 36 def get_vnode_id(d) d & @search_mask end |
#nodes ⇒ Object
27 28 29 |
# File 'lib/roma/client/client_rttable.rb', line 27 def nodes @rd.nodes.clone end |
#proc_failed(nid) ⇒ Object
68 69 70 71 |
# File 'lib/roma/client/client_rttable.rb', line 68 def proc_failed(nid) @fail_cnt[nid] += 1 @mklhash = 0 end |
#search_node(key) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/roma/client/client_rttable.rb', line 48 def search_node(key) d = Digest::SHA1.hexdigest(key).hex % @hbits nodes = @rd.v_idx[d & @search_mask] nodes.each_index { |i| return [nodes[i], d] if @fail_cnt[nodes[i]] == 0 } # for expecting an auto assign process svn = vn = d & @search_mask while( (vn = @rd.next_vnode(vn)) != svn ) nodes = @rd.v_idx[vn] nodes.each_index { |i| return [nodes[i], d] if @fail_cnt[nodes[i]] == 0 } end nil rescue => e p e nil end |
#search_nodes(vn) ⇒ Object
Returns a node-is list at the vnode. vn
: vnode-id
42 43 44 45 46 |
# File 'lib/roma/client/client_rttable.rb', line 42 def search_nodes(vn) @rd.v_idx[vn].clone rescue nil end |
#vnodes ⇒ Object
31 32 33 |
# File 'lib/roma/client/client_rttable.rb', line 31 def vnodes @rd.v_idx.keys end |