Class: Aerospike::BatchCommandGet

Inherits:
BatchCommand show all
Defined in:
lib/aerospike/command/batch_command_get.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods inherited from BatchCommand

#parse_key, #parse_record, #parse_result, #read_bytes, #stop, #valid?

Methods inherited from Command

#execute, #set_batch_exists, #set_batch_get, #set_delete, #set_exists, #set_operate, #set_read, #set_read_for_key_only, #set_read_header, #set_scan, #set_touch, #set_udf, #set_write

Constructor Details

#initialize(node, batch_namespace, policy, key_map, bin_names, records, read_attr) ⇒ BatchCommandGet

Returns a new instance of BatchCommandGet.



25
26
27
28
29
30
31
32
33
34
# File 'lib/aerospike/command/batch_command_get.rb', line 25

def initialize(node, batch_namespace, policy, key_map, bin_names, records, read_attr)
  super(node)

  @batch_namespace = batch_namespace
  @policy = policy
  @key_map = key_map
  @bin_names = bin_names
  @records = records
  @read_attr = read_attr
end

Instance Method Details

#parse_record_results(receive_size) ⇒ Object

Parse all results in the batch. Add records to shared list. If the record was not found, the bins will be nil.



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

def parse_record_results(receive_size)
  #Parse each message response and add it to the result array
  @data_offset = 0

  while @data_offset < receive_size
    read_bytes(MSG_REMAINING_HEADER_SIZE)
    result_code = @data_buffer.read(5).ord & 0xFF

    # The only valid server return codes are "ok" and "not found".
    # If other return codes are received, then abort the batch.
    if result_code != 0 && result_code != Aerospike::ResultCode::KEY_NOT_FOUND_ERROR
      raise Aerospike::Exceptions::Aerospike.new(result_code)
    end

    info3 = @data_buffer.read(3).ord

    # If cmd is the end marker of the response, do not proceed further
    return false if (info3 & INFO3_LAST) == INFO3_LAST

    generation = @data_buffer.read_int32(6).ord
    expiration = @data_buffer.read_int32(10).ord
    field_count = @data_buffer.read_int16(18).ord
    op_count = @data_buffer.read_int16(20).ord
    key = parse_key(field_count)
    item = @key_map[key.digest]

    if item
      if result_code == 0
        index = item.index
        @records[index] = parse_record(key, op_count, generation, expiration)
      end
    else
      Aerospike.logger.debug("Unexpected batch key returned: #{key.namespace}, #{key.digest}")
    end

  end # while

  true
end

#write_bufferObject



36
37
38
# File 'lib/aerospike/command/batch_command_get.rb', line 36

def write_buffer
  set_batch_get(@policy, @batch_namespace, @bin_names, @read_attr)
end