Class: Aerospike::RackParser

Inherits:
Object
  • Object
show all
Defined in:
lib/aerospike/cluster/rack_parser.rb

Overview

:nodoc:

Constant Summary collapse

REBALANCE_GENERATION =
"rebalance-generation"
RACK_IDS =
"rack-ids"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, conn) ⇒ RackParser

Returns a new instance of RackParser.



29
30
31
32
33
# File 'lib/aerospike/cluster/rack_parser.rb', line 29

def initialize(node, conn)
  @node = node
  @conn = conn
  @racks = nil
end

Instance Attribute Details

#racksObject

Returns the value of attribute racks.



24
25
26
# File 'lib/aerospike/cluster/rack_parser.rb', line 24

def racks
  @racks
end

#rebalance_generationObject

Returns the value of attribute rebalance_generation.



24
25
26
# File 'lib/aerospike/cluster/rack_parser.rb', line 24

def rebalance_generation
  @rebalance_generation
end

Instance Method Details

#update_racksObject



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
# File 'lib/aerospike/cluster/rack_parser.rb', line 35

def update_racks
  # Use low-level info methods and parse byte array directly for maximum performance.
  # Receive format: rack-ids\t
  #                 <ns1>:<rack-id>...;
  #                 <ns2>:<rack-id>...; ...
  info_map = Info.request(@conn, REBALANCE_GENERATION, RACK_IDS)

  @rebalance_generation = info_map[REBALANCE_GENERATION].to_i

  info = info_map[RACK_IDS]
  if !info || info.length == 0
    raise Aerospike::Exceptions::Connection.new("#{RACK_IDS} response for node #{@node.name} is empty", @node)
  end

  @buffer = info
  @length = info.length
  @offset = 0

  while @offset < @length && @buffer[@offset] != '\n'
    namespace = parse_name
    rack_id = parse_rack_id

    @racks ||= {}
    @racks[namespace] = rack_id
  end

  @racks
end