aerospike 2.23.0 → 2.25.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 +321 -266
- data/lib/aerospike/cdt/map_policy.rb +16 -2
- data/lib/aerospike/cdt/map_return_type.rb +9 -1
- data/lib/aerospike/client.rb +52 -56
- data/lib/aerospike/command/command.rb +105 -97
- data/lib/aerospike/command/field_type.rb +25 -28
- data/lib/aerospike/command/operate_args.rb +99 -0
- data/lib/aerospike/command/operate_command.rb +6 -11
- data/lib/aerospike/exp/exp.rb +1329 -0
- 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/policy/query_policy.rb +35 -2
- data/lib/aerospike/policy/scan_policy.rb +0 -2
- data/lib/aerospike/query/query_command.rb +1 -1
- data/lib/aerospike/query/query_executor.rb +71 -0
- data/lib/aerospike/query/query_partition_command.rb +269 -0
- data/lib/aerospike/query/recordset.rb +9 -9
- data/lib/aerospike/query/scan_executor.rb +7 -5
- data/lib/aerospike/query/statement.rb +7 -0
- data/lib/aerospike/query/stream_command.rb +2 -1
- data/lib/aerospike/task/execute_task.rb +17 -14
- data/lib/aerospike/utils/buffer.rb +62 -35
- 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 -146
- metadata +12 -3
@@ -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,7 +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
|
-
|
36
|
+
# Short query
|
37
|
+
INFO1_SHORT_QUERY = Integer(1 << 2)
|
38
38
|
|
39
39
|
INFO1_BATCH = Integer(1 << 3)
|
40
40
|
# Do not read the bins
|
@@ -76,19 +76,18 @@ module Aerospike
|
|
76
76
|
# Completely replace existing record only.
|
77
77
|
INFO3_REPLACE_ONLY = Integer(1 << 5)
|
78
78
|
|
79
|
-
MSG_TOTAL_HEADER_SIZE
|
80
|
-
FIELD_HEADER_SIZE
|
81
|
-
OPERATION_HEADER_SIZE
|
82
|
-
MSG_REMAINING_HEADER_SIZE
|
83
|
-
DIGEST_SIZE
|
84
|
-
COMPRESS_THRESHOLD
|
85
|
-
CL_MSG_VERSION
|
86
|
-
AS_MSG_TYPE
|
87
|
-
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
|
88
88
|
|
89
89
|
class Command #:nodoc:
|
90
|
-
|
91
|
-
def initialize(node=nil)
|
90
|
+
def initialize(node = nil)
|
92
91
|
@data_offset = 0
|
93
92
|
@data_buffer = nil
|
94
93
|
|
@@ -116,6 +115,9 @@ module Aerospike
|
|
116
115
|
predexp_size = estimate_predexp(policy.predexp)
|
117
116
|
field_count += 1 if predexp_size > 0
|
118
117
|
|
118
|
+
exp_size = estimate_expression_size(@policy.filter_exp)
|
119
|
+
field_count += 1 if exp_size > 0
|
120
|
+
|
119
121
|
bins.each do |bin|
|
120
122
|
estimate_operation_size_for_bin(bin)
|
121
123
|
end
|
@@ -125,6 +127,7 @@ module Aerospike
|
|
125
127
|
write_header_with_policy(policy, 0, INFO2_WRITE, field_count, bins.length)
|
126
128
|
write_key(key, policy)
|
127
129
|
write_predexp(policy.predexp, predexp_size)
|
130
|
+
write_filter_exp(@policy.filter_exp, exp_size)
|
128
131
|
|
129
132
|
bins.each do |bin|
|
130
133
|
write_operation_for_bin(bin, operation)
|
@@ -142,10 +145,14 @@ module Aerospike
|
|
142
145
|
predexp_size = estimate_predexp(policy.predexp)
|
143
146
|
field_count += 1 if predexp_size > 0
|
144
147
|
|
148
|
+
exp_size = estimate_expression_size(@policy.filter_exp)
|
149
|
+
field_count += 1 if exp_size > 0
|
150
|
+
|
145
151
|
size_buffer
|
146
|
-
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)
|
147
153
|
write_key(key)
|
148
154
|
write_predexp(policy.predexp, predexp_size)
|
155
|
+
write_filter_exp(@policy.filter_exp, exp_size)
|
149
156
|
end_cmd
|
150
157
|
end
|
151
158
|
|
@@ -157,11 +164,15 @@ module Aerospike
|
|
157
164
|
predexp_size = estimate_predexp(policy.predexp)
|
158
165
|
field_count += 1 if predexp_size > 0
|
159
166
|
|
167
|
+
exp_size = estimate_expression_size(@policy.filter_exp)
|
168
|
+
field_count += 1 if exp_size > 0
|
169
|
+
|
160
170
|
estimate_operation_size
|
161
171
|
size_buffer
|
162
172
|
write_header_with_policy(policy, 0, INFO2_WRITE, field_count, 1)
|
163
173
|
write_key(key)
|
164
174
|
write_predexp(policy.predexp, predexp_size)
|
175
|
+
write_filter_exp(@policy.filter_exp, exp_size)
|
165
176
|
write_operation_for_operation_type(Aerospike::Operation::TOUCH)
|
166
177
|
end_cmd
|
167
178
|
end
|
@@ -174,10 +185,14 @@ module Aerospike
|
|
174
185
|
predexp_size = estimate_predexp(policy.predexp)
|
175
186
|
field_count += 1 if predexp_size > 0
|
176
187
|
|
188
|
+
exp_size = estimate_expression_size(@policy.filter_exp)
|
189
|
+
field_count += 1 if exp_size > 0
|
190
|
+
|
177
191
|
size_buffer
|
178
|
-
write_header(policy, INFO1_READ|INFO1_NOBINDATA, 0, field_count, 0)
|
192
|
+
write_header(policy, INFO1_READ | INFO1_NOBINDATA, 0, field_count, 0)
|
179
193
|
write_key(key)
|
180
194
|
write_predexp(policy.predexp, predexp_size)
|
195
|
+
write_filter_exp(@policy.filter_exp, exp_size)
|
181
196
|
end_cmd
|
182
197
|
end
|
183
198
|
|
@@ -189,10 +204,14 @@ module Aerospike
|
|
189
204
|
predexp_size = estimate_predexp(policy.predexp)
|
190
205
|
field_count += 1 if predexp_size > 0
|
191
206
|
|
207
|
+
exp_size = estimate_expression_size(@policy.filter_exp)
|
208
|
+
field_count += 1 if exp_size > 0
|
209
|
+
|
192
210
|
size_buffer
|
193
|
-
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)
|
194
212
|
write_key(key)
|
195
213
|
write_predexp(policy.predexp, predexp_size)
|
214
|
+
write_filter_exp(@policy.filter_exp, exp_size)
|
196
215
|
end_cmd
|
197
216
|
end
|
198
217
|
|
@@ -205,6 +224,8 @@ module Aerospike
|
|
205
224
|
predexp_size = estimate_predexp(policy.predexp)
|
206
225
|
field_count += 1 if predexp_size > 0
|
207
226
|
|
227
|
+
exp_size = estimate_expression_size(@policy.filter_exp)
|
228
|
+
field_count += 1 if exp_size > 0
|
208
229
|
|
209
230
|
bin_names.each do |bin_name|
|
210
231
|
estimate_operation_size_for_bin_name(bin_name)
|
@@ -214,6 +235,7 @@ module Aerospike
|
|
214
235
|
write_header(policy, INFO1_READ, 0, field_count, bin_names.length)
|
215
236
|
write_key(key)
|
216
237
|
write_predexp(policy.predexp, predexp_size)
|
238
|
+
write_filter_exp(@policy.filter_exp, exp_size)
|
217
239
|
|
218
240
|
bin_names.each do |bin_name|
|
219
241
|
write_operation_for_bin_name(bin_name, Aerospike::Operation::READ)
|
@@ -233,7 +255,10 @@ module Aerospike
|
|
233
255
|
predexp_size = estimate_predexp(policy.predexp)
|
234
256
|
field_count += 1 if predexp_size > 0
|
235
257
|
|
236
|
-
|
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("")
|
237
262
|
size_buffer
|
238
263
|
|
239
264
|
# The server does not currently return record header data with _INFO1_NOBINDATA attribute set.
|
@@ -244,70 +269,35 @@ module Aerospike
|
|
244
269
|
|
245
270
|
write_key(key)
|
246
271
|
write_predexp(policy.predexp, predexp_size)
|
247
|
-
|
272
|
+
write_filter_exp(@policy.filter_exp, exp_size)
|
273
|
+
write_operation_for_bin_name("", Aerospike::Operation::READ)
|
248
274
|
end_cmd
|
249
275
|
end
|
250
276
|
|
251
277
|
# Implements different command operations
|
252
|
-
def set_operate(policy, key,
|
278
|
+
def set_operate(policy, key, args)
|
253
279
|
begin_cmd
|
254
280
|
field_count = estimate_key_size(key, policy)
|
255
281
|
|
256
282
|
predexp_size = estimate_predexp(policy.predexp)
|
257
283
|
field_count += 1 if predexp_size > 0
|
258
284
|
|
259
|
-
|
260
|
-
|
261
|
-
read_header = false
|
262
|
-
record_bin_multiplicity = policy.record_bin_multiplicity == RecordBinMultiplicity::ARRAY
|
263
|
-
|
264
|
-
operations.each do |operation|
|
265
|
-
case operation.op_type
|
266
|
-
when Aerospike::Operation::READ, Aerospike::Operation::CDT_READ,
|
267
|
-
Aerospike::Operation::HLL_READ, Aerospike::Operation::BIT_READ
|
268
|
-
read_attr |= INFO1_READ
|
269
|
-
|
270
|
-
# Read all bins if no bin is specified.
|
271
|
-
read_attr |= INFO1_GET_ALL unless operation.bin_name
|
272
|
-
|
273
|
-
when Aerospike::Operation::READ_HEADER
|
274
|
-
# The server does not currently return record header data with _INFO1_NOBINDATA attribute set.
|
275
|
-
# The workaround is to request a non-existent bin.
|
276
|
-
# TODO: Fix this on server.
|
277
|
-
# read_attr |= _INFO1_READ | _INFO1_NOBINDATA
|
278
|
-
read_attr |= INFO1_READ
|
279
|
-
read_header = true
|
280
|
-
|
281
|
-
else
|
282
|
-
write_attr = INFO2_WRITE
|
283
|
-
end
|
285
|
+
exp_size = estimate_expression_size(policy.filter_exp)
|
286
|
+
field_count += 1 if exp_size > 0
|
284
287
|
|
285
|
-
|
286
|
-
Aerospike::Operation::BIT_MODIFY, Aerospike::Operation::BIT_READ].include?(operation.op_type)
|
287
|
-
record_bin_multiplicity = true
|
288
|
-
end
|
288
|
+
@data_offset += args.size
|
289
289
|
|
290
|
-
estimate_operation_size_for_operation(operation)
|
291
|
-
end
|
292
290
|
size_buffer
|
293
291
|
|
294
|
-
|
295
|
-
write_attr |= INFO2_RESPOND_ALL_OPS if write_attr != 0 && record_bin_multiplicity
|
296
|
-
|
297
|
-
if write_attr == 0
|
298
|
-
write_header(policy, read_attr, write_attr, field_count, operations.length)
|
299
|
-
else
|
300
|
-
write_header_with_policy(policy, read_attr, write_attr, field_count, operations.length)
|
301
|
-
end
|
292
|
+
write_header_with_policy(policy, args.read_attr, args.write_attr, field_count, args.operations.length)
|
302
293
|
write_key(key, policy)
|
303
294
|
write_predexp(policy.predexp, predexp_size)
|
295
|
+
write_filter_exp(policy.filter_exp, exp_size)
|
304
296
|
|
305
|
-
operations.each do |operation|
|
297
|
+
args.operations.each do |operation|
|
306
298
|
write_operation_for_operation(operation)
|
307
299
|
end
|
308
300
|
|
309
|
-
write_operation_for_bin(nil, Aerospike::Operation::READ) if read_header
|
310
|
-
|
311
301
|
end_cmd
|
312
302
|
mark_compressed(policy)
|
313
303
|
end
|
@@ -319,6 +309,9 @@ module Aerospike
|
|
319
309
|
predexp_size = estimate_predexp(policy.predexp)
|
320
310
|
field_count += 1 if predexp_size > 0
|
321
311
|
|
312
|
+
exp_size = estimate_expression_size(@policy.filter_exp)
|
313
|
+
field_count += 1 if exp_size > 0
|
314
|
+
|
322
315
|
arg_bytes = args.to_bytes
|
323
316
|
|
324
317
|
field_count += estimate_udf_size(package_name, function_name, arg_bytes)
|
@@ -327,6 +320,7 @@ module Aerospike
|
|
327
320
|
write_header(policy, 0, INFO2_WRITE, field_count, 0)
|
328
321
|
write_key(key, policy)
|
329
322
|
write_predexp(policy.predexp, predexp_size)
|
323
|
+
write_filter_exp(@policy.filter_exp, exp_size)
|
330
324
|
write_field_string(package_name, Aerospike::FieldType::UDF_PACKAGE_NAME)
|
331
325
|
write_field_string(function_name, Aerospike::FieldType::UDF_FUNCTION)
|
332
326
|
write_field_bytes(arg_bytes, Aerospike::FieldType::UDF_ARGLIST)
|
@@ -377,6 +371,9 @@ module Aerospike
|
|
377
371
|
predexp_size = estimate_predexp(policy.predexp)
|
378
372
|
field_count += 1 if predexp_size > 0
|
379
373
|
|
374
|
+
exp_size = estimate_expression_size(@policy.filter_exp)
|
375
|
+
field_count += 1 if exp_size > 0
|
376
|
+
|
380
377
|
# Estimate scan options size.
|
381
378
|
# @data_offset += 2 + FIELD_HEADER_SIZE
|
382
379
|
# field_count += 1
|
@@ -418,7 +415,7 @@ module Aerospike
|
|
418
415
|
|
419
416
|
node_partitions.parts_full.each do |part|
|
420
417
|
@data_buffer.write_uint16_little_endian(part.id, @data_offset)
|
421
|
-
@data_offset+=2
|
418
|
+
@data_offset += 2
|
422
419
|
end
|
423
420
|
end
|
424
421
|
|
@@ -427,7 +424,7 @@ module Aerospike
|
|
427
424
|
|
428
425
|
node_partitions.parts_partial.each do |part|
|
429
426
|
@data_buffer.write_binary(part.digest, @data_offset)
|
430
|
-
@data_offset+=part.digest.length
|
427
|
+
@data_offset += part.digest.length
|
431
428
|
end
|
432
429
|
end
|
433
430
|
|
@@ -440,6 +437,7 @@ module Aerospike
|
|
440
437
|
end
|
441
438
|
|
442
439
|
write_predexp(policy.predexp, predexp_size)
|
440
|
+
write_filter_exp(@policy.filter_exp, exp_size)
|
443
441
|
|
444
442
|
# write_field_header(2, Aerospike::FieldType::SCAN_OPTIONS)
|
445
443
|
|
@@ -454,7 +452,7 @@ module Aerospike
|
|
454
452
|
# @data_buffer.write_byte(policy.scan_percent.to_i.ord, @data_offset)
|
455
453
|
# @data_offset += 1
|
456
454
|
|
457
|
-
write_field_header(4, Aerospike::FieldType::
|
455
|
+
write_field_header(4, Aerospike::FieldType::SOCKET_TIMEOUT)
|
458
456
|
@data_buffer.write_uint32(policy.socket_timeout.to_i, @data_offset)
|
459
457
|
@data_offset += 4
|
460
458
|
|
@@ -477,7 +475,7 @@ module Aerospike
|
|
477
475
|
while true
|
478
476
|
# too many retries
|
479
477
|
iterations += 1
|
480
|
-
break if (@policy.max_retries > 0) && (iterations > @policy.max_retries+1)
|
478
|
+
break if (@policy.max_retries > 0) && (iterations > @policy.max_retries + 1)
|
481
479
|
|
482
480
|
# Sleep before trying again, after the first iteration
|
483
481
|
sleep(@policy.sleep_between_retries) if iterations > 1 && @policy.sleep_between_retries > 0
|
@@ -565,7 +563,6 @@ module Aerospike
|
|
565
563
|
ensure
|
566
564
|
Buffer.put(@data_buffer)
|
567
565
|
end
|
568
|
-
|
569
566
|
end # while
|
570
567
|
|
571
568
|
# execution timeout
|
@@ -574,7 +571,6 @@ module Aerospike
|
|
574
571
|
|
575
572
|
protected
|
576
573
|
|
577
|
-
|
578
574
|
def estimate_key_size(key, policy = nil)
|
579
575
|
field_count = 0
|
580
576
|
|
@@ -644,6 +640,15 @@ module Aerospike
|
|
644
640
|
return 0
|
645
641
|
end
|
646
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
|
+
|
647
652
|
# Generic header write.
|
648
653
|
def write_header(policy, read_attr, write_attr, field_count, operation_count)
|
649
654
|
read_attr |= INFO1_CONSISTENCY_ALL if policy.consistency_level == Aerospike::ConsistencyLevel::CONSISTENCY_ALL
|
@@ -715,7 +720,6 @@ module Aerospike
|
|
715
720
|
@data_buffer.write_byte(0, 24)
|
716
721
|
@data_buffer.write_byte(0, 25)
|
717
722
|
|
718
|
-
|
719
723
|
@data_buffer.write_int16(field_count, 26)
|
720
724
|
@data_buffer.write_int16(operation_count, 28)
|
721
725
|
|
@@ -737,15 +741,14 @@ module Aerospike
|
|
737
741
|
if policy && policy.respond_to?(:send_key) && policy.send_key == true
|
738
742
|
write_field_value(key.user_key_as_value, Aerospike::FieldType::KEY)
|
739
743
|
end
|
740
|
-
|
741
744
|
end
|
742
745
|
|
743
746
|
def write_operation_for_bin(bin, operation)
|
744
|
-
name_length = @data_buffer.write_binary(bin.name, @data_offset+OPERATION_HEADER_SIZE)
|
745
|
-
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)
|
746
749
|
|
747
750
|
# Buffer.Int32ToBytes(name_length+value_length+4, @data_buffer, @data_offset)
|
748
|
-
@data_buffer.write_int32(name_length+value_length+4, @data_offset)
|
751
|
+
@data_buffer.write_int32(name_length + value_length + 4, @data_offset)
|
749
752
|
|
750
753
|
@data_offset += 4
|
751
754
|
@data_buffer.write_byte(operation, @data_offset)
|
@@ -762,13 +765,13 @@ module Aerospike
|
|
762
765
|
def write_operation_for_operation(operation)
|
763
766
|
name_length = 0
|
764
767
|
if operation.bin_name
|
765
|
-
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)
|
766
769
|
end
|
767
770
|
|
768
|
-
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)
|
769
772
|
|
770
773
|
# Buffer.Int32ToBytes(name_length+value_length+4, @data_buffer, @data_offset)
|
771
|
-
@data_buffer.write_int32(name_length+value_length+4, @data_offset)
|
774
|
+
@data_buffer.write_int32(name_length + value_length + 4, @data_offset)
|
772
775
|
|
773
776
|
@data_offset += 4
|
774
777
|
@data_buffer.write_byte(operation.op_type, @data_offset)
|
@@ -783,9 +786,9 @@ module Aerospike
|
|
783
786
|
end
|
784
787
|
|
785
788
|
def write_operation_for_bin_name(name, operation)
|
786
|
-
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)
|
787
790
|
# Buffer.Int32ToBytes(name_length+4, @data_buffer, @data_offset)
|
788
|
-
@data_buffer.write_int32(name_length+4, @data_offset)
|
791
|
+
@data_buffer.write_int32(name_length + 4, @data_offset)
|
789
792
|
|
790
793
|
@data_offset += 4
|
791
794
|
@data_buffer.write_byte(operation, @data_offset)
|
@@ -824,37 +827,37 @@ module Aerospike
|
|
824
827
|
end
|
825
828
|
|
826
829
|
def write_field_string(str, ftype)
|
827
|
-
len = @data_buffer.write_binary(str, @data_offset+FIELD_HEADER_SIZE)
|
830
|
+
len = @data_buffer.write_binary(str, @data_offset + FIELD_HEADER_SIZE)
|
828
831
|
write_field_header(len, ftype)
|
829
832
|
@data_offset += len
|
830
833
|
end
|
831
834
|
|
832
835
|
def write_u16_little_endian(i, ftype)
|
833
|
-
@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)
|
834
837
|
write_field_header(2, ftype)
|
835
838
|
@data_offset += 2
|
836
839
|
end
|
837
840
|
|
838
841
|
def write_field_int(i, ftype)
|
839
|
-
@data_buffer.write_int32(i, @data_offset+FIELD_HEADER_SIZE)
|
842
|
+
@data_buffer.write_int32(i, @data_offset + FIELD_HEADER_SIZE)
|
840
843
|
write_field_header(4, ftype)
|
841
844
|
@data_offset += 4
|
842
845
|
end
|
843
846
|
|
844
847
|
def write_field_int64(i, ftype)
|
845
|
-
@data_buffer.write_int64(i, @data_offset+FIELD_HEADER_SIZE)
|
848
|
+
@data_buffer.write_int64(i, @data_offset + FIELD_HEADER_SIZE)
|
846
849
|
write_field_header(8, ftype)
|
847
850
|
@data_offset += 8
|
848
851
|
end
|
849
852
|
|
850
853
|
def write_field_bytes(bytes, ftype)
|
851
|
-
@data_buffer.write_binary(bytes, @data_offset+FIELD_HEADER_SIZE)
|
854
|
+
@data_buffer.write_binary(bytes, @data_offset + FIELD_HEADER_SIZE)
|
852
855
|
write_field_header(bytes.bytesize, ftype)
|
853
856
|
@data_offset += bytes.bytesize
|
854
857
|
end
|
855
858
|
|
856
859
|
def write_field_header(size, ftype)
|
857
|
-
@data_buffer.write_int32(size+1, @data_offset)
|
860
|
+
@data_buffer.write_int32(size + 1, @data_offset)
|
858
861
|
@data_offset += 4
|
859
862
|
@data_buffer.write_byte(ftype, @data_offset)
|
860
863
|
@data_offset += 1
|
@@ -862,13 +865,20 @@ module Aerospike
|
|
862
865
|
|
863
866
|
def write_predexp(predexp, predexp_size)
|
864
867
|
if predexp && predexp.size > 0
|
865
|
-
write_field_header(predexp_size, Aerospike::FieldType::
|
868
|
+
write_field_header(predexp_size, Aerospike::FieldType::FILTER_EXP)
|
866
869
|
@data_offset = Aerospike::PredExp.write(
|
867
870
|
predexp, @data_buffer, @data_offset
|
868
871
|
)
|
869
872
|
end
|
870
873
|
end
|
871
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
|
+
|
872
882
|
def begin_cmd
|
873
883
|
@data_offset = MSG_TOTAL_HEADER_SIZE
|
874
884
|
end
|
@@ -882,7 +892,7 @@ module Aerospike
|
|
882
892
|
end
|
883
893
|
|
884
894
|
def end_cmd
|
885
|
-
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)
|
886
896
|
@data_buffer.write_int64(size, 0)
|
887
897
|
end
|
888
898
|
|
@@ -896,13 +906,13 @@ module Aerospike
|
|
896
906
|
|
897
907
|
# write original size as header
|
898
908
|
proto_s = "%08d" % 0
|
899
|
-
proto_s[0, 8] = [@data_offset].pack(
|
909
|
+
proto_s[0, 8] = [@data_offset].pack("q>")
|
900
910
|
compressed.prepend(proto_s)
|
901
911
|
|
902
912
|
# write proto
|
903
|
-
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)
|
904
914
|
proto_s = "%08d" % 0
|
905
|
-
proto_s[0, 8] = [proto].pack(
|
915
|
+
proto_s[0, 8] = [proto].pack("q>")
|
906
916
|
compressed.prepend(proto_s)
|
907
917
|
|
908
918
|
@data_buffer = Buffer.new(-1, compressed)
|
@@ -927,7 +937,5 @@ module Aerospike
|
|
927
937
|
def mark_compressed(policy)
|
928
938
|
@compress = policy.use_compression
|
929
939
|
end
|
930
|
-
|
931
940
|
end # class
|
932
|
-
|
933
941
|
end # module
|
@@ -21,34 +21,31 @@ module Aerospike
|
|
21
21
|
|
22
22
|
module FieldType
|
23
23
|
|
24
|
-
NAMESPACE
|
25
|
-
TABLE
|
26
|
-
KEY
|
27
|
-
|
28
|
-
|
29
|
-
#
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
QUERY_BINLIST = 40
|
50
|
-
BATCH_INDEX = 41
|
51
|
-
PREDEXP = 43
|
24
|
+
NAMESPACE = 0
|
25
|
+
TABLE = 1
|
26
|
+
KEY = 2
|
27
|
+
DIGEST_RIPE = 4
|
28
|
+
DIGEST_RIPE_ARRAY = 6
|
29
|
+
TRAN_ID = 7 # user supplied transaction id, which is simply passed back
|
30
|
+
SCAN_OPTIONS = 8
|
31
|
+
SOCKET_TIMEOUT = 9
|
32
|
+
RECORDS_PER_SECOND = 10
|
33
|
+
PID_ARRAY = 11
|
34
|
+
DIGEST_ARRAY = 12
|
35
|
+
MAX_RECORDS = 13
|
36
|
+
BVAL_ARRAY = 15
|
37
|
+
INDEX_NAME = 21
|
38
|
+
INDEX_RANGE = 22
|
39
|
+
INDEX_CONTEXT = 23
|
40
|
+
INDEX_TYPE = 26
|
41
|
+
UDF_PACKAGE_NAME = 30
|
42
|
+
UDF_FUNCTION = 31
|
43
|
+
UDF_ARGLIST = 32
|
44
|
+
UDF_OP = 33
|
45
|
+
QUERY_BINLIST = 40
|
46
|
+
BATCH_INDEX = 41
|
47
|
+
BATCH_INDEX_WITH_SET = 42
|
48
|
+
FILTER_EXP = 43
|
52
49
|
|
53
50
|
end # module
|
54
51
|
|
@@ -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
|