Class: Aerospike::BatchCommand

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

Overview

:nodoc:

Instance Method Summary collapse

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, #write_bins

Constructor Details

#initialize(node) ⇒ BatchCommand

Returns a new instance of BatchCommand.



29
30
31
32
33
34
35
36
# File 'lib/aerospike/command/batch_command.rb', line 29

def initialize(node)
  super(node)

  @valid = true
  @mutex = Mutex.new

  self
end

Instance Method Details

#parse_key(field_count) ⇒ Object



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

def parse_key(field_count)
  # in Stream queries, there are no keys
  return unless field_count > 0

  digest = nil
  namespace = nil
  set_name = nil
  user_key = nil

  i = 0
  while i < field_count
    read_bytes(4)

    fieldlen = @data_buffer.read_int32(0)
    read_bytes(fieldlen)

    fieldtype = @data_buffer.read(0).ord
    size = fieldlen - 1

    case fieldtype
    when Aerospike::FieldType::DIGEST_RIPE
      digest = @data_buffer.read(1, size)
    when Aerospike::FieldType::NAMESPACE
      namespace = @data_buffer.read(1, size).force_encoding('utf-8')
    when Aerospike::FieldType::TABLE
      set_name = @data_buffer.read(1, size).force_encoding('utf-8')
    when Aerospike::FieldType::KEY
      user_key = Aerospike::bytes_to_key_value(@data_buffer.read(1).ord, @data_buffer, 2, size-1)
    end

    i = i.succ
  end

  Aerospike::Key.new(namespace, set_name, user_key, digest)
end

#parse_record(key, op_count, generation, expiration) ⇒ Object

Parses the given byte buffer and populate the result object. Returns the number of bytes that were parsed from the given buffer.



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/aerospike/command/batch_command.rb', line 96

def parse_record(key, op_count, generation, expiration)
  bins = op_count > 0 ? {} : nil
  i = 0
  while i < op_count
    raise Aerospike::Exceptions::QueryTerminated.new unless valid?

    read_bytes(8)

    op_size = @data_buffer.read_int32(0).ord
    particle_type = @data_buffer.read(5).ord
    name_size = @data_buffer.read(7).ord

    read_bytes(name_size)
    name = @data_buffer.read(0, name_size).force_encoding('utf-8')

    particle_bytes_size = op_size - (4 + name_size)
    read_bytes(particle_bytes_size)
    value = Aerospike.bytes_to_particle(particle_type, @data_buffer, 0, particle_bytes_size)

    bins[name] = value

    i = i.succ
  end

  Record.new(@node, key, bins, generation, expiration)
end

#parse_resultObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/aerospike/command/batch_command.rb', line 38

def parse_result
  # Read socket into receive buffer one record at a time.  Do not read entire receive size
  # because the receive buffer would be too big.
  status = true

  while status
    # Read header.
    read_bytes(8)

    size = @data_buffer.read_int64(0)
    receive_size = size & 0xFFFFFFFFFFFF

    if receive_size > 0
      status = parse_record_results(receive_size)
    else
      status = false
    end
  end
end

#read_bytes(length) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/aerospike/command/batch_command.rb', line 123

def read_bytes(length)
  if length > @data_buffer.length
    # Corrupted data streams can result in a huge length.
    # Do a sanity check here.
    if length > Aerospike::Buffer::MAX_BUFFER_SIZE
      raise Aerospike::Exceptions::Parse.new("Invalid read_bytes length: #{length}")
    end
    @data_buffer = Buffer.new(length)
  end

  @conn.read(@data_buffer, length)
  @data_offset += length
end

#stopObject



137
138
139
140
141
# File 'lib/aerospike/command/batch_command.rb', line 137

def stop
  @mutex.synchronize do
    @valid = false
  end
end

#valid?Boolean

Returns:

  • (Boolean)


143
144
145
146
147
148
149
150
# File 'lib/aerospike/command/batch_command.rb', line 143

def valid?
  res = nil
  @mutex.synchronize do
    res = @valid
  end

  res
end