Class: Aerospike::PartitionParser
- Inherits:
-
Object
- Object
- Aerospike::PartitionParser
- Defined in:
- lib/aerospike/cluster/partition_parser.rb
Overview
:nodoc:
Constant Summary collapse
- PARTITION_GENERATION =
"partition-generation"
- REPLICAS_ALL =
"replicas-all"
Instance Attribute Summary collapse
-
#copied ⇒ Object
Returns the value of attribute copied.
-
#partition_generation ⇒ Object
Returns the value of attribute partition_generation.
Instance Method Summary collapse
-
#initialize(node, conn) ⇒ PartitionParser
constructor
A new instance of PartitionParser.
- #update_partitions(current_map) ⇒ Object
Constructor Details
#initialize(node, conn) ⇒ PartitionParser
Returns a new instance of PartitionParser.
29 30 31 32 |
# File 'lib/aerospike/cluster/partition_parser.rb', line 29 def initialize(node, conn) @node = node @conn = conn end |
Instance Attribute Details
#copied ⇒ Object
Returns the value of attribute copied.
24 25 26 |
# File 'lib/aerospike/cluster/partition_parser.rb', line 24 def copied @copied end |
#partition_generation ⇒ Object
Returns the value of attribute partition_generation.
24 25 26 |
# File 'lib/aerospike/cluster/partition_parser.rb', line 24 def partition_generation @partition_generation end |
Instance Method Details
#update_partitions(current_map) ⇒ Object
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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/aerospike/cluster/partition_parser.rb', line 34 def update_partitions(current_map) # Use low-level info methods and parse byte array directly for maximum performance. # Receive format: replicas-all\t # <ns1>:<count>,<base 64 encoded bitmap1>,<base 64 encoded bitmap2>...; # <ns2>:<count>,<base 64 encoded bitmap1>,<base 64 encoded bitmap2>...;\n info_map = Info.request(@conn, PARTITION_GENERATION, REPLICAS_ALL) @partition_generation = info_map[PARTITION_GENERATION].to_i info = info_map[REPLICAS_ALL] if !info || info.length == 0 raise Aerospike::Exceptions::Connection.new("#{REPLICAS_ALL} response for node #{@node.name} is empty") end @buffer = info @length = info.length @offset = 0 new_map = nil copied = false beginning = @offset while @offset < @length && @buffer[@offset] != '\n' namespace = parse_name replica_count = parse_replica_count replica_array = current_map[namespace] if !replica_array if !copied # Make shallow copy of map. new_map = current_map.clone copied = true end replica_array = Atomic.new(Array.new(replica_count)) new_map[namespace] = replica_array end for replica in 0...replica_count do node_array = (replica_array.get)[replica] if !node_array if !copied # Make shallow copy of map. new_map = current_map.clone copied = true end node_array = Atomic.new(Array.new(Aerospike::Node::PARTITIONS)) new_map[namespace].update{|v| v[replica] = node_array; v} end restore_buffer = parse_bitmap i = 0 while i < Aerospike::Node::PARTITIONS if (restore_buffer[i>>3].ord & (0x80 >> (i & 7))) != 0 node_array.update{|v| v[i] = @node; v} end i = i.succ end end end copied ? new_map : nil end |