aerospike 3.0.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -0
- data/README.md +13 -9
- data/lib/aerospike/batch_attr.rb +292 -0
- data/lib/aerospike/batch_delete.rb +48 -0
- data/lib/aerospike/batch_read.rb +97 -0
- data/lib/aerospike/batch_record.rb +83 -0
- data/lib/aerospike/batch_results.rb +38 -0
- data/lib/aerospike/batch_udf.rb +76 -0
- data/lib/aerospike/batch_write.rb +79 -0
- data/lib/aerospike/cdt/bit_operation.rb +4 -5
- data/lib/aerospike/cdt/map_return_type.rb +8 -0
- data/lib/aerospike/client.rb +37 -51
- data/lib/aerospike/cluster.rb +50 -46
- data/lib/aerospike/command/batch_index_command.rb +6 -10
- data/lib/aerospike/command/batch_index_node.rb +3 -4
- data/lib/aerospike/command/batch_operate_command.rb +151 -0
- data/lib/aerospike/command/batch_operate_node.rb +51 -0
- data/lib/aerospike/command/command.rb +101 -87
- data/lib/aerospike/command/single_command.rb +1 -1
- data/lib/aerospike/exp/exp.rb +39 -41
- data/lib/aerospike/exp/exp_bit.rb +24 -24
- data/lib/aerospike/exp/exp_hll.rb +12 -12
- data/lib/aerospike/exp/exp_list.rb +101 -92
- data/lib/aerospike/exp/exp_map.rb +118 -121
- data/lib/aerospike/exp/operation.rb +2 -2
- data/lib/aerospike/info.rb +2 -4
- data/lib/aerospike/node.rb +7 -3
- data/lib/aerospike/operation.rb +38 -0
- data/lib/aerospike/policy/batch_delete_policy.rb +71 -0
- data/lib/aerospike/policy/batch_policy.rb +53 -4
- data/lib/aerospike/{command/batch_direct_node.rb → policy/batch_read_policy.rb} +17 -19
- data/lib/aerospike/policy/batch_udf_policy.rb +75 -0
- data/lib/aerospike/policy/batch_write_policy.rb +105 -0
- data/lib/aerospike/policy/policy.rb +3 -40
- data/lib/aerospike/query/server_command.rb +1 -0
- data/lib/aerospike/query/statement.rb +5 -21
- data/lib/aerospike/utils/buffer.rb +15 -15
- data/lib/aerospike/version.rb +1 -1
- data/lib/aerospike.rb +13 -12
- metadata +16 -14
- data/lib/aerospike/command/batch_direct_command.rb +0 -105
- data/lib/aerospike/command/batch_direct_exists_command.rb +0 -51
- data/lib/aerospike/query/pred_exp/and_or.rb +0 -32
- data/lib/aerospike/query/pred_exp/geo_json_value.rb +0 -41
- data/lib/aerospike/query/pred_exp/integer_value.rb +0 -32
- data/lib/aerospike/query/pred_exp/op.rb +0 -27
- data/lib/aerospike/query/pred_exp/regex.rb +0 -32
- data/lib/aerospike/query/pred_exp/regex_flags.rb +0 -23
- data/lib/aerospike/query/pred_exp/string_value.rb +0 -29
- data/lib/aerospike/query/pred_exp.rb +0 -192
@@ -0,0 +1,151 @@
|
|
1
|
+
# Copyright 2018 Aerospike, Inc.
|
2
|
+
#
|
3
|
+
# Portions may be licensed to Aerospike, Inc. under one or more contributor
|
4
|
+
# license agreements.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
7
|
+
# use this file except in compliance with the License. You may obtain a copy of
|
8
|
+
# the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
14
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
15
|
+
# License for the specific language governing permissions and limitations under
|
16
|
+
# the License.
|
17
|
+
|
18
|
+
require 'aerospike/command/multi_command'
|
19
|
+
|
20
|
+
module Aerospike
|
21
|
+
|
22
|
+
class BatchOperateCommand < MultiCommand #:nodoc:
|
23
|
+
|
24
|
+
attr_accessor :batch, :policy, :attr, :records
|
25
|
+
|
26
|
+
def initialize(node, batch, policy, records)
|
27
|
+
super(node)
|
28
|
+
@batch = batch
|
29
|
+
@policy = policy
|
30
|
+
@records = records
|
31
|
+
end
|
32
|
+
|
33
|
+
def batch_flags
|
34
|
+
flags = 0
|
35
|
+
# flags |= 0x1 if @policy.allow_inline
|
36
|
+
flags |= 0x2 if @policy.allow_inline_ssd
|
37
|
+
flags |= 0x4 if @policy.respond_all_keys
|
38
|
+
flags
|
39
|
+
end
|
40
|
+
|
41
|
+
def write_buffer
|
42
|
+
field_count = 1
|
43
|
+
|
44
|
+
exp_size = estimate_expression_size(@policy.filter_exp)
|
45
|
+
@data_offset += exp_size
|
46
|
+
field_count += 1 if exp_size > 0
|
47
|
+
|
48
|
+
@data_buffer.reset
|
49
|
+
begin_cmd
|
50
|
+
@data_offset += FIELD_HEADER_SIZE + 4 + 1 # batch.keys.length + flags
|
51
|
+
|
52
|
+
prev = nil
|
53
|
+
@records.each do |record|
|
54
|
+
key = record.key
|
55
|
+
@data_offset += key.digest.length + 4 # 4 byte batch offset
|
56
|
+
|
57
|
+
if !@policy.send_key && !prev.nil? && prev.key.namespace == key.namespace && prev.key.set_name == key.set_name && record == prev
|
58
|
+
@data_offset += 1
|
59
|
+
else
|
60
|
+
@data_offset += 12
|
61
|
+
@data_offset += key.namespace.bytesize + FIELD_HEADER_SIZE
|
62
|
+
@data_offset += key.set_name.bytesize + FIELD_HEADER_SIZE
|
63
|
+
@data_offset += record.size
|
64
|
+
end
|
65
|
+
|
66
|
+
prev = record
|
67
|
+
end
|
68
|
+
size_buffer
|
69
|
+
write_batch_header(policy, field_count)
|
70
|
+
|
71
|
+
write_filter_exp(@policy.filter_exp, exp_size)
|
72
|
+
|
73
|
+
field_size_offset = @data_offset
|
74
|
+
|
75
|
+
write_field_header(0, Aerospike::FieldType::BATCH_INDEX)
|
76
|
+
@data_offset += @data_buffer.write_int32(batch.records.length, @data_offset)
|
77
|
+
@data_offset += @data_buffer.write_byte(batch_flags, @data_offset)
|
78
|
+
|
79
|
+
prev = nil
|
80
|
+
attr = BatchAttr.new
|
81
|
+
batch.records.each_with_index do |record, index|
|
82
|
+
@data_offset += @data_buffer.write_int32(index, @data_offset)
|
83
|
+
key = record.key
|
84
|
+
@data_offset += @data_buffer.write_binary(key.digest, @data_offset)
|
85
|
+
|
86
|
+
if !@policy.send_key && !prev.nil? && prev.key.namespace == key.namespace && prev.key.set_name == key.set_name && record == prev
|
87
|
+
@data_offset += @data_buffer.write_byte(BATCH_MSG_REPEAT, @data_offset)
|
88
|
+
else
|
89
|
+
case record
|
90
|
+
when BatchRead
|
91
|
+
attr.set_batch_read(record.policy)
|
92
|
+
if record.bin_names&.length&.> 0
|
93
|
+
write_batch_bin_names(key, record.bin_names, attr, attr.filter_exp)
|
94
|
+
elsif record.ops&.length&.> 0
|
95
|
+
attr.adjust_read(br.ops)
|
96
|
+
write_batch_operations(key, record.ops, attr, attr.filter_exp)
|
97
|
+
else
|
98
|
+
attr.adjust_read_all_bins(record.read_all_bins)
|
99
|
+
write_batch_read(key, attr, attr.filter_exp, 0)
|
100
|
+
end
|
101
|
+
|
102
|
+
when BatchWrite
|
103
|
+
attr.set_batch_write(record.policy)
|
104
|
+
attr.adjust_write(record.ops)
|
105
|
+
write_batch_operations(key, record.ops, attr, attr.filter_exp)
|
106
|
+
|
107
|
+
when BatchUDF
|
108
|
+
attr.set_batch_udf(record.policy)
|
109
|
+
write_batch_write(key, attr, attr.filter_exp, 3, 0)
|
110
|
+
write_field_string(record.package_name, Aerospike::FieldType::UDF_PACKAGE_NAME)
|
111
|
+
write_field_string(record.function_name, Aerospike::FieldType::UDF_FUNCTION)
|
112
|
+
write_field_bytes(record.arg_bytes, Aerospike::FieldType::UDF_ARGLIST)
|
113
|
+
|
114
|
+
when BatchDelete
|
115
|
+
attr.set_batch_delete(record.policy)
|
116
|
+
write_batch_write(key, attr, attr.filter_exp, 0, 0)
|
117
|
+
end
|
118
|
+
|
119
|
+
prev = record
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
@data_buffer.write_uint32(@data_offset-MSG_TOTAL_HEADER_SIZE-4, field_size_offset)
|
124
|
+
|
125
|
+
end_cmd
|
126
|
+
mark_compressed(@policy)
|
127
|
+
end
|
128
|
+
|
129
|
+
# Parse all results in the batch. Add records to shared list.
|
130
|
+
# If the record was not found, the bins will be nil.
|
131
|
+
def parse_row(result_code)
|
132
|
+
generation = @data_buffer.read_int32(6)
|
133
|
+
expiration = @data_buffer.read_int32(10)
|
134
|
+
batch_index = @data_buffer.read_int32(14)
|
135
|
+
field_count = @data_buffer.read_int16(18)
|
136
|
+
op_count = @data_buffer.read_int16(20)
|
137
|
+
|
138
|
+
skip_key(field_count)
|
139
|
+
req_key = records[batch_index].key
|
140
|
+
|
141
|
+
records[batch_index].result_code = result_code
|
142
|
+
case result_code
|
143
|
+
when 0, ResultCode::UDF_BAD_RESPONSE
|
144
|
+
record = parse_record(req_key, op_count, generation, expiration)
|
145
|
+
records[batch_index].record = record
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
end # class
|
150
|
+
|
151
|
+
end # module
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# Copyright 2018 Aerospike, Inc.
|
2
|
+
#
|
3
|
+
# Portions may be licensed to Aerospike, Inc. under one or more contributor
|
4
|
+
# license agreements.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
7
|
+
# use this file except in compliance with the License. You may obtain a copy of
|
8
|
+
# the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
14
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
15
|
+
# License for the specific language governing permissions and limitations under
|
16
|
+
# the License.
|
17
|
+
|
18
|
+
module Aerospike
|
19
|
+
|
20
|
+
class BatchOperateNode #:nodoc:
|
21
|
+
|
22
|
+
attr_accessor :node, :records_by_idx
|
23
|
+
|
24
|
+
def self.generate_list(cluster, replica_policy, records)
|
25
|
+
records.each_with_index
|
26
|
+
.group_by { |record, _| cluster.get_node_for_key(replica_policy, record.key, is_write: record.has_write) }
|
27
|
+
.map { |node, records_with_idx| BatchOperateNode.new(node, records_with_idx) }
|
28
|
+
end
|
29
|
+
|
30
|
+
def initialize(node, records_with_idx)
|
31
|
+
@node = node
|
32
|
+
@records_by_idx = records_with_idx.map(&:reverse).to_h
|
33
|
+
end
|
34
|
+
|
35
|
+
def records
|
36
|
+
records_by_idx.values
|
37
|
+
end
|
38
|
+
|
39
|
+
def each_record_with_index
|
40
|
+
records_by_idx.each do |idx, rec|
|
41
|
+
yield rec, idx
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def record_for_index(idx)
|
46
|
+
@records_by_idx[idx]
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -76,6 +76,12 @@ module Aerospike
|
|
76
76
|
# Completely replace existing record only.
|
77
77
|
INFO3_REPLACE_ONLY = Integer(1 << 5)
|
78
78
|
|
79
|
+
BATCH_MSG_READ = 0x0
|
80
|
+
BATCH_MSG_REPEAT = 0x1
|
81
|
+
BATCH_MSG_INFO = 0x2
|
82
|
+
BATCH_MSG_GEN = 0x4
|
83
|
+
BATCH_MSG_TTL = 0x8
|
84
|
+
|
79
85
|
MSG_TOTAL_HEADER_SIZE = 30
|
80
86
|
FIELD_HEADER_SIZE = 5
|
81
87
|
OPERATION_HEADER_SIZE = 8
|
@@ -112,9 +118,6 @@ module Aerospike
|
|
112
118
|
begin_cmd
|
113
119
|
field_count = estimate_key_size(key, policy)
|
114
120
|
|
115
|
-
predexp_size = estimate_predexp(policy.predexp)
|
116
|
-
field_count += 1 if predexp_size > 0
|
117
|
-
|
118
121
|
exp_size = estimate_expression_size(@policy.filter_exp)
|
119
122
|
field_count += 1 if exp_size > 0
|
120
123
|
|
@@ -126,7 +129,6 @@ module Aerospike
|
|
126
129
|
|
127
130
|
write_header_write(policy, INFO2_WRITE, field_count, bins.length)
|
128
131
|
write_key(key, policy)
|
129
|
-
write_predexp(policy.predexp, predexp_size)
|
130
132
|
write_filter_exp(@policy.filter_exp, exp_size)
|
131
133
|
|
132
134
|
bins.each do |bin|
|
@@ -142,16 +144,12 @@ module Aerospike
|
|
142
144
|
begin_cmd
|
143
145
|
field_count = estimate_key_size(key)
|
144
146
|
|
145
|
-
predexp_size = estimate_predexp(policy.predexp)
|
146
|
-
field_count += 1 if predexp_size > 0
|
147
|
-
|
148
147
|
exp_size = estimate_expression_size(@policy.filter_exp)
|
149
148
|
field_count += 1 if exp_size > 0
|
150
149
|
|
151
150
|
size_buffer
|
152
|
-
write_header_write(policy,
|
151
|
+
write_header_write(policy, INFO2_WRITE | INFO2_DELETE, field_count, 0)
|
153
152
|
write_key(key)
|
154
|
-
write_predexp(policy.predexp, predexp_size)
|
155
153
|
write_filter_exp(@policy.filter_exp, exp_size)
|
156
154
|
end_cmd
|
157
155
|
end
|
@@ -161,17 +159,13 @@ module Aerospike
|
|
161
159
|
begin_cmd
|
162
160
|
field_count = estimate_key_size(key)
|
163
161
|
|
164
|
-
predexp_size = estimate_predexp(policy.predexp)
|
165
|
-
field_count += 1 if predexp_size > 0
|
166
|
-
|
167
162
|
exp_size = estimate_expression_size(@policy.filter_exp)
|
168
163
|
field_count += 1 if exp_size > 0
|
169
164
|
|
170
165
|
estimate_operation_size
|
171
166
|
size_buffer
|
172
|
-
write_header_write(policy,
|
167
|
+
write_header_write(policy, INFO2_WRITE, field_count, 1)
|
173
168
|
write_key(key)
|
174
|
-
write_predexp(policy.predexp, predexp_size)
|
175
169
|
write_filter_exp(@policy.filter_exp, exp_size)
|
176
170
|
write_operation_for_operation_type(Aerospike::Operation::TOUCH)
|
177
171
|
end_cmd
|
@@ -182,16 +176,12 @@ module Aerospike
|
|
182
176
|
begin_cmd
|
183
177
|
field_count = estimate_key_size(key)
|
184
178
|
|
185
|
-
predexp_size = estimate_predexp(policy.predexp)
|
186
|
-
field_count += 1 if predexp_size > 0
|
187
|
-
|
188
179
|
exp_size = estimate_expression_size(@policy.filter_exp)
|
189
180
|
field_count += 1 if exp_size > 0
|
190
181
|
|
191
182
|
size_buffer
|
192
183
|
write_header_read_header(policy, INFO1_READ | INFO1_NOBINDATA, field_count, 0)
|
193
184
|
write_key(key)
|
194
|
-
write_predexp(policy.predexp, predexp_size)
|
195
185
|
write_filter_exp(@policy.filter_exp, exp_size)
|
196
186
|
end_cmd
|
197
187
|
end
|
@@ -201,16 +191,12 @@ module Aerospike
|
|
201
191
|
begin_cmd
|
202
192
|
field_count = estimate_key_size(key)
|
203
193
|
|
204
|
-
predexp_size = estimate_predexp(policy.predexp)
|
205
|
-
field_count += 1 if predexp_size > 0
|
206
|
-
|
207
194
|
exp_size = estimate_expression_size(@policy.filter_exp)
|
208
195
|
field_count += 1 if exp_size > 0
|
209
196
|
|
210
197
|
size_buffer
|
211
198
|
write_header_read(policy, INFO1_READ | INFO1_GET_ALL, 0, field_count, 0)
|
212
199
|
write_key(key)
|
213
|
-
write_predexp(policy.predexp, predexp_size)
|
214
200
|
write_filter_exp(@policy.filter_exp, exp_size)
|
215
201
|
end_cmd
|
216
202
|
end
|
@@ -221,9 +207,6 @@ module Aerospike
|
|
221
207
|
begin_cmd
|
222
208
|
field_count = estimate_key_size(key)
|
223
209
|
|
224
|
-
predexp_size = estimate_predexp(policy.predexp)
|
225
|
-
field_count += 1 if predexp_size > 0
|
226
|
-
|
227
210
|
exp_size = estimate_expression_size(@policy.filter_exp)
|
228
211
|
field_count += 1 if exp_size > 0
|
229
212
|
|
@@ -239,7 +222,6 @@ module Aerospike
|
|
239
222
|
|
240
223
|
write_header_read(policy, attr, 0, field_count, bin_names.length)
|
241
224
|
write_key(key)
|
242
|
-
write_predexp(policy.predexp, predexp_size)
|
243
225
|
write_filter_exp(@policy.filter_exp, exp_size)
|
244
226
|
|
245
227
|
bin_names.each do |bin_name|
|
@@ -258,9 +240,6 @@ module Aerospike
|
|
258
240
|
begin_cmd
|
259
241
|
field_count = estimate_key_size(key)
|
260
242
|
|
261
|
-
predexp_size = estimate_predexp(policy.predexp)
|
262
|
-
field_count += 1 if predexp_size > 0
|
263
|
-
|
264
243
|
exp_size = estimate_expression_size(@policy.filter_exp)
|
265
244
|
field_count += 1 if exp_size > 0
|
266
245
|
|
@@ -273,7 +252,6 @@ module Aerospike
|
|
273
252
|
write_header_read_header(policy, INFO1_READ|INFO1_NOBINDATA, field_count, 0)
|
274
253
|
|
275
254
|
write_key(key)
|
276
|
-
write_predexp(policy.predexp, predexp_size)
|
277
255
|
write_filter_exp(@policy.filter_exp, exp_size)
|
278
256
|
end_cmd
|
279
257
|
mark_compressed(policy)
|
@@ -284,9 +262,6 @@ module Aerospike
|
|
284
262
|
begin_cmd
|
285
263
|
field_count = estimate_key_size(key, policy)
|
286
264
|
|
287
|
-
predexp_size = estimate_predexp(policy.predexp)
|
288
|
-
field_count += 1 if predexp_size > 0
|
289
|
-
|
290
265
|
exp_size = estimate_expression_size(policy.filter_exp)
|
291
266
|
field_count += 1 if exp_size > 0
|
292
267
|
|
@@ -296,7 +271,6 @@ module Aerospike
|
|
296
271
|
|
297
272
|
write_header_read_write(policy, args.read_attr, args.write_attr, field_count, args.operations.length)
|
298
273
|
write_key(key, policy)
|
299
|
-
write_predexp(policy.predexp, predexp_size)
|
300
274
|
write_filter_exp(policy.filter_exp, exp_size)
|
301
275
|
|
302
276
|
args.operations.each do |operation|
|
@@ -311,9 +285,6 @@ module Aerospike
|
|
311
285
|
begin_cmd
|
312
286
|
field_count = estimate_key_size(key, policy)
|
313
287
|
|
314
|
-
predexp_size = estimate_predexp(policy.predexp)
|
315
|
-
field_count += 1 if predexp_size > 0
|
316
|
-
|
317
288
|
exp_size = estimate_expression_size(@policy.filter_exp)
|
318
289
|
field_count += 1 if exp_size > 0
|
319
290
|
|
@@ -324,7 +295,6 @@ module Aerospike
|
|
324
295
|
|
325
296
|
write_header_write(policy, INFO2_WRITE, field_count, 0)
|
326
297
|
write_key(key, policy)
|
327
|
-
write_predexp(policy.predexp, predexp_size)
|
328
298
|
write_filter_exp(@policy.filter_exp, exp_size)
|
329
299
|
write_field_string(package_name, Aerospike::FieldType::UDF_PACKAGE_NAME)
|
330
300
|
write_field_string(function_name, Aerospike::FieldType::UDF_FUNCTION)
|
@@ -373,9 +343,6 @@ module Aerospike
|
|
373
343
|
field_count += 1
|
374
344
|
end
|
375
345
|
|
376
|
-
predexp_size = estimate_predexp(policy.predexp)
|
377
|
-
field_count += 1 if predexp_size > 0
|
378
|
-
|
379
346
|
exp_size = estimate_expression_size(@policy.filter_exp)
|
380
347
|
field_count += 1 if exp_size > 0
|
381
348
|
|
@@ -446,7 +413,6 @@ module Aerospike
|
|
446
413
|
write_field_int(policy.records_per_second, Aerospike::FieldType::RECORDS_PER_SECOND)
|
447
414
|
end
|
448
415
|
|
449
|
-
write_predexp(policy.predexp, predexp_size)
|
450
416
|
write_filter_exp(@policy.filter_exp, exp_size)
|
451
417
|
|
452
418
|
# write_field_header(2, Aerospike::FieldType::SCAN_OPTIONS)
|
@@ -475,7 +441,6 @@ module Aerospike
|
|
475
441
|
end_cmd
|
476
442
|
end
|
477
443
|
|
478
|
-
|
479
444
|
def set_query(cluster, policy, statement, background, node_partitions)
|
480
445
|
function_arg_buffer = nil
|
481
446
|
field_count = 0
|
@@ -525,7 +490,7 @@ module Aerospike
|
|
525
490
|
|
526
491
|
# Estimate INDEX_RANGE field.
|
527
492
|
@data_offset += FIELD_HEADER_SIZE
|
528
|
-
filter_size += 1
|
493
|
+
filter_size += 1 # num filters
|
529
494
|
filter_size += filter.estimate_size
|
530
495
|
|
531
496
|
@data_offset += filter_size
|
@@ -539,14 +504,6 @@ module Aerospike
|
|
539
504
|
end
|
540
505
|
|
541
506
|
statement.set_task_id
|
542
|
-
predexp = policy.predexp || statement.predexp
|
543
|
-
|
544
|
-
if predexp
|
545
|
-
@data_offset += FIELD_HEADER_SIZE
|
546
|
-
pred_size = Aerospike::PredExp.estimate_size(predexp)
|
547
|
-
@data_offset += pred_size
|
548
|
-
field_count += 1
|
549
|
-
end
|
550
507
|
|
551
508
|
unless policy.filter_exp.nil?
|
552
509
|
exp_size = estimate_expression_size(policy.filter_exp)
|
@@ -656,13 +613,6 @@ module Aerospike
|
|
656
613
|
# Write task_id field
|
657
614
|
write_field_int64(statement.task_id, FieldType::TRAN_ID)
|
658
615
|
|
659
|
-
unless predexp.nil?
|
660
|
-
write_field_header(pred_size, Aerospike::FieldType::PREDEXP)
|
661
|
-
@data_offset = Aerospike::PredExp.write(
|
662
|
-
predexp, @data_buffer, @data_offset
|
663
|
-
)
|
664
|
-
end
|
665
|
-
|
666
616
|
if filter
|
667
617
|
type = filter.collection_type
|
668
618
|
|
@@ -683,7 +633,8 @@ module Aerospike
|
|
683
633
|
|
684
634
|
if statement.function_name
|
685
635
|
write_field_header(1, FieldType::UDF_OP)
|
686
|
-
|
636
|
+
ret_marker = statement.return_data ? 1 : 2
|
637
|
+
@data_offset += @data_buffer.write_byte(ret_marker, @data_offset)
|
687
638
|
write_field_string(statement.package_name, FieldType::UDF_PACKAGE_NAME)
|
688
639
|
write_field_string(statement.function_name, FieldType::UDF_FUNCTION)
|
689
640
|
write_field_string(function_arg_buffer, FieldType::UDF_ARGLIST)
|
@@ -725,7 +676,6 @@ module Aerospike
|
|
725
676
|
end_cmd
|
726
677
|
end
|
727
678
|
|
728
|
-
|
729
679
|
def execute
|
730
680
|
iterations = 0
|
731
681
|
|
@@ -752,7 +702,7 @@ module Aerospike
|
|
752
702
|
# Socket connection error has occurred. Decrease health and retry.
|
753
703
|
@node.decrease_health
|
754
704
|
|
755
|
-
Aerospike.logger.error("Node #{@node
|
705
|
+
Aerospike.logger.error("Node #{@node}: #{e}")
|
756
706
|
else
|
757
707
|
Aerospike.logger.error("No node available for transaction: #{e}")
|
758
708
|
end
|
@@ -785,7 +735,7 @@ module Aerospike
|
|
785
735
|
# Close socket to flush out possible garbage. Do not put back in pool.
|
786
736
|
@conn.close if @conn
|
787
737
|
|
788
|
-
Aerospike.logger.error("Node #{@node
|
738
|
+
Aerospike.logger.error("Node #{@node}: #{e}")
|
789
739
|
# IO error means connection to server @node is unhealthy.
|
790
740
|
# Reflect cmd status.
|
791
741
|
@node.decrease_health
|
@@ -853,14 +803,14 @@ module Aerospike
|
|
853
803
|
field_count += 1
|
854
804
|
end
|
855
805
|
|
856
|
-
|
806
|
+
field_count
|
857
807
|
end
|
858
808
|
|
859
809
|
def estimate_udf_size(package_name, function_name, bytes)
|
860
810
|
@data_offset += package_name.bytesize + FIELD_HEADER_SIZE
|
861
811
|
@data_offset += function_name.bytesize + FIELD_HEADER_SIZE
|
862
812
|
@data_offset += bytes.bytesize + FIELD_HEADER_SIZE
|
863
|
-
|
813
|
+
3
|
864
814
|
end
|
865
815
|
|
866
816
|
def estimate_operation_size_for_bin(bin)
|
@@ -890,16 +840,6 @@ module Aerospike
|
|
890
840
|
@data_offset += OPERATION_HEADER_SIZE
|
891
841
|
end
|
892
842
|
|
893
|
-
def estimate_predexp(predexp)
|
894
|
-
if predexp && !predexp.empty?
|
895
|
-
@data_offset += FIELD_HEADER_SIZE
|
896
|
-
sz = Aerospike::PredExp.estimate_size(predexp)
|
897
|
-
@data_offset += sz
|
898
|
-
return sz
|
899
|
-
end
|
900
|
-
return 0
|
901
|
-
end
|
902
|
-
|
903
843
|
def estimate_expression_size(exp)
|
904
844
|
unless exp.nil?
|
905
845
|
@data_offset += FIELD_HEADER_SIZE
|
@@ -1025,7 +965,7 @@ module Aerospike
|
|
1025
965
|
@data_buffer.write_byte(0, 10)
|
1026
966
|
@data_buffer.write_byte(info_attr, 11)
|
1027
967
|
|
1028
|
-
(12...22).each { |i| @data_buffer.write_byte(
|
968
|
+
(12...22).each { |i| @data_buffer.write_byte(0, i) }
|
1029
969
|
|
1030
970
|
# Initialize timeout. It will be written later.
|
1031
971
|
@data_buffer.write_byte(0, 22)
|
@@ -1048,7 +988,7 @@ module Aerospike
|
|
1048
988
|
@data_buffer.write_byte(0, 10)
|
1049
989
|
@data_buffer.write_byte(info_attr, 11)
|
1050
990
|
|
1051
|
-
(12...22).each { |i| @data_buffer.write_byte(
|
991
|
+
(12...22).each { |i| @data_buffer.write_byte(0, i) }
|
1052
992
|
|
1053
993
|
# Initialize timeout. It will be written later.
|
1054
994
|
@data_buffer.write_byte(0, 22)
|
@@ -1062,6 +1002,89 @@ module Aerospike
|
|
1062
1002
|
@data_offset = MSG_TOTAL_HEADER_SIZE
|
1063
1003
|
end
|
1064
1004
|
|
1005
|
+
def write_batch_operations(key, ops, attr, filter_exp)
|
1006
|
+
if attr.has_write
|
1007
|
+
write_batch_write(key, attr, filter_exp, 0, ops.length)
|
1008
|
+
else
|
1009
|
+
write_batch_read(key, attr, filter_exp, ops.length)
|
1010
|
+
end
|
1011
|
+
|
1012
|
+
ops.each do |op|
|
1013
|
+
write_operation_for_operation(op)
|
1014
|
+
end
|
1015
|
+
end
|
1016
|
+
|
1017
|
+
def write_batch_fields(key, field_count, op_count)
|
1018
|
+
field_count+=2
|
1019
|
+
@data_offset += @data_buffer.write_uint16(field_count, @data_offset)
|
1020
|
+
@data_offset += @data_buffer.write_uint16(op_count, @data_offset)
|
1021
|
+
write_field_string(key.namespace, Aerospike::FieldType::NAMESPACE)
|
1022
|
+
write_field_string(key.set_name, Aerospike::FieldType::TABLE)
|
1023
|
+
end
|
1024
|
+
|
1025
|
+
def write_batch_fields_with_filter(key, filter_exp, field_count, op_count)
|
1026
|
+
if filter_exp
|
1027
|
+
field_count+=1
|
1028
|
+
write_batch_fields(key, field_count, op_count)
|
1029
|
+
write_filter_exp(filter_exp, filter_exp.size)
|
1030
|
+
else
|
1031
|
+
write_batch_fields(key, field_count, op_count)
|
1032
|
+
end
|
1033
|
+
end
|
1034
|
+
|
1035
|
+
def write_batch_read(key, attr, filter_exp, op_count)
|
1036
|
+
@data_offset += @data_buffer.write_byte(BATCH_MSG_INFO | BATCH_MSG_TTL, @data_offset)
|
1037
|
+
@data_offset += @data_buffer.write_byte(attr.read_attr, @data_offset)
|
1038
|
+
@data_offset += @data_buffer.write_byte(attr.write_attr, @data_offset)
|
1039
|
+
@data_offset += @data_buffer.write_byte(attr.info_attr, @data_offset)
|
1040
|
+
@data_offset += @data_buffer.write_uint32(attr.expiration, @data_offset)
|
1041
|
+
write_batch_fields_with_filter(key, filter_exp, 0, op_count)
|
1042
|
+
end
|
1043
|
+
|
1044
|
+
def write_batch_write(key, attr, filter_exp, field_count, op_count)
|
1045
|
+
@data_offset += @data_buffer.write_byte(BATCH_MSG_INFO | BATCH_MSG_GEN | BATCH_MSG_TTL, @data_offset)
|
1046
|
+
@data_offset += @data_buffer.write_byte(attr.read_attr, @data_offset)
|
1047
|
+
@data_offset += @data_buffer.write_byte(attr.write_attr, @data_offset)
|
1048
|
+
@data_offset += @data_buffer.write_byte(attr.info_attr, @data_offset)
|
1049
|
+
@data_offset += @data_buffer.write_uint16(attr.generation, @data_offset)
|
1050
|
+
@data_offset += @data_buffer.write_uint32(attr.expiration, @data_offset)
|
1051
|
+
if attr.send_key
|
1052
|
+
field_count+=1
|
1053
|
+
write_batch_fields_with_filter(key, filter_exp, field_count, op_count)
|
1054
|
+
write_field_value(key.user_key, KEY)
|
1055
|
+
else
|
1056
|
+
write_batch_fields_with_filter(key, filter_exp, field_count, op_count)
|
1057
|
+
end
|
1058
|
+
end
|
1059
|
+
|
1060
|
+
def write_batch_bin_names(key, bin_names, attr, filter_exp)
|
1061
|
+
write_batch_read(key, attr, filter_exp, bin_names.length)
|
1062
|
+
bin_names.each do |bin_name|
|
1063
|
+
write_operation_for_bin_name(bin_name, Aerospike::Operation::READ)
|
1064
|
+
end
|
1065
|
+
end
|
1066
|
+
|
1067
|
+
def write_batch_header(policy, field_count)
|
1068
|
+
read_attr = INFO1_BATCH
|
1069
|
+
read_attr |= INFO1_COMPRESS_RESPONSE if policy.use_compression
|
1070
|
+
#TODO: Add SC Mode
|
1071
|
+
|
1072
|
+
@data_buffer.write_byte(MSG_REMAINING_HEADER_SIZE, 8) # Message header.length, @data_offset.
|
1073
|
+
@data_buffer.write_byte(read_attr, 9)
|
1074
|
+
@data_buffer.write_byte(0, 10)
|
1075
|
+
@data_buffer.write_byte(0, 11)
|
1076
|
+
|
1077
|
+
(12...22).each { |i| @data_buffer.write_byte(0, i) }
|
1078
|
+
|
1079
|
+
# Initialize timeout. It will be written later.
|
1080
|
+
@data_buffer.write_uint32(0, 22)
|
1081
|
+
|
1082
|
+
@data_buffer.write_uint16(field_count, 26)
|
1083
|
+
@data_buffer.write_uint16(0, 28)
|
1084
|
+
|
1085
|
+
@data_offset = MSG_TOTAL_HEADER_SIZE
|
1086
|
+
end
|
1087
|
+
|
1065
1088
|
def write_key(key, policy = nil)
|
1066
1089
|
# Write key into buffer.
|
1067
1090
|
if key.namespace
|
@@ -1199,15 +1222,6 @@ module Aerospike
|
|
1199
1222
|
@data_offset += 1
|
1200
1223
|
end
|
1201
1224
|
|
1202
|
-
def write_predexp(predexp, predexp_size)
|
1203
|
-
if predexp && !predexp.empty?
|
1204
|
-
write_field_header(predexp_size, Aerospike::FieldType::FILTER_EXP)
|
1205
|
-
@data_offset = Aerospike::PredExp.write(
|
1206
|
-
predexp, @data_buffer, @data_offset
|
1207
|
-
)
|
1208
|
-
end
|
1209
|
-
end
|
1210
|
-
|
1211
1225
|
def write_filter_exp(exp, exp_size)
|
1212
1226
|
unless exp.nil?
|
1213
1227
|
write_field_header(exp_size, Aerospike::FieldType::FILTER_EXP)
|
@@ -1238,7 +1252,7 @@ module Aerospike
|
|
1238
1252
|
|
1239
1253
|
def compress_buffer
|
1240
1254
|
if @data_offset > COMPRESS_THRESHOLD
|
1241
|
-
compressed = Zlib
|
1255
|
+
compressed = Zlib.deflate(@data_buffer.buf, Zlib::DEFAULT_COMPRESSION)
|
1242
1256
|
|
1243
1257
|
# write original size as header
|
1244
1258
|
proto_s = format("%08d", 0)
|