aerospike 3.0.0 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +35 -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 +7 -11
- 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 +125 -98
- 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 +116 -119
- 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/policy/batch_read_policy.rb +55 -0
- 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 +20 -40
- data/lib/aerospike/policy/query_duration.rb +48 -0
- data/lib/aerospike/policy/query_policy.rb +13 -8
- data/lib/aerospike/query/server_command.rb +1 -0
- data/lib/aerospike/query/statement.rb +5 -21
- data/lib/aerospike/result_code.rb +7 -1
- data/lib/aerospike/utils/buffer.rb +15 -15
- data/lib/aerospike/version.rb +1 -1
- data/lib/aerospike.rb +14 -12
- metadata +17 -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/command/batch_direct_node.rb +0 -40
- 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
@@ -58,7 +58,8 @@ module Aerospike
|
|
58
58
|
INFO2_DURABLE_DELETE = Integer(1 << 4)
|
59
59
|
# Create only. Fail if record already exists.
|
60
60
|
INFO2_CREATE_ONLY = Integer(1 << 5)
|
61
|
-
|
61
|
+
# Treat as long query, but relax read consistency.
|
62
|
+
INFO2_RELAX_AP_LONG_QUERY = (1 << 6)
|
62
63
|
# Return a result for every operation.
|
63
64
|
INFO2_RESPOND_ALL_OPS = Integer(1 << 7)
|
64
65
|
|
@@ -76,6 +77,12 @@ module Aerospike
|
|
76
77
|
# Completely replace existing record only.
|
77
78
|
INFO3_REPLACE_ONLY = Integer(1 << 5)
|
78
79
|
|
80
|
+
BATCH_MSG_READ = 0x0
|
81
|
+
BATCH_MSG_REPEAT = 0x1
|
82
|
+
BATCH_MSG_INFO = 0x2
|
83
|
+
BATCH_MSG_GEN = 0x4
|
84
|
+
BATCH_MSG_TTL = 0x8
|
85
|
+
|
79
86
|
MSG_TOTAL_HEADER_SIZE = 30
|
80
87
|
FIELD_HEADER_SIZE = 5
|
81
88
|
OPERATION_HEADER_SIZE = 8
|
@@ -112,9 +119,6 @@ module Aerospike
|
|
112
119
|
begin_cmd
|
113
120
|
field_count = estimate_key_size(key, policy)
|
114
121
|
|
115
|
-
predexp_size = estimate_predexp(policy.predexp)
|
116
|
-
field_count += 1 if predexp_size > 0
|
117
|
-
|
118
122
|
exp_size = estimate_expression_size(@policy.filter_exp)
|
119
123
|
field_count += 1 if exp_size > 0
|
120
124
|
|
@@ -126,7 +130,6 @@ module Aerospike
|
|
126
130
|
|
127
131
|
write_header_write(policy, INFO2_WRITE, field_count, bins.length)
|
128
132
|
write_key(key, policy)
|
129
|
-
write_predexp(policy.predexp, predexp_size)
|
130
133
|
write_filter_exp(@policy.filter_exp, exp_size)
|
131
134
|
|
132
135
|
bins.each do |bin|
|
@@ -142,16 +145,12 @@ module Aerospike
|
|
142
145
|
begin_cmd
|
143
146
|
field_count = estimate_key_size(key)
|
144
147
|
|
145
|
-
predexp_size = estimate_predexp(policy.predexp)
|
146
|
-
field_count += 1 if predexp_size > 0
|
147
|
-
|
148
148
|
exp_size = estimate_expression_size(@policy.filter_exp)
|
149
149
|
field_count += 1 if exp_size > 0
|
150
150
|
|
151
151
|
size_buffer
|
152
|
-
write_header_write(policy,
|
152
|
+
write_header_write(policy, INFO2_WRITE | INFO2_DELETE, field_count, 0)
|
153
153
|
write_key(key)
|
154
|
-
write_predexp(policy.predexp, predexp_size)
|
155
154
|
write_filter_exp(@policy.filter_exp, exp_size)
|
156
155
|
end_cmd
|
157
156
|
end
|
@@ -161,17 +160,13 @@ module Aerospike
|
|
161
160
|
begin_cmd
|
162
161
|
field_count = estimate_key_size(key)
|
163
162
|
|
164
|
-
predexp_size = estimate_predexp(policy.predexp)
|
165
|
-
field_count += 1 if predexp_size > 0
|
166
|
-
|
167
163
|
exp_size = estimate_expression_size(@policy.filter_exp)
|
168
164
|
field_count += 1 if exp_size > 0
|
169
165
|
|
170
166
|
estimate_operation_size
|
171
167
|
size_buffer
|
172
|
-
write_header_write(policy,
|
168
|
+
write_header_write(policy, INFO2_WRITE, field_count, 1)
|
173
169
|
write_key(key)
|
174
|
-
write_predexp(policy.predexp, predexp_size)
|
175
170
|
write_filter_exp(@policy.filter_exp, exp_size)
|
176
171
|
write_operation_for_operation_type(Aerospike::Operation::TOUCH)
|
177
172
|
end_cmd
|
@@ -182,16 +177,12 @@ module Aerospike
|
|
182
177
|
begin_cmd
|
183
178
|
field_count = estimate_key_size(key)
|
184
179
|
|
185
|
-
predexp_size = estimate_predexp(policy.predexp)
|
186
|
-
field_count += 1 if predexp_size > 0
|
187
|
-
|
188
180
|
exp_size = estimate_expression_size(@policy.filter_exp)
|
189
181
|
field_count += 1 if exp_size > 0
|
190
182
|
|
191
183
|
size_buffer
|
192
184
|
write_header_read_header(policy, INFO1_READ | INFO1_NOBINDATA, field_count, 0)
|
193
185
|
write_key(key)
|
194
|
-
write_predexp(policy.predexp, predexp_size)
|
195
186
|
write_filter_exp(@policy.filter_exp, exp_size)
|
196
187
|
end_cmd
|
197
188
|
end
|
@@ -201,16 +192,12 @@ module Aerospike
|
|
201
192
|
begin_cmd
|
202
193
|
field_count = estimate_key_size(key)
|
203
194
|
|
204
|
-
predexp_size = estimate_predexp(policy.predexp)
|
205
|
-
field_count += 1 if predexp_size > 0
|
206
|
-
|
207
195
|
exp_size = estimate_expression_size(@policy.filter_exp)
|
208
196
|
field_count += 1 if exp_size > 0
|
209
197
|
|
210
198
|
size_buffer
|
211
|
-
write_header_read(policy, INFO1_READ | INFO1_GET_ALL, 0, field_count, 0)
|
199
|
+
write_header_read(policy, INFO1_READ | INFO1_GET_ALL, 0, 0, field_count, 0)
|
212
200
|
write_key(key)
|
213
|
-
write_predexp(policy.predexp, predexp_size)
|
214
201
|
write_filter_exp(@policy.filter_exp, exp_size)
|
215
202
|
end_cmd
|
216
203
|
end
|
@@ -221,9 +208,6 @@ module Aerospike
|
|
221
208
|
begin_cmd
|
222
209
|
field_count = estimate_key_size(key)
|
223
210
|
|
224
|
-
predexp_size = estimate_predexp(policy.predexp)
|
225
|
-
field_count += 1 if predexp_size > 0
|
226
|
-
|
227
211
|
exp_size = estimate_expression_size(@policy.filter_exp)
|
228
212
|
field_count += 1 if exp_size > 0
|
229
213
|
|
@@ -237,9 +221,8 @@ module Aerospike
|
|
237
221
|
attr |= INFO1_GET_ALL
|
238
222
|
end
|
239
223
|
|
240
|
-
write_header_read(policy, attr, 0, field_count, bin_names.length)
|
224
|
+
write_header_read(policy, attr, 0, 0, field_count, bin_names.length)
|
241
225
|
write_key(key)
|
242
|
-
write_predexp(policy.predexp, predexp_size)
|
243
226
|
write_filter_exp(@policy.filter_exp, exp_size)
|
244
227
|
|
245
228
|
bin_names.each do |bin_name|
|
@@ -258,9 +241,6 @@ module Aerospike
|
|
258
241
|
begin_cmd
|
259
242
|
field_count = estimate_key_size(key)
|
260
243
|
|
261
|
-
predexp_size = estimate_predexp(policy.predexp)
|
262
|
-
field_count += 1 if predexp_size > 0
|
263
|
-
|
264
244
|
exp_size = estimate_expression_size(@policy.filter_exp)
|
265
245
|
field_count += 1 if exp_size > 0
|
266
246
|
|
@@ -273,7 +253,6 @@ module Aerospike
|
|
273
253
|
write_header_read_header(policy, INFO1_READ|INFO1_NOBINDATA, field_count, 0)
|
274
254
|
|
275
255
|
write_key(key)
|
276
|
-
write_predexp(policy.predexp, predexp_size)
|
277
256
|
write_filter_exp(@policy.filter_exp, exp_size)
|
278
257
|
end_cmd
|
279
258
|
mark_compressed(policy)
|
@@ -284,9 +263,6 @@ module Aerospike
|
|
284
263
|
begin_cmd
|
285
264
|
field_count = estimate_key_size(key, policy)
|
286
265
|
|
287
|
-
predexp_size = estimate_predexp(policy.predexp)
|
288
|
-
field_count += 1 if predexp_size > 0
|
289
|
-
|
290
266
|
exp_size = estimate_expression_size(policy.filter_exp)
|
291
267
|
field_count += 1 if exp_size > 0
|
292
268
|
|
@@ -294,9 +270,8 @@ module Aerospike
|
|
294
270
|
|
295
271
|
size_buffer
|
296
272
|
|
297
|
-
write_header_read_write(policy, args
|
273
|
+
write_header_read_write(policy, args, field_count)
|
298
274
|
write_key(key, policy)
|
299
|
-
write_predexp(policy.predexp, predexp_size)
|
300
275
|
write_filter_exp(policy.filter_exp, exp_size)
|
301
276
|
|
302
277
|
args.operations.each do |operation|
|
@@ -311,9 +286,6 @@ module Aerospike
|
|
311
286
|
begin_cmd
|
312
287
|
field_count = estimate_key_size(key, policy)
|
313
288
|
|
314
|
-
predexp_size = estimate_predexp(policy.predexp)
|
315
|
-
field_count += 1 if predexp_size > 0
|
316
|
-
|
317
289
|
exp_size = estimate_expression_size(@policy.filter_exp)
|
318
290
|
field_count += 1 if exp_size > 0
|
319
291
|
|
@@ -324,7 +296,6 @@ module Aerospike
|
|
324
296
|
|
325
297
|
write_header_write(policy, INFO2_WRITE, field_count, 0)
|
326
298
|
write_key(key, policy)
|
327
|
-
write_predexp(policy.predexp, predexp_size)
|
328
299
|
write_filter_exp(@policy.filter_exp, exp_size)
|
329
300
|
write_field_string(package_name, Aerospike::FieldType::UDF_PACKAGE_NAME)
|
330
301
|
write_field_string(function_name, Aerospike::FieldType::UDF_FUNCTION)
|
@@ -373,9 +344,6 @@ module Aerospike
|
|
373
344
|
field_count += 1
|
374
345
|
end
|
375
346
|
|
376
|
-
predexp_size = estimate_predexp(policy.predexp)
|
377
|
-
field_count += 1 if predexp_size > 0
|
378
|
-
|
379
347
|
exp_size = estimate_expression_size(@policy.filter_exp)
|
380
348
|
field_count += 1 if exp_size > 0
|
381
349
|
|
@@ -410,7 +378,7 @@ module Aerospike
|
|
410
378
|
operation_count = bin_names.length
|
411
379
|
end
|
412
380
|
|
413
|
-
write_header_read(policy, read_attr, info_attr, field_count, operation_count)
|
381
|
+
write_header_read(policy, read_attr, 0, info_attr, field_count, operation_count)
|
414
382
|
|
415
383
|
if namespace
|
416
384
|
write_field_string(namespace, Aerospike::FieldType::NAMESPACE)
|
@@ -446,7 +414,6 @@ module Aerospike
|
|
446
414
|
write_field_int(policy.records_per_second, Aerospike::FieldType::RECORDS_PER_SECOND)
|
447
415
|
end
|
448
416
|
|
449
|
-
write_predexp(policy.predexp, predexp_size)
|
450
417
|
write_filter_exp(@policy.filter_exp, exp_size)
|
451
418
|
|
452
419
|
# write_field_header(2, Aerospike::FieldType::SCAN_OPTIONS)
|
@@ -475,7 +442,6 @@ module Aerospike
|
|
475
442
|
end_cmd
|
476
443
|
end
|
477
444
|
|
478
|
-
|
479
445
|
def set_query(cluster, policy, statement, background, node_partitions)
|
480
446
|
function_arg_buffer = nil
|
481
447
|
field_count = 0
|
@@ -525,7 +491,7 @@ module Aerospike
|
|
525
491
|
|
526
492
|
# Estimate INDEX_RANGE field.
|
527
493
|
@data_offset += FIELD_HEADER_SIZE
|
528
|
-
filter_size += 1
|
494
|
+
filter_size += 1 # num filters
|
529
495
|
filter_size += filter.estimate_size
|
530
496
|
|
531
497
|
@data_offset += filter_size
|
@@ -539,14 +505,6 @@ module Aerospike
|
|
539
505
|
end
|
540
506
|
|
541
507
|
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
508
|
|
551
509
|
unless policy.filter_exp.nil?
|
552
510
|
exp_size = estimate_expression_size(policy.filter_exp)
|
@@ -634,10 +592,16 @@ module Aerospike
|
|
634
592
|
write_header_write(policy, INFO2_WRITE, field_count, operation_count)
|
635
593
|
else
|
636
594
|
read_attr = INFO1_READ
|
595
|
+
write_attr = 0
|
596
|
+
|
637
597
|
read_attr |= INFO1_NOBINDATA unless policy.include_bin_data
|
638
|
-
|
598
|
+
if policy.short_query || policy.expected_duration == QueryDuration::SHORT
|
599
|
+
read_attr |= INFO1_SHORT_QUERY
|
600
|
+
elsif policy.expected_duration == QueryDuration::LONG_RELAX_AP
|
601
|
+
write_attr |= INFO2_RELAX_AP_LONG_QUERY
|
602
|
+
end
|
639
603
|
info_attr = INFO3_PARTITION_DONE if is_new
|
640
|
-
write_header_read(policy, read_attr, info_attr, field_count, operation_count)
|
604
|
+
write_header_read(policy, read_attr, write_attr, info_attr, field_count, operation_count)
|
641
605
|
end
|
642
606
|
|
643
607
|
|
@@ -656,13 +620,6 @@ module Aerospike
|
|
656
620
|
# Write task_id field
|
657
621
|
write_field_int64(statement.task_id, FieldType::TRAN_ID)
|
658
622
|
|
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
623
|
if filter
|
667
624
|
type = filter.collection_type
|
668
625
|
|
@@ -683,7 +640,8 @@ module Aerospike
|
|
683
640
|
|
684
641
|
if statement.function_name
|
685
642
|
write_field_header(1, FieldType::UDF_OP)
|
686
|
-
|
643
|
+
ret_marker = statement.return_data ? 1 : 2
|
644
|
+
@data_offset += @data_buffer.write_byte(ret_marker, @data_offset)
|
687
645
|
write_field_string(statement.package_name, FieldType::UDF_PACKAGE_NAME)
|
688
646
|
write_field_string(statement.function_name, FieldType::UDF_FUNCTION)
|
689
647
|
write_field_string(function_arg_buffer, FieldType::UDF_ARGLIST)
|
@@ -725,7 +683,6 @@ module Aerospike
|
|
725
683
|
end_cmd
|
726
684
|
end
|
727
685
|
|
728
|
-
|
729
686
|
def execute
|
730
687
|
iterations = 0
|
731
688
|
|
@@ -752,7 +709,7 @@ module Aerospike
|
|
752
709
|
# Socket connection error has occurred. Decrease health and retry.
|
753
710
|
@node.decrease_health
|
754
711
|
|
755
|
-
Aerospike.logger.error("Node #{@node
|
712
|
+
Aerospike.logger.error("Node #{@node}: #{e}")
|
756
713
|
else
|
757
714
|
Aerospike.logger.error("No node available for transaction: #{e}")
|
758
715
|
end
|
@@ -785,7 +742,7 @@ module Aerospike
|
|
785
742
|
# Close socket to flush out possible garbage. Do not put back in pool.
|
786
743
|
@conn.close if @conn
|
787
744
|
|
788
|
-
Aerospike.logger.error("Node #{@node
|
745
|
+
Aerospike.logger.error("Node #{@node}: #{e}")
|
789
746
|
# IO error means connection to server @node is unhealthy.
|
790
747
|
# Reflect cmd status.
|
791
748
|
@node.decrease_health
|
@@ -853,14 +810,14 @@ module Aerospike
|
|
853
810
|
field_count += 1
|
854
811
|
end
|
855
812
|
|
856
|
-
|
813
|
+
field_count
|
857
814
|
end
|
858
815
|
|
859
816
|
def estimate_udf_size(package_name, function_name, bytes)
|
860
817
|
@data_offset += package_name.bytesize + FIELD_HEADER_SIZE
|
861
818
|
@data_offset += function_name.bytesize + FIELD_HEADER_SIZE
|
862
819
|
@data_offset += bytes.bytesize + FIELD_HEADER_SIZE
|
863
|
-
|
820
|
+
3
|
864
821
|
end
|
865
822
|
|
866
823
|
def estimate_operation_size_for_bin(bin)
|
@@ -890,16 +847,6 @@ module Aerospike
|
|
890
847
|
@data_offset += OPERATION_HEADER_SIZE
|
891
848
|
end
|
892
849
|
|
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
850
|
def estimate_expression_size(exp)
|
904
851
|
unless exp.nil?
|
905
852
|
@data_offset += FIELD_HEADER_SIZE
|
@@ -963,10 +910,14 @@ module Aerospike
|
|
963
910
|
end
|
964
911
|
|
965
912
|
# Header write for write operations.
|
966
|
-
def write_header_read_write(policy,
|
913
|
+
def write_header_read_write(policy, args, field_count)
|
967
914
|
# Set flags.
|
968
915
|
generation = Integer(0)
|
916
|
+
ttl = args.has_write ? policy.expiration : policy.read_touch_ttl_percent
|
917
|
+
read_attr = args.read_attr
|
918
|
+
write_attr = args.write_attr
|
969
919
|
info_attr = Integer(0)
|
920
|
+
operation_count = args.operations.length
|
970
921
|
|
971
922
|
case policy.record_exists_action
|
972
923
|
when Aerospike::RecordExistsAction::UPDATE
|
@@ -1002,7 +953,7 @@ module Aerospike
|
|
1002
953
|
@data_buffer.write_byte(0, 12) # unused
|
1003
954
|
@data_buffer.write_byte(0, 13) # clear the result code
|
1004
955
|
@data_buffer.write_uint32(generation, 14)
|
1005
|
-
@data_buffer.write_uint32(
|
956
|
+
@data_buffer.write_uint32(ttl, 18)
|
1006
957
|
|
1007
958
|
# Initialize timeout. It will be written later.
|
1008
959
|
@data_buffer.write_byte(0, 22)
|
@@ -1016,18 +967,19 @@ module Aerospike
|
|
1016
967
|
@data_offset = MSG_TOTAL_HEADER_SIZE
|
1017
968
|
end
|
1018
969
|
|
1019
|
-
def write_header_read(policy, read_attr, info_attr, field_count, operation_count)
|
970
|
+
def write_header_read(policy, read_attr, write_attr, info_attr, field_count, operation_count)
|
1020
971
|
read_attr |= INFO1_COMPRESS_RESPONSE if policy.use_compression
|
1021
972
|
#TODO: Add SC Mode
|
1022
973
|
|
1023
974
|
@data_buffer.write_byte(MSG_REMAINING_HEADER_SIZE, 8) # Message header.length.
|
1024
975
|
@data_buffer.write_byte(read_attr, 9)
|
1025
|
-
@data_buffer.write_byte(
|
976
|
+
@data_buffer.write_byte(write_attr, 10)
|
1026
977
|
@data_buffer.write_byte(info_attr, 11)
|
1027
978
|
|
1028
|
-
(12...
|
979
|
+
(12...18).each { |i| @data_buffer.write_byte(0, i) }
|
1029
980
|
|
1030
981
|
# Initialize timeout. It will be written later.
|
982
|
+
@data_buffer.write_int32(policy.read_touch_ttl_percent, 18)
|
1031
983
|
@data_buffer.write_byte(0, 22)
|
1032
984
|
@data_buffer.write_byte(0, 23)
|
1033
985
|
@data_buffer.write_byte(0, 24)
|
@@ -1048,9 +1000,10 @@ module Aerospike
|
|
1048
1000
|
@data_buffer.write_byte(0, 10)
|
1049
1001
|
@data_buffer.write_byte(info_attr, 11)
|
1050
1002
|
|
1051
|
-
(12...
|
1003
|
+
(12...18).each { |i| @data_buffer.write_byte(0, i) }
|
1052
1004
|
|
1053
1005
|
# Initialize timeout. It will be written later.
|
1006
|
+
@data_buffer.write_int32(policy.read_touch_ttl_percent, 18)
|
1054
1007
|
@data_buffer.write_byte(0, 22)
|
1055
1008
|
@data_buffer.write_byte(0, 23)
|
1056
1009
|
@data_buffer.write_byte(0, 24)
|
@@ -1062,6 +1015,89 @@ module Aerospike
|
|
1062
1015
|
@data_offset = MSG_TOTAL_HEADER_SIZE
|
1063
1016
|
end
|
1064
1017
|
|
1018
|
+
def write_batch_operations(key, ops, attr, filter_exp)
|
1019
|
+
if attr.has_write
|
1020
|
+
write_batch_write(key, attr, filter_exp, 0, ops.length)
|
1021
|
+
else
|
1022
|
+
write_batch_read(key, attr, filter_exp, ops.length)
|
1023
|
+
end
|
1024
|
+
|
1025
|
+
ops.each do |op|
|
1026
|
+
write_operation_for_operation(op)
|
1027
|
+
end
|
1028
|
+
end
|
1029
|
+
|
1030
|
+
def write_batch_fields(key, field_count, op_count)
|
1031
|
+
field_count+=2
|
1032
|
+
@data_offset += @data_buffer.write_uint16(field_count, @data_offset)
|
1033
|
+
@data_offset += @data_buffer.write_uint16(op_count, @data_offset)
|
1034
|
+
write_field_string(key.namespace, Aerospike::FieldType::NAMESPACE)
|
1035
|
+
write_field_string(key.set_name, Aerospike::FieldType::TABLE)
|
1036
|
+
end
|
1037
|
+
|
1038
|
+
def write_batch_fields_with_filter(key, filter_exp, field_count, op_count)
|
1039
|
+
if filter_exp
|
1040
|
+
field_count+=1
|
1041
|
+
write_batch_fields(key, field_count, op_count)
|
1042
|
+
write_filter_exp(filter_exp, filter_exp.size)
|
1043
|
+
else
|
1044
|
+
write_batch_fields(key, field_count, op_count)
|
1045
|
+
end
|
1046
|
+
end
|
1047
|
+
|
1048
|
+
def write_batch_read(key, attr, filter_exp, op_count)
|
1049
|
+
@data_offset += @data_buffer.write_byte(BATCH_MSG_INFO | BATCH_MSG_TTL, @data_offset)
|
1050
|
+
@data_offset += @data_buffer.write_byte(attr.read_attr, @data_offset)
|
1051
|
+
@data_offset += @data_buffer.write_byte(attr.write_attr, @data_offset)
|
1052
|
+
@data_offset += @data_buffer.write_byte(attr.info_attr, @data_offset)
|
1053
|
+
@data_offset += @data_buffer.write_uint32(attr.expiration, @data_offset)
|
1054
|
+
write_batch_fields_with_filter(key, filter_exp, 0, op_count)
|
1055
|
+
end
|
1056
|
+
|
1057
|
+
def write_batch_write(key, attr, filter_exp, field_count, op_count)
|
1058
|
+
@data_offset += @data_buffer.write_byte(BATCH_MSG_INFO | BATCH_MSG_GEN | BATCH_MSG_TTL, @data_offset)
|
1059
|
+
@data_offset += @data_buffer.write_byte(attr.read_attr, @data_offset)
|
1060
|
+
@data_offset += @data_buffer.write_byte(attr.write_attr, @data_offset)
|
1061
|
+
@data_offset += @data_buffer.write_byte(attr.info_attr, @data_offset)
|
1062
|
+
@data_offset += @data_buffer.write_uint16(attr.generation, @data_offset)
|
1063
|
+
@data_offset += @data_buffer.write_uint32(attr.expiration, @data_offset)
|
1064
|
+
if attr.send_key
|
1065
|
+
field_count+=1
|
1066
|
+
write_batch_fields_with_filter(key, filter_exp, field_count, op_count)
|
1067
|
+
write_field_value(key.user_key, KEY)
|
1068
|
+
else
|
1069
|
+
write_batch_fields_with_filter(key, filter_exp, field_count, op_count)
|
1070
|
+
end
|
1071
|
+
end
|
1072
|
+
|
1073
|
+
def write_batch_bin_names(key, bin_names, attr, filter_exp)
|
1074
|
+
write_batch_read(key, attr, filter_exp, bin_names.length)
|
1075
|
+
bin_names.each do |bin_name|
|
1076
|
+
write_operation_for_bin_name(bin_name, Aerospike::Operation::READ)
|
1077
|
+
end
|
1078
|
+
end
|
1079
|
+
|
1080
|
+
def write_batch_header(policy, field_count)
|
1081
|
+
read_attr = INFO1_BATCH
|
1082
|
+
read_attr |= INFO1_COMPRESS_RESPONSE if policy.use_compression
|
1083
|
+
#TODO: Add SC Mode
|
1084
|
+
|
1085
|
+
@data_buffer.write_byte(MSG_REMAINING_HEADER_SIZE, 8) # Message header.length, @data_offset.
|
1086
|
+
@data_buffer.write_byte(read_attr, 9)
|
1087
|
+
@data_buffer.write_byte(0, 10)
|
1088
|
+
@data_buffer.write_byte(0, 11)
|
1089
|
+
|
1090
|
+
(12...22).each { |i| @data_buffer.write_byte(0, i) }
|
1091
|
+
|
1092
|
+
# Initialize timeout. It will be written later.
|
1093
|
+
@data_buffer.write_uint32(0, 22)
|
1094
|
+
|
1095
|
+
@data_buffer.write_uint16(field_count, 26)
|
1096
|
+
@data_buffer.write_uint16(0, 28)
|
1097
|
+
|
1098
|
+
@data_offset = MSG_TOTAL_HEADER_SIZE
|
1099
|
+
end
|
1100
|
+
|
1065
1101
|
def write_key(key, policy = nil)
|
1066
1102
|
# Write key into buffer.
|
1067
1103
|
if key.namespace
|
@@ -1199,15 +1235,6 @@ module Aerospike
|
|
1199
1235
|
@data_offset += 1
|
1200
1236
|
end
|
1201
1237
|
|
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
1238
|
def write_filter_exp(exp, exp_size)
|
1212
1239
|
unless exp.nil?
|
1213
1240
|
write_field_header(exp_size, Aerospike::FieldType::FILTER_EXP)
|
@@ -1238,7 +1265,7 @@ module Aerospike
|
|
1238
1265
|
|
1239
1266
|
def compress_buffer
|
1240
1267
|
if @data_offset > COMPRESS_THRESHOLD
|
1241
|
-
compressed = Zlib
|
1268
|
+
compressed = Zlib.deflate(@data_buffer.buf, Zlib::DEFAULT_COMPRESSION)
|
1242
1269
|
|
1243
1270
|
# write original size as header
|
1244
1271
|
proto_s = format("%08d", 0)
|