Class: Roma::Client::ClientRoutingTable

Inherits:
Object
  • Object
show all
Defined in:
lib/roma/client/client_rttable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_bitsObject (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_cntObject (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

#hbitsObject (readonly)

Returns the value of attribute hbits.



12
13
14
# File 'lib/roma/client/client_rttable.rb', line 12

def hbits
  @hbits
end

#mklhashObject

Returns the value of attribute mklhash.



15
16
17
# File 'lib/roma/client/client_rttable.rb', line 15

def mklhash
  @mklhash
end

#rdObject (readonly)

Returns the value of attribute rd.



9
10
11
# File 'lib/roma/client/client_rttable.rb', line 9

def rd
  @rd
end

#rnObject (readonly)

Returns the value of attribute rn.



13
14
15
# File 'lib/roma/client/client_rttable.rb', line 13

def rn
  @rn
end

#search_maskObject (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

#nodesObject



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

#vnodesObject



31
32
33
# File 'lib/roma/client/client_rttable.rb', line 31

def vnodes
  @rd.v_idx.keys
end