Class: Aerospike::BatchIndexCommand
- Inherits:
-
MultiCommand
- Object
- Command
- MultiCommand
- Aerospike::BatchIndexCommand
- Defined in:
- lib/aerospike/command/batch_index_command.rb
Overview
:nodoc:
Direct Known Subclasses
Instance Attribute Summary collapse
-
#batch ⇒ Object
Returns the value of attribute batch.
-
#bin_names ⇒ Object
Returns the value of attribute bin_names.
-
#policy ⇒ Object
Returns the value of attribute policy.
-
#read_attr ⇒ Object
Returns the value of attribute read_attr.
-
#results ⇒ Object
Returns the value of attribute results.
Instance Method Summary collapse
-
#initialize(node, batch, policy, bin_names, results, read_attr) ⇒ BatchIndexCommand
constructor
A new instance of BatchIndexCommand.
-
#parse_row(result_code) ⇒ Object
Parse all results in the batch.
- #write_buffer ⇒ Object
Methods inherited from MultiCommand
#compressed?, #get_node, #parse_group, #parse_key, #parse_record, #parse_result, #read_bytes, #skip_key, #stop, #valid?
Methods inherited from Command
#execute, #set_delete, #set_exists, #set_operate, #set_query, #set_read, #set_read_for_key_only, #set_read_header, #set_scan, #set_touch, #set_udf, #set_write, #write_bins
Constructor Details
#initialize(node, batch, policy, bin_names, results, read_attr) ⇒ BatchIndexCommand
Returns a new instance of BatchIndexCommand.
30 31 32 33 34 35 36 37 |
# File 'lib/aerospike/command/batch_index_command.rb', line 30 def initialize(node, batch, policy, bin_names, results, read_attr) super(node) @batch = batch @policy = policy @bin_names = bin_names @results = results @read_attr = read_attr end |
Instance Attribute Details
#batch ⇒ Object
Returns the value of attribute batch.
24 25 26 |
# File 'lib/aerospike/command/batch_index_command.rb', line 24 def batch @batch end |
#bin_names ⇒ Object
Returns the value of attribute bin_names.
26 27 28 |
# File 'lib/aerospike/command/batch_index_command.rb', line 26 def bin_names @bin_names end |
#policy ⇒ Object
Returns the value of attribute policy.
25 26 27 |
# File 'lib/aerospike/command/batch_index_command.rb', line 25 def policy @policy end |
#read_attr ⇒ Object
Returns the value of attribute read_attr.
28 29 30 |
# File 'lib/aerospike/command/batch_index_command.rb', line 28 def read_attr @read_attr end |
#results ⇒ Object
Returns the value of attribute results.
27 28 29 |
# File 'lib/aerospike/command/batch_index_command.rb', line 27 def results @results end |
Instance Method Details
#parse_row(result_code) ⇒ Object
Parse all results in the batch. Add records to shared list. If the record was not found, the bins will be nil.
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/aerospike/command/batch_index_command.rb', line 106 def parse_row(result_code) generation = @data_buffer.read_int32(6) expiration = @data_buffer.read_int32(10) batch_index = @data_buffer.read_int32(14) field_count = @data_buffer.read_int16(18) op_count = @data_buffer.read_int16(20) skip_key(field_count) req_key = batch.key_for_index(batch_index) if result_code == 0 record = parse_record(req_key, op_count, generation, expiration) results[batch_index] = record end end |
#write_buffer ⇒ Object
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 99 100 101 102 |
# File 'lib/aerospike/command/batch_index_command.rb', line 39 def write_buffer bin_name_size = 0 operation_count = 0 field_count_row = 1 field_count = 1 predexp_size = estimate_predexp(@policy.predexp) field_count += 1 if predexp_size > 0 if bin_names bin_names.each do |bin_name| bin_name_size += bin_name.bytesize + OPERATION_HEADER_SIZE end operation_count = bin_names.length end begin_cmd @data_offset += FIELD_HEADER_SIZE + 4 + 1 # batch.keys.length + flags prev = nil batch.keys.each do |key| @data_offset += key.digest.length + 4 # 4 byte batch offset if prev != nil && prev.namespace == key.namespace @data_offset += 1 else @data_offset += key.namespace.bytesize + FIELD_HEADER_SIZE + 1 + 1 + 2 + 2 # repeat/no-repeat flag + read_attr flags + field_count + operation_count @data_offset += bin_name_size end end size_buffer write_header_read(policy, read_attr | INFO1_BATCH, 0, field_count, 0) write_predexp(@policy.predexp, predexp_size) write_field_header(0, Aerospike::FieldType::BATCH_INDEX) @data_offset += @data_buffer.write_int32(batch.keys.length, @data_offset) @data_offset += @data_buffer.write_byte(1, @data_offset) prev = nil batch.each_key_with_index do |key, index| @data_offset += @data_buffer.write_int32(index, @data_offset) @data_offset += @data_buffer.write_binary(key.digest, @data_offset) if (prev != nil && prev.namespace == key.namespace) @data_offset += @data_buffer.write_byte(1, @data_offset) else @data_offset += @data_buffer.write_byte(0, @data_offset) @data_offset += @data_buffer.write_byte(read_attr, @data_offset) @data_offset += @data_buffer.write_int16(field_count_row, @data_offset) @data_offset += @data_buffer.write_int16(operation_count, @data_offset) write_field_string(key.namespace, Aerospike::FieldType::NAMESPACE) if bin_names bin_names.each do |bin_name| write_operation_for_bin_name(bin_name, Aerospike::Operation::READ) end end prev = key end end end_cmd mark_compressed(@policy) end |