Class: Aerospike::BatchNode

Inherits:
Object
  • Object
show all
Defined in:
lib/aerospike/command/batch_node.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, key_capacity, key) ⇒ BatchNode

Returns a new instance of BatchNode.



64
65
66
67
68
# File 'lib/aerospike/command/batch_node.rb', line 64

def initialize(node, key_capacity, key)
  @node = node
  @key_capacity = key_capacity
  @batch_namespaces = [BatchNamespace.new(key.namespace, [key])]
end

Instance Attribute Details

#batch_namespacesObject

Returns the value of attribute batch_namespaces.



31
32
33
# File 'lib/aerospike/command/batch_node.rb', line 31

def batch_namespaces
  @batch_namespaces
end

#key_capacityObject

Returns the value of attribute key_capacity.



31
32
33
# File 'lib/aerospike/command/batch_node.rb', line 31

def key_capacity
  @key_capacity
end

#nodeObject

Returns the value of attribute node.



31
32
33
# File 'lib/aerospike/command/batch_node.rb', line 31

def node
  @node
end

Class Method Details

.generate_list(cluster, keys) ⇒ Object



33
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
# File 'lib/aerospike/command/batch_node.rb', line 33

def self.generate_list(cluster, keys)
  nodes = cluster.nodes

  if nodes.length == 0
    raise Aerospike::Exceptions::Connection.new("command failed because cluster is empty.")
  end

  node_count = nodes.length
  keys_per_node = (keys.length/node_count).to_i + 10

  # Split keys by server node.
  batch_nodes = []

  keys.each do |key|
    partition = Partition.new_by_key(key)

    # error not required
    node = cluster.get_node(partition)
    batch_node = batch_nodes.detect{|bn| bn.node == node}

    unless batch_node
      batch_nodes << BatchNode.new(node, keys_per_node, key)
    else
      batch_node.add_key(key)
    end
  end

  batch_nodes
end

Instance Method Details

#add_key(key) ⇒ Object



70
71
72
73
74
75
76
77
78
# File 'lib/aerospike/command/batch_node.rb', line 70

def add_key(key)
  batch_namespace = @batch_namespaces.detect{|bn| bn.namespace == key.namespace }

  unless batch_namespace
    @batch_namespaces << BatchNamespace.new(key.namespace, [key])
  else
    batch_namespace.keys << key
  end
end