Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix batch_operate for multi-node cluster #136

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/aerospike/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def batch_operate(records, options = nil)
policy = create_policy(options, BatchPolicy, default_batch_policy)

execute_batch_operate_commands(policy, records) do |node, batch|
BatchOperateCommand.new(node, batch, policy, records)
BatchOperateCommand.new(node, batch, policy)
end
end

Expand Down
15 changes: 7 additions & 8 deletions lib/aerospike/command/batch_operate_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ module Aerospike

class BatchOperateCommand < MultiCommand #:nodoc:

attr_accessor :batch, :policy, :attr, :records
attr_accessor :batch, :policy, :attr

def initialize(node, batch, policy, records)
def initialize(node, batch, policy)
super(node)
@batch = batch
@policy = policy
@records = records
end

def batch_flags
Expand All @@ -50,7 +49,7 @@ def write_buffer
@data_offset += FIELD_HEADER_SIZE + 4 + 1 # batch.keys.length + flags

prev = nil
@records.each do |record|
batch.records.each do |record|
key = record.key
@data_offset += key.digest.length + 4 # 4 byte batch offset

Expand Down Expand Up @@ -78,7 +77,7 @@ def write_buffer

prev = nil
attr = BatchAttr.new
batch.records.each_with_index do |record, index|
batch.each_record_with_index do |record, index|
@data_offset += @data_buffer.write_int32(index, @data_offset)
key = record.key
@data_offset += @data_buffer.write_binary(key.digest, @data_offset)
Expand Down Expand Up @@ -136,13 +135,13 @@ def parse_row(result_code)
op_count = @data_buffer.read_int16(20)

skip_key(field_count)
req_key = records[batch_index].key
req_key = batch.record_for_index(batch_index).key

records[batch_index].result_code = result_code
batch.record_for_index(batch_index).result_code = result_code
case result_code
when 0, ResultCode::UDF_BAD_RESPONSE
record = parse_record(req_key, op_count, generation, expiration)
records[batch_index].record = record
batch.record_for_index(batch_index).record = record
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/aerospike/command/batch_operate_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def self.generate_list(cluster, replica_policy, records)

def initialize(node, records_with_idx)
@node = node
@records_by_idx = records_with_idx.map(&:reverse).to_h
@records_by_idx = records_with_idx.to_h { |rec, idx| [idx, rec] }
end

def records
Expand Down