aerospike 2.24.0 → 2.26.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 +27 -0
- data/lib/aerospike/cdt/context.rb +136 -69
- data/lib/aerospike/cdt/map_policy.rb +16 -2
- data/lib/aerospike/cdt/map_return_type.rb +9 -1
- data/lib/aerospike/client.rb +30 -32
- data/lib/aerospike/command/command.rb +104 -98
- data/lib/aerospike/command/operate_args.rb +99 -0
- data/lib/aerospike/command/operate_command.rb +6 -11
- data/lib/aerospike/exp/exp.rb +401 -334
- data/lib/aerospike/exp/exp_bit.rb +388 -0
- data/lib/aerospike/exp/exp_hll.rb +169 -0
- data/lib/aerospike/exp/exp_list.rb +403 -0
- data/lib/aerospike/exp/exp_map.rb +493 -0
- data/lib/aerospike/exp/operation.rb +56 -0
- data/lib/aerospike/features.rb +13 -0
- data/lib/aerospike/operation.rb +20 -22
- data/lib/aerospike/policy/policy.rb +25 -12
- data/lib/aerospike/query/filter.rb +44 -32
- data/lib/aerospike/query/query_executor.rb +7 -9
- data/lib/aerospike/query/query_partition_command.rb +32 -31
- data/lib/aerospike/query/recordset.rb +9 -9
- data/lib/aerospike/query/scan_executor.rb +7 -5
- data/lib/aerospike/task/execute_task.rb +17 -14
- data/lib/aerospike/utils/buffer.rb +46 -38
- data/lib/aerospike/utils/packer.rb +7 -6
- data/lib/aerospike/value/value.rb +21 -51
- data/lib/aerospike/version.rb +1 -1
- data/lib/aerospike.rb +156 -148
- metadata +8 -2
@@ -15,18 +15,17 @@
|
|
15
15
|
# License for the specific language governing permissions and limitations under
|
16
16
|
# the License.
|
17
17
|
|
18
|
-
require
|
19
|
-
require
|
18
|
+
require "time"
|
19
|
+
require "zlib"
|
20
20
|
|
21
|
-
require
|
22
|
-
require
|
23
|
-
require
|
21
|
+
require "msgpack"
|
22
|
+
require "aerospike/result_code"
|
23
|
+
require "aerospike/command/field_type"
|
24
24
|
|
25
|
-
require
|
26
|
-
require
|
25
|
+
require "aerospike/policy/consistency_level"
|
26
|
+
require "aerospike/policy/commit_level"
|
27
27
|
|
28
28
|
module Aerospike
|
29
|
-
|
30
29
|
private
|
31
30
|
|
32
31
|
# Flags commented out are not supported by cmd client.
|
@@ -34,9 +33,8 @@ module Aerospike
|
|
34
33
|
INFO1_READ = Integer(1 << 0)
|
35
34
|
# Get all bins.
|
36
35
|
INFO1_GET_ALL = Integer(1 << 1)
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
# Short query
|
37
|
+
INFO1_SHORT_QUERY = Integer(1 << 2)
|
40
38
|
|
41
39
|
INFO1_BATCH = Integer(1 << 3)
|
42
40
|
# Do not read the bins
|
@@ -78,19 +76,18 @@ module Aerospike
|
|
78
76
|
# Completely replace existing record only.
|
79
77
|
INFO3_REPLACE_ONLY = Integer(1 << 5)
|
80
78
|
|
81
|
-
MSG_TOTAL_HEADER_SIZE
|
82
|
-
FIELD_HEADER_SIZE
|
83
|
-
OPERATION_HEADER_SIZE
|
84
|
-
MSG_REMAINING_HEADER_SIZE
|
85
|
-
DIGEST_SIZE
|
86
|
-
COMPRESS_THRESHOLD
|
87
|
-
CL_MSG_VERSION
|
88
|
-
AS_MSG_TYPE
|
89
|
-
AS_MSG_TYPE_COMPRESSED
|
79
|
+
MSG_TOTAL_HEADER_SIZE = 30
|
80
|
+
FIELD_HEADER_SIZE = 5
|
81
|
+
OPERATION_HEADER_SIZE = 8
|
82
|
+
MSG_REMAINING_HEADER_SIZE = 22
|
83
|
+
DIGEST_SIZE = 20
|
84
|
+
COMPRESS_THRESHOLD = 128
|
85
|
+
CL_MSG_VERSION = 2
|
86
|
+
AS_MSG_TYPE = 3
|
87
|
+
AS_MSG_TYPE_COMPRESSED = 4
|
90
88
|
|
91
89
|
class Command #:nodoc:
|
92
|
-
|
93
|
-
def initialize(node=nil)
|
90
|
+
def initialize(node = nil)
|
94
91
|
@data_offset = 0
|
95
92
|
@data_buffer = nil
|
96
93
|
|
@@ -118,6 +115,9 @@ module Aerospike
|
|
118
115
|
predexp_size = estimate_predexp(policy.predexp)
|
119
116
|
field_count += 1 if predexp_size > 0
|
120
117
|
|
118
|
+
exp_size = estimate_expression_size(@policy.filter_exp)
|
119
|
+
field_count += 1 if exp_size > 0
|
120
|
+
|
121
121
|
bins.each do |bin|
|
122
122
|
estimate_operation_size_for_bin(bin)
|
123
123
|
end
|
@@ -127,6 +127,7 @@ module Aerospike
|
|
127
127
|
write_header_with_policy(policy, 0, INFO2_WRITE, field_count, bins.length)
|
128
128
|
write_key(key, policy)
|
129
129
|
write_predexp(policy.predexp, predexp_size)
|
130
|
+
write_filter_exp(@policy.filter_exp, exp_size)
|
130
131
|
|
131
132
|
bins.each do |bin|
|
132
133
|
write_operation_for_bin(bin, operation)
|
@@ -144,10 +145,14 @@ module Aerospike
|
|
144
145
|
predexp_size = estimate_predexp(policy.predexp)
|
145
146
|
field_count += 1 if predexp_size > 0
|
146
147
|
|
148
|
+
exp_size = estimate_expression_size(@policy.filter_exp)
|
149
|
+
field_count += 1 if exp_size > 0
|
150
|
+
|
147
151
|
size_buffer
|
148
|
-
write_header_with_policy(policy, 0, INFO2_WRITE|INFO2_DELETE, field_count, 0)
|
152
|
+
write_header_with_policy(policy, 0, INFO2_WRITE | INFO2_DELETE, field_count, 0)
|
149
153
|
write_key(key)
|
150
154
|
write_predexp(policy.predexp, predexp_size)
|
155
|
+
write_filter_exp(@policy.filter_exp, exp_size)
|
151
156
|
end_cmd
|
152
157
|
end
|
153
158
|
|
@@ -159,11 +164,15 @@ module Aerospike
|
|
159
164
|
predexp_size = estimate_predexp(policy.predexp)
|
160
165
|
field_count += 1 if predexp_size > 0
|
161
166
|
|
167
|
+
exp_size = estimate_expression_size(@policy.filter_exp)
|
168
|
+
field_count += 1 if exp_size > 0
|
169
|
+
|
162
170
|
estimate_operation_size
|
163
171
|
size_buffer
|
164
172
|
write_header_with_policy(policy, 0, INFO2_WRITE, field_count, 1)
|
165
173
|
write_key(key)
|
166
174
|
write_predexp(policy.predexp, predexp_size)
|
175
|
+
write_filter_exp(@policy.filter_exp, exp_size)
|
167
176
|
write_operation_for_operation_type(Aerospike::Operation::TOUCH)
|
168
177
|
end_cmd
|
169
178
|
end
|
@@ -176,10 +185,14 @@ module Aerospike
|
|
176
185
|
predexp_size = estimate_predexp(policy.predexp)
|
177
186
|
field_count += 1 if predexp_size > 0
|
178
187
|
|
188
|
+
exp_size = estimate_expression_size(@policy.filter_exp)
|
189
|
+
field_count += 1 if exp_size > 0
|
190
|
+
|
179
191
|
size_buffer
|
180
|
-
write_header(policy, INFO1_READ|INFO1_NOBINDATA, 0, field_count, 0)
|
192
|
+
write_header(policy, INFO1_READ | INFO1_NOBINDATA, 0, field_count, 0)
|
181
193
|
write_key(key)
|
182
194
|
write_predexp(policy.predexp, predexp_size)
|
195
|
+
write_filter_exp(@policy.filter_exp, exp_size)
|
183
196
|
end_cmd
|
184
197
|
end
|
185
198
|
|
@@ -191,10 +204,14 @@ module Aerospike
|
|
191
204
|
predexp_size = estimate_predexp(policy.predexp)
|
192
205
|
field_count += 1 if predexp_size > 0
|
193
206
|
|
207
|
+
exp_size = estimate_expression_size(@policy.filter_exp)
|
208
|
+
field_count += 1 if exp_size > 0
|
209
|
+
|
194
210
|
size_buffer
|
195
|
-
write_header(policy, INFO1_READ|INFO1_GET_ALL, 0, field_count, 0)
|
211
|
+
write_header(policy, INFO1_READ | INFO1_GET_ALL, 0, field_count, 0)
|
196
212
|
write_key(key)
|
197
213
|
write_predexp(policy.predexp, predexp_size)
|
214
|
+
write_filter_exp(@policy.filter_exp, exp_size)
|
198
215
|
end_cmd
|
199
216
|
end
|
200
217
|
|
@@ -207,6 +224,8 @@ module Aerospike
|
|
207
224
|
predexp_size = estimate_predexp(policy.predexp)
|
208
225
|
field_count += 1 if predexp_size > 0
|
209
226
|
|
227
|
+
exp_size = estimate_expression_size(@policy.filter_exp)
|
228
|
+
field_count += 1 if exp_size > 0
|
210
229
|
|
211
230
|
bin_names.each do |bin_name|
|
212
231
|
estimate_operation_size_for_bin_name(bin_name)
|
@@ -216,6 +235,7 @@ module Aerospike
|
|
216
235
|
write_header(policy, INFO1_READ, 0, field_count, bin_names.length)
|
217
236
|
write_key(key)
|
218
237
|
write_predexp(policy.predexp, predexp_size)
|
238
|
+
write_filter_exp(@policy.filter_exp, exp_size)
|
219
239
|
|
220
240
|
bin_names.each do |bin_name|
|
221
241
|
write_operation_for_bin_name(bin_name, Aerospike::Operation::READ)
|
@@ -235,7 +255,10 @@ module Aerospike
|
|
235
255
|
predexp_size = estimate_predexp(policy.predexp)
|
236
256
|
field_count += 1 if predexp_size > 0
|
237
257
|
|
238
|
-
|
258
|
+
exp_size = estimate_expression_size(@policy.filter_exp)
|
259
|
+
field_count += 1 if exp_size > 0
|
260
|
+
|
261
|
+
estimate_operation_size_for_bin_name("")
|
239
262
|
size_buffer
|
240
263
|
|
241
264
|
# The server does not currently return record header data with _INFO1_NOBINDATA attribute set.
|
@@ -246,70 +269,35 @@ module Aerospike
|
|
246
269
|
|
247
270
|
write_key(key)
|
248
271
|
write_predexp(policy.predexp, predexp_size)
|
249
|
-
|
272
|
+
write_filter_exp(@policy.filter_exp, exp_size)
|
273
|
+
write_operation_for_bin_name("", Aerospike::Operation::READ)
|
250
274
|
end_cmd
|
251
275
|
end
|
252
276
|
|
253
277
|
# Implements different command operations
|
254
|
-
def set_operate(policy, key,
|
278
|
+
def set_operate(policy, key, args)
|
255
279
|
begin_cmd
|
256
280
|
field_count = estimate_key_size(key, policy)
|
257
281
|
|
258
282
|
predexp_size = estimate_predexp(policy.predexp)
|
259
283
|
field_count += 1 if predexp_size > 0
|
260
284
|
|
261
|
-
|
262
|
-
|
263
|
-
read_header = false
|
264
|
-
record_bin_multiplicity = policy.record_bin_multiplicity == RecordBinMultiplicity::ARRAY
|
265
|
-
|
266
|
-
operations.each do |operation|
|
267
|
-
case operation.op_type
|
268
|
-
when Aerospike::Operation::READ, Aerospike::Operation::CDT_READ,
|
269
|
-
Aerospike::Operation::HLL_READ, Aerospike::Operation::BIT_READ
|
270
|
-
read_attr |= INFO1_READ
|
271
|
-
|
272
|
-
# Read all bins if no bin is specified.
|
273
|
-
read_attr |= INFO1_GET_ALL unless operation.bin_name
|
274
|
-
|
275
|
-
when Aerospike::Operation::READ_HEADER
|
276
|
-
# The server does not currently return record header data with _INFO1_NOBINDATA attribute set.
|
277
|
-
# The workaround is to request a non-existent bin.
|
278
|
-
# TODO: Fix this on server.
|
279
|
-
# read_attr |= _INFO1_READ | _INFO1_NOBINDATA
|
280
|
-
read_attr |= INFO1_READ
|
281
|
-
read_header = true
|
282
|
-
|
283
|
-
else
|
284
|
-
write_attr = INFO2_WRITE
|
285
|
-
end
|
285
|
+
exp_size = estimate_expression_size(policy.filter_exp)
|
286
|
+
field_count += 1 if exp_size > 0
|
286
287
|
|
287
|
-
|
288
|
-
Aerospike::Operation::BIT_MODIFY, Aerospike::Operation::BIT_READ].include?(operation.op_type)
|
289
|
-
record_bin_multiplicity = true
|
290
|
-
end
|
288
|
+
@data_offset += args.size
|
291
289
|
|
292
|
-
estimate_operation_size_for_operation(operation)
|
293
|
-
end
|
294
290
|
size_buffer
|
295
291
|
|
296
|
-
|
297
|
-
write_attr |= INFO2_RESPOND_ALL_OPS if write_attr != 0 && record_bin_multiplicity
|
298
|
-
|
299
|
-
if write_attr == 0
|
300
|
-
write_header(policy, read_attr, write_attr, field_count, operations.length)
|
301
|
-
else
|
302
|
-
write_header_with_policy(policy, read_attr, write_attr, field_count, operations.length)
|
303
|
-
end
|
292
|
+
write_header_with_policy(policy, args.read_attr, args.write_attr, field_count, args.operations.length)
|
304
293
|
write_key(key, policy)
|
305
294
|
write_predexp(policy.predexp, predexp_size)
|
295
|
+
write_filter_exp(policy.filter_exp, exp_size)
|
306
296
|
|
307
|
-
operations.each do |operation|
|
297
|
+
args.operations.each do |operation|
|
308
298
|
write_operation_for_operation(operation)
|
309
299
|
end
|
310
300
|
|
311
|
-
write_operation_for_bin(nil, Aerospike::Operation::READ) if read_header
|
312
|
-
|
313
301
|
end_cmd
|
314
302
|
mark_compressed(policy)
|
315
303
|
end
|
@@ -321,6 +309,9 @@ module Aerospike
|
|
321
309
|
predexp_size = estimate_predexp(policy.predexp)
|
322
310
|
field_count += 1 if predexp_size > 0
|
323
311
|
|
312
|
+
exp_size = estimate_expression_size(@policy.filter_exp)
|
313
|
+
field_count += 1 if exp_size > 0
|
314
|
+
|
324
315
|
arg_bytes = args.to_bytes
|
325
316
|
|
326
317
|
field_count += estimate_udf_size(package_name, function_name, arg_bytes)
|
@@ -329,6 +320,7 @@ module Aerospike
|
|
329
320
|
write_header(policy, 0, INFO2_WRITE, field_count, 0)
|
330
321
|
write_key(key, policy)
|
331
322
|
write_predexp(policy.predexp, predexp_size)
|
323
|
+
write_filter_exp(@policy.filter_exp, exp_size)
|
332
324
|
write_field_string(package_name, Aerospike::FieldType::UDF_PACKAGE_NAME)
|
333
325
|
write_field_string(function_name, Aerospike::FieldType::UDF_FUNCTION)
|
334
326
|
write_field_bytes(arg_bytes, Aerospike::FieldType::UDF_ARGLIST)
|
@@ -379,6 +371,9 @@ module Aerospike
|
|
379
371
|
predexp_size = estimate_predexp(policy.predexp)
|
380
372
|
field_count += 1 if predexp_size > 0
|
381
373
|
|
374
|
+
exp_size = estimate_expression_size(@policy.filter_exp)
|
375
|
+
field_count += 1 if exp_size > 0
|
376
|
+
|
382
377
|
# Estimate scan options size.
|
383
378
|
# @data_offset += 2 + FIELD_HEADER_SIZE
|
384
379
|
# field_count += 1
|
@@ -420,7 +415,7 @@ module Aerospike
|
|
420
415
|
|
421
416
|
node_partitions.parts_full.each do |part|
|
422
417
|
@data_buffer.write_uint16_little_endian(part.id, @data_offset)
|
423
|
-
@data_offset+=2
|
418
|
+
@data_offset += 2
|
424
419
|
end
|
425
420
|
end
|
426
421
|
|
@@ -429,7 +424,7 @@ module Aerospike
|
|
429
424
|
|
430
425
|
node_partitions.parts_partial.each do |part|
|
431
426
|
@data_buffer.write_binary(part.digest, @data_offset)
|
432
|
-
@data_offset+=part.digest.length
|
427
|
+
@data_offset += part.digest.length
|
433
428
|
end
|
434
429
|
end
|
435
430
|
|
@@ -442,6 +437,7 @@ module Aerospike
|
|
442
437
|
end
|
443
438
|
|
444
439
|
write_predexp(policy.predexp, predexp_size)
|
440
|
+
write_filter_exp(@policy.filter_exp, exp_size)
|
445
441
|
|
446
442
|
# write_field_header(2, Aerospike::FieldType::SCAN_OPTIONS)
|
447
443
|
|
@@ -479,7 +475,7 @@ module Aerospike
|
|
479
475
|
while true
|
480
476
|
# too many retries
|
481
477
|
iterations += 1
|
482
|
-
break if (@policy.max_retries > 0) && (iterations > @policy.max_retries+1)
|
478
|
+
break if (@policy.max_retries > 0) && (iterations > @policy.max_retries + 1)
|
483
479
|
|
484
480
|
# Sleep before trying again, after the first iteration
|
485
481
|
sleep(@policy.sleep_between_retries) if iterations > 1 && @policy.sleep_between_retries > 0
|
@@ -567,7 +563,6 @@ module Aerospike
|
|
567
563
|
ensure
|
568
564
|
Buffer.put(@data_buffer)
|
569
565
|
end
|
570
|
-
|
571
566
|
end # while
|
572
567
|
|
573
568
|
# execution timeout
|
@@ -576,7 +571,6 @@ module Aerospike
|
|
576
571
|
|
577
572
|
protected
|
578
573
|
|
579
|
-
|
580
574
|
def estimate_key_size(key, policy = nil)
|
581
575
|
field_count = 0
|
582
576
|
|
@@ -646,6 +640,15 @@ module Aerospike
|
|
646
640
|
return 0
|
647
641
|
end
|
648
642
|
|
643
|
+
def estimate_expression_size(exp)
|
644
|
+
unless exp.nil?
|
645
|
+
@data_offset += FIELD_HEADER_SIZE
|
646
|
+
@data_offset += exp.size
|
647
|
+
return exp.size
|
648
|
+
end
|
649
|
+
0
|
650
|
+
end
|
651
|
+
|
649
652
|
# Generic header write.
|
650
653
|
def write_header(policy, read_attr, write_attr, field_count, operation_count)
|
651
654
|
read_attr |= INFO1_CONSISTENCY_ALL if policy.consistency_level == Aerospike::ConsistencyLevel::CONSISTENCY_ALL
|
@@ -717,7 +720,6 @@ module Aerospike
|
|
717
720
|
@data_buffer.write_byte(0, 24)
|
718
721
|
@data_buffer.write_byte(0, 25)
|
719
722
|
|
720
|
-
|
721
723
|
@data_buffer.write_int16(field_count, 26)
|
722
724
|
@data_buffer.write_int16(operation_count, 28)
|
723
725
|
|
@@ -739,15 +741,14 @@ module Aerospike
|
|
739
741
|
if policy && policy.respond_to?(:send_key) && policy.send_key == true
|
740
742
|
write_field_value(key.user_key_as_value, Aerospike::FieldType::KEY)
|
741
743
|
end
|
742
|
-
|
743
744
|
end
|
744
745
|
|
745
746
|
def write_operation_for_bin(bin, operation)
|
746
|
-
name_length = @data_buffer.write_binary(bin.name, @data_offset+OPERATION_HEADER_SIZE)
|
747
|
-
value_length = bin.value_object.write(@data_buffer, @data_offset+OPERATION_HEADER_SIZE+name_length)
|
747
|
+
name_length = @data_buffer.write_binary(bin.name, @data_offset + OPERATION_HEADER_SIZE)
|
748
|
+
value_length = bin.value_object.write(@data_buffer, @data_offset + OPERATION_HEADER_SIZE + name_length)
|
748
749
|
|
749
750
|
# Buffer.Int32ToBytes(name_length+value_length+4, @data_buffer, @data_offset)
|
750
|
-
@data_buffer.write_int32(name_length+value_length+4, @data_offset)
|
751
|
+
@data_buffer.write_int32(name_length + value_length + 4, @data_offset)
|
751
752
|
|
752
753
|
@data_offset += 4
|
753
754
|
@data_buffer.write_byte(operation, @data_offset)
|
@@ -764,13 +765,13 @@ module Aerospike
|
|
764
765
|
def write_operation_for_operation(operation)
|
765
766
|
name_length = 0
|
766
767
|
if operation.bin_name
|
767
|
-
name_length = @data_buffer.write_binary(operation.bin_name, @data_offset+OPERATION_HEADER_SIZE)
|
768
|
+
name_length = @data_buffer.write_binary(operation.bin_name, @data_offset + OPERATION_HEADER_SIZE)
|
768
769
|
end
|
769
770
|
|
770
|
-
value_length = operation.bin_value.write(@data_buffer, @data_offset+OPERATION_HEADER_SIZE+name_length)
|
771
|
+
value_length = operation.bin_value.write(@data_buffer, @data_offset + OPERATION_HEADER_SIZE + name_length)
|
771
772
|
|
772
773
|
# Buffer.Int32ToBytes(name_length+value_length+4, @data_buffer, @data_offset)
|
773
|
-
@data_buffer.write_int32(name_length+value_length+4, @data_offset)
|
774
|
+
@data_buffer.write_int32(name_length + value_length + 4, @data_offset)
|
774
775
|
|
775
776
|
@data_offset += 4
|
776
777
|
@data_buffer.write_byte(operation.op_type, @data_offset)
|
@@ -785,9 +786,9 @@ module Aerospike
|
|
785
786
|
end
|
786
787
|
|
787
788
|
def write_operation_for_bin_name(name, operation)
|
788
|
-
name_length = @data_buffer.write_binary(name, @data_offset+OPERATION_HEADER_SIZE)
|
789
|
+
name_length = @data_buffer.write_binary(name, @data_offset + OPERATION_HEADER_SIZE)
|
789
790
|
# Buffer.Int32ToBytes(name_length+4, @data_buffer, @data_offset)
|
790
|
-
@data_buffer.write_int32(name_length+4, @data_offset)
|
791
|
+
@data_buffer.write_int32(name_length + 4, @data_offset)
|
791
792
|
|
792
793
|
@data_offset += 4
|
793
794
|
@data_buffer.write_byte(operation, @data_offset)
|
@@ -826,37 +827,37 @@ module Aerospike
|
|
826
827
|
end
|
827
828
|
|
828
829
|
def write_field_string(str, ftype)
|
829
|
-
len = @data_buffer.write_binary(str, @data_offset+FIELD_HEADER_SIZE)
|
830
|
+
len = @data_buffer.write_binary(str, @data_offset + FIELD_HEADER_SIZE)
|
830
831
|
write_field_header(len, ftype)
|
831
832
|
@data_offset += len
|
832
833
|
end
|
833
834
|
|
834
835
|
def write_u16_little_endian(i, ftype)
|
835
|
-
@data_buffer.write_uint16_little_endian(i, @data_offset+FIELD_HEADER_SIZE)
|
836
|
+
@data_buffer.write_uint16_little_endian(i, @data_offset + FIELD_HEADER_SIZE)
|
836
837
|
write_field_header(2, ftype)
|
837
838
|
@data_offset += 2
|
838
839
|
end
|
839
840
|
|
840
841
|
def write_field_int(i, ftype)
|
841
|
-
@data_buffer.write_int32(i, @data_offset+FIELD_HEADER_SIZE)
|
842
|
+
@data_buffer.write_int32(i, @data_offset + FIELD_HEADER_SIZE)
|
842
843
|
write_field_header(4, ftype)
|
843
844
|
@data_offset += 4
|
844
845
|
end
|
845
846
|
|
846
847
|
def write_field_int64(i, ftype)
|
847
|
-
@data_buffer.write_int64(i, @data_offset+FIELD_HEADER_SIZE)
|
848
|
+
@data_buffer.write_int64(i, @data_offset + FIELD_HEADER_SIZE)
|
848
849
|
write_field_header(8, ftype)
|
849
850
|
@data_offset += 8
|
850
851
|
end
|
851
852
|
|
852
853
|
def write_field_bytes(bytes, ftype)
|
853
|
-
@data_buffer.write_binary(bytes, @data_offset+FIELD_HEADER_SIZE)
|
854
|
+
@data_buffer.write_binary(bytes, @data_offset + FIELD_HEADER_SIZE)
|
854
855
|
write_field_header(bytes.bytesize, ftype)
|
855
856
|
@data_offset += bytes.bytesize
|
856
857
|
end
|
857
858
|
|
858
859
|
def write_field_header(size, ftype)
|
859
|
-
@data_buffer.write_int32(size+1, @data_offset)
|
860
|
+
@data_buffer.write_int32(size + 1, @data_offset)
|
860
861
|
@data_offset += 4
|
861
862
|
@data_buffer.write_byte(ftype, @data_offset)
|
862
863
|
@data_offset += 1
|
@@ -864,13 +865,20 @@ module Aerospike
|
|
864
865
|
|
865
866
|
def write_predexp(predexp, predexp_size)
|
866
867
|
if predexp && predexp.size > 0
|
867
|
-
write_field_header(predexp_size, Aerospike::FieldType::
|
868
|
+
write_field_header(predexp_size, Aerospike::FieldType::FILTER_EXP)
|
868
869
|
@data_offset = Aerospike::PredExp.write(
|
869
870
|
predexp, @data_buffer, @data_offset
|
870
871
|
)
|
871
872
|
end
|
872
873
|
end
|
873
874
|
|
875
|
+
def write_filter_exp(exp, exp_size)
|
876
|
+
unless exp.nil?
|
877
|
+
write_field_header(exp_size, Aerospike::FieldType::FILTER_EXP)
|
878
|
+
@data_offset += exp.write(@data_buffer, @data_offset)
|
879
|
+
end
|
880
|
+
end
|
881
|
+
|
874
882
|
def begin_cmd
|
875
883
|
@data_offset = MSG_TOTAL_HEADER_SIZE
|
876
884
|
end
|
@@ -884,7 +892,7 @@ module Aerospike
|
|
884
892
|
end
|
885
893
|
|
886
894
|
def end_cmd
|
887
|
-
size = (@data_offset-8) | Integer(CL_MSG_VERSION << 56) | Integer(AS_MSG_TYPE << 48)
|
895
|
+
size = (@data_offset - 8) | Integer(CL_MSG_VERSION << 56) | Integer(AS_MSG_TYPE << 48)
|
888
896
|
@data_buffer.write_int64(size, 0)
|
889
897
|
end
|
890
898
|
|
@@ -898,13 +906,13 @@ module Aerospike
|
|
898
906
|
|
899
907
|
# write original size as header
|
900
908
|
proto_s = "%08d" % 0
|
901
|
-
proto_s[0, 8] = [@data_offset].pack(
|
909
|
+
proto_s[0, 8] = [@data_offset].pack("q>")
|
902
910
|
compressed.prepend(proto_s)
|
903
911
|
|
904
912
|
# write proto
|
905
|
-
proto = (compressed.size+8) | Integer(CL_MSG_VERSION << 56) | Integer(AS_MSG_TYPE << 48)
|
913
|
+
proto = (compressed.size + 8) | Integer(CL_MSG_VERSION << 56) | Integer(AS_MSG_TYPE << 48)
|
906
914
|
proto_s = "%08d" % 0
|
907
|
-
proto_s[0, 8] = [proto].pack(
|
915
|
+
proto_s[0, 8] = [proto].pack("q>")
|
908
916
|
compressed.prepend(proto_s)
|
909
917
|
|
910
918
|
@data_buffer = Buffer.new(-1, compressed)
|
@@ -929,7 +937,5 @@ module Aerospike
|
|
929
937
|
def mark_compressed(policy)
|
930
938
|
@compress = policy.use_compression
|
931
939
|
end
|
932
|
-
|
933
940
|
end # class
|
934
|
-
|
935
941
|
end # module
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright 2016-2020 Aerospike, Inc.
|
3
|
+
#
|
4
|
+
# Portions may be licensed to Aerospike, Inc. under one or more contributor
|
5
|
+
# license agreements.
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License") you may not
|
8
|
+
# use this file except in compliance with the License. You may obtain a copy of
|
9
|
+
# the License at http:#www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
13
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
14
|
+
# License for the specific language governing permissions and limitations under
|
15
|
+
# the License.
|
16
|
+
|
17
|
+
require "aerospike/operation"
|
18
|
+
|
19
|
+
module Aerospike
|
20
|
+
private
|
21
|
+
|
22
|
+
class OperateArgs
|
23
|
+
attr_reader :write_policy, :operations, :partition
|
24
|
+
attr_reader :size, :read_attr, :write_attr, :has_write
|
25
|
+
|
26
|
+
RESPOND_ALL_OPS_READ_CMDS = [Operation::BIT_READ, Operation::EXP_READ, Operation::HLL_READ, Operation::CDT_READ]
|
27
|
+
READ_CMDS = [Operation::BIT_READ, Operation::EXP_READ, Operation::HLL_READ, Operation::CDT_READ, Operation::CDT_READ, Operation::READ]
|
28
|
+
MODIFY_CMDS = [Operation::BIT_MODIFY, Operation::EXP_MODIFY, Operation::HLL_MODIFY, Operation::CDT_MODIFY]
|
29
|
+
|
30
|
+
def initialize(cluster, policy, write_default, read_default, key, operations)
|
31
|
+
@operations = operations
|
32
|
+
|
33
|
+
data_offset = 0
|
34
|
+
rattr = 0
|
35
|
+
wattr = 0
|
36
|
+
write = false
|
37
|
+
read_bin = false
|
38
|
+
read_header = false
|
39
|
+
respond_all_ops = false
|
40
|
+
|
41
|
+
@operations.each do |operation|
|
42
|
+
if READ_CMDS.include?(operation.op_type)
|
43
|
+
if RESPOND_ALL_OPS_READ_CMDS.include?(operation.op_type)
|
44
|
+
# Map @operations require respond_all_ops to be true.
|
45
|
+
respond_all_ops = true
|
46
|
+
end
|
47
|
+
|
48
|
+
rattr |= Aerospike::INFO1_READ
|
49
|
+
|
50
|
+
# Read all bins if no bin is specified.
|
51
|
+
rattr |= Aerospike::INFO1_GET_ALL if operation.bin_name.nil?
|
52
|
+
read_bin = true
|
53
|
+
elsif operation.op_type == Operation::READ_HEADER
|
54
|
+
rattr |= Aerospike::INFO1_READ
|
55
|
+
read_header = true
|
56
|
+
elsif MODIFY_CMDS.include?(operation.op_type)
|
57
|
+
# Map @operations require respond_all_ops to be true.
|
58
|
+
respond_all_ops = true
|
59
|
+
|
60
|
+
wattr = Aerospike::INFO2_WRITE
|
61
|
+
write = true
|
62
|
+
else
|
63
|
+
wattr = Aerospike::INFO2_WRITE
|
64
|
+
write = true
|
65
|
+
end
|
66
|
+
data_offset += operation.bin_name.bytesize + Aerospike::OPERATION_HEADER_SIZE unless operation.bin_name.nil?
|
67
|
+
data_offset += operation.bin_value.estimate_size
|
68
|
+
end
|
69
|
+
|
70
|
+
@size = data_offset
|
71
|
+
@has_write = write
|
72
|
+
|
73
|
+
if read_header && !read_bin
|
74
|
+
rattr |= Aerospike::INFO1_NOBINDATA
|
75
|
+
end
|
76
|
+
@read_attr = rattr
|
77
|
+
|
78
|
+
if policy.nil?
|
79
|
+
@write_policy = write ? write_default : read_default
|
80
|
+
else
|
81
|
+
@write_policy = policy
|
82
|
+
end
|
83
|
+
|
84
|
+
# When GET_ALL is specified, RESPOND_ALL_OPS must be disabled.
|
85
|
+
if (respond_all_ops && policy.record_bin_multiplicity) && (rattr & Aerospike::INFO1_GET_ALL) == 0
|
86
|
+
wattr |= Aerospike::INFO2_RESPOND_ALL_OPS
|
87
|
+
end
|
88
|
+
@write_attr = wattr
|
89
|
+
|
90
|
+
if write
|
91
|
+
# @partition = Partition.write(cluster, @write_policy, key)
|
92
|
+
@partition = Partition.new_by_key(key)
|
93
|
+
else
|
94
|
+
# @partition = Partition.read(cluster, @write_policy, key)
|
95
|
+
@partition = Partition.new_by_key(key)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -14,33 +14,28 @@
|
|
14
14
|
# License for the specific language governing permissions and limitations under
|
15
15
|
# the License.
|
16
16
|
|
17
|
-
require
|
17
|
+
require "aerospike/command/read_command"
|
18
18
|
|
19
19
|
module Aerospike
|
20
|
-
|
21
20
|
private
|
22
21
|
|
23
22
|
class OperateCommand < ReadCommand #:nodoc:
|
23
|
+
def initialize(cluster, key, args)
|
24
|
+
super(cluster, args.write_policy, key, nil)
|
24
25
|
|
25
|
-
|
26
|
-
super(cluster, policy, key, nil)
|
27
|
-
|
28
|
-
@operations = operations
|
26
|
+
@args = args
|
29
27
|
end
|
30
28
|
|
31
29
|
def get_node
|
32
30
|
@cluster.master_node(@partition)
|
33
31
|
end
|
34
32
|
|
35
|
-
|
36
33
|
def write_bins
|
37
|
-
@operations.select{|op| op.op_type == Aerospike::Operation::WRITE}.map(&:bin).compact
|
34
|
+
@operations.select { |op| op.op_type == Aerospike::Operation::WRITE }.map(&:bin).compact
|
38
35
|
end
|
39
36
|
|
40
37
|
def write_buffer
|
41
|
-
set_operate(@
|
38
|
+
set_operate(@args.write_policy, @key, @args)
|
42
39
|
end
|
43
|
-
|
44
40
|
end # class
|
45
|
-
|
46
41
|
end # module
|