aerospike 2.19.0 → 2.26.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +354 -244
  3. data/lib/aerospike/atomic/atomic.rb +1 -1
  4. data/lib/aerospike/cdt/context.rb +137 -70
  5. data/lib/aerospike/cdt/list_return_type.rb +4 -0
  6. data/lib/aerospike/cdt/map_operation.rb +6 -6
  7. data/lib/aerospike/cdt/map_policy.rb +16 -2
  8. data/lib/aerospike/cdt/map_return_type.rb +13 -1
  9. data/lib/aerospike/client.rb +137 -115
  10. data/lib/aerospike/cluster/create_connection.rb +1 -1
  11. data/lib/aerospike/cluster.rb +41 -4
  12. data/lib/aerospike/command/admin_command.rb +368 -52
  13. data/lib/aerospike/command/batch_index_command.rb +4 -8
  14. data/lib/aerospike/command/batch_index_exists_command.rb +1 -1
  15. data/lib/aerospike/command/batch_index_node.rb +1 -1
  16. data/lib/aerospike/command/batch_item.rb +1 -1
  17. data/lib/aerospike/command/command.rb +180 -123
  18. data/lib/aerospike/command/field_type.rb +25 -24
  19. data/lib/aerospike/command/login_command.rb +164 -0
  20. data/lib/aerospike/command/multi_command.rb +25 -2
  21. data/lib/aerospike/command/operate_args.rb +99 -0
  22. data/lib/aerospike/command/operate_command.rb +6 -11
  23. data/lib/aerospike/command/read_command.rb +2 -2
  24. data/lib/aerospike/connection/authenticate.rb +36 -3
  25. data/lib/aerospike/exp/exp.rb +1329 -0
  26. data/lib/aerospike/exp/exp_bit.rb +388 -0
  27. data/lib/aerospike/exp/exp_hll.rb +169 -0
  28. data/lib/aerospike/exp/exp_list.rb +403 -0
  29. data/lib/aerospike/exp/exp_map.rb +493 -0
  30. data/lib/aerospike/exp/operation.rb +56 -0
  31. data/lib/aerospike/features.rb +22 -9
  32. data/lib/aerospike/host/parse.rb +2 -2
  33. data/lib/aerospike/key.rb +10 -1
  34. data/lib/aerospike/node/refresh/info.rb +1 -1
  35. data/lib/aerospike/node/verify/name.rb +1 -1
  36. data/lib/aerospike/node/verify/partition_generation.rb +1 -1
  37. data/lib/aerospike/node/verify/peers_generation.rb +1 -1
  38. data/lib/aerospike/node/verify/rebalance_generation.rb +1 -1
  39. data/lib/aerospike/node_validator.rb +6 -1
  40. data/lib/aerospike/operation.rb +20 -22
  41. data/lib/aerospike/policy/auth_mode.rb +36 -0
  42. data/lib/aerospike/policy/client_policy.rb +4 -1
  43. data/lib/aerospike/policy/policy.rb +29 -13
  44. data/lib/aerospike/policy/query_policy.rb +35 -2
  45. data/lib/aerospike/policy/scan_policy.rb +19 -2
  46. data/lib/aerospike/privilege.rb +133 -0
  47. data/lib/aerospike/query/filter.rb +44 -32
  48. data/lib/aerospike/query/node_partitions.rb +39 -0
  49. data/lib/aerospike/query/partition_filter.rb +66 -0
  50. data/lib/aerospike/{command/roles.rb → query/partition_status.rb} +16 -19
  51. data/lib/aerospike/query/partition_tracker.rb +347 -0
  52. data/lib/aerospike/query/query_command.rb +20 -10
  53. data/lib/aerospike/query/query_executor.rb +71 -0
  54. data/lib/aerospike/query/query_partition_command.rb +267 -0
  55. data/lib/aerospike/query/recordset.rb +9 -9
  56. data/lib/aerospike/query/scan_command.rb +3 -2
  57. data/lib/aerospike/query/scan_executor.rb +71 -0
  58. data/lib/aerospike/query/scan_partition_command.rb +49 -0
  59. data/lib/aerospike/query/statement.rb +8 -1
  60. data/lib/aerospike/query/stream_command.rb +17 -0
  61. data/lib/aerospike/result_code.rb +83 -8
  62. data/lib/aerospike/role.rb +55 -0
  63. data/lib/aerospike/task/execute_task.rb +19 -16
  64. data/lib/aerospike/task/index_task.rb +1 -1
  65. data/lib/aerospike/user_role.rb +26 -1
  66. data/lib/aerospike/utils/buffer.rb +93 -29
  67. data/lib/aerospike/utils/packer.rb +7 -6
  68. data/lib/aerospike/utils/pool.rb +1 -1
  69. data/lib/aerospike/value/particle_type.rb +1 -12
  70. data/lib/aerospike/value/value.rb +35 -60
  71. data/lib/aerospike/version.rb +1 -1
  72. data/lib/aerospike.rb +156 -136
  73. metadata +24 -6
@@ -15,18 +15,17 @@
15
15
  # License for the specific language governing permissions and limitations under
16
16
  # the License.
17
17
 
18
- require 'time'
19
- require 'zlib'
18
+ require "time"
19
+ require "zlib"
20
20
 
21
- require 'msgpack'
22
- require 'aerospike/result_code'
23
- require 'aerospike/command/field_type'
21
+ require "msgpack"
22
+ require "aerospike/result_code"
23
+ require "aerospike/command/field_type"
24
24
 
25
- require 'aerospike/policy/consistency_level'
26
- require 'aerospike/policy/commit_level'
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
@@ -66,6 +66,8 @@ module Aerospike
66
66
  INFO3_LAST = Integer(1 << 0)
67
67
  # Commit to master only before declaring success.
68
68
  INFO3_COMMIT_MASTER = Integer(1 << 1)
69
+ # Partition is complete response in scan.
70
+ INFO3_PARTITION_DONE = Integer(1 << 2)
69
71
  # Update only. Merge bins.
70
72
  INFO3_UPDATE_ONLY = Integer(1 << 3)
71
73
 
@@ -74,19 +76,18 @@ module Aerospike
74
76
  # Completely replace existing record only.
75
77
  INFO3_REPLACE_ONLY = Integer(1 << 5)
76
78
 
77
- MSG_TOTAL_HEADER_SIZE = 30
78
- FIELD_HEADER_SIZE = 5
79
- OPERATION_HEADER_SIZE = 8
80
- MSG_REMAINING_HEADER_SIZE = 22
81
- DIGEST_SIZE = 20
82
- COMPRESS_THRESHOLD = 128
83
- CL_MSG_VERSION = 2
84
- AS_MSG_TYPE = 3
85
- AS_MSG_TYPE_COMPRESSED = 4
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
86
88
 
87
89
  class Command #:nodoc:
88
-
89
- def initialize(node=nil)
90
+ def initialize(node = nil)
90
91
  @data_offset = 0
91
92
  @data_buffer = nil
92
93
 
@@ -110,10 +111,13 @@ module Aerospike
110
111
  def set_write(policy, operation, key, bins)
111
112
  begin_cmd
112
113
  field_count = estimate_key_size(key, policy)
113
-
114
+
114
115
  predexp_size = estimate_predexp(policy.predexp)
115
116
  field_count += 1 if predexp_size > 0
116
117
 
118
+ exp_size = estimate_expression_size(@policy.filter_exp)
119
+ field_count += 1 if exp_size > 0
120
+
117
121
  bins.each do |bin|
118
122
  estimate_operation_size_for_bin(bin)
119
123
  end
@@ -123,6 +127,7 @@ module Aerospike
123
127
  write_header_with_policy(policy, 0, INFO2_WRITE, field_count, bins.length)
124
128
  write_key(key, policy)
125
129
  write_predexp(policy.predexp, predexp_size)
130
+ write_filter_exp(@policy.filter_exp, exp_size)
126
131
 
127
132
  bins.each do |bin|
128
133
  write_operation_for_bin(bin, operation)
@@ -136,14 +141,18 @@ module Aerospike
136
141
  def set_delete(policy, key)
137
142
  begin_cmd
138
143
  field_count = estimate_key_size(key)
139
-
144
+
140
145
  predexp_size = estimate_predexp(policy.predexp)
141
146
  field_count += 1 if predexp_size > 0
142
147
 
148
+ exp_size = estimate_expression_size(@policy.filter_exp)
149
+ field_count += 1 if exp_size > 0
150
+
143
151
  size_buffer
144
- 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)
145
153
  write_key(key)
146
154
  write_predexp(policy.predexp, predexp_size)
155
+ write_filter_exp(@policy.filter_exp, exp_size)
147
156
  end_cmd
148
157
  end
149
158
 
@@ -151,15 +160,19 @@ module Aerospike
151
160
  def set_touch(policy, key)
152
161
  begin_cmd
153
162
  field_count = estimate_key_size(key)
154
-
163
+
155
164
  predexp_size = estimate_predexp(policy.predexp)
156
165
  field_count += 1 if predexp_size > 0
157
166
 
167
+ exp_size = estimate_expression_size(@policy.filter_exp)
168
+ field_count += 1 if exp_size > 0
169
+
158
170
  estimate_operation_size
159
171
  size_buffer
160
172
  write_header_with_policy(policy, 0, INFO2_WRITE, field_count, 1)
161
173
  write_key(key)
162
174
  write_predexp(policy.predexp, predexp_size)
175
+ write_filter_exp(@policy.filter_exp, exp_size)
163
176
  write_operation_for_operation_type(Aerospike::Operation::TOUCH)
164
177
  end_cmd
165
178
  end
@@ -168,14 +181,18 @@ module Aerospike
168
181
  def set_exists(policy, key)
169
182
  begin_cmd
170
183
  field_count = estimate_key_size(key)
171
-
184
+
172
185
  predexp_size = estimate_predexp(policy.predexp)
173
186
  field_count += 1 if predexp_size > 0
174
187
 
188
+ exp_size = estimate_expression_size(@policy.filter_exp)
189
+ field_count += 1 if exp_size > 0
190
+
175
191
  size_buffer
176
- write_header(policy, INFO1_READ|INFO1_NOBINDATA, 0, field_count, 0)
192
+ write_header(policy, INFO1_READ | INFO1_NOBINDATA, 0, field_count, 0)
177
193
  write_key(key)
178
194
  write_predexp(policy.predexp, predexp_size)
195
+ write_filter_exp(@policy.filter_exp, exp_size)
179
196
  end_cmd
180
197
  end
181
198
 
@@ -183,14 +200,18 @@ module Aerospike
183
200
  def set_read_for_key_only(policy, key)
184
201
  begin_cmd
185
202
  field_count = estimate_key_size(key)
186
-
203
+
187
204
  predexp_size = estimate_predexp(policy.predexp)
188
205
  field_count += 1 if predexp_size > 0
189
206
 
207
+ exp_size = estimate_expression_size(@policy.filter_exp)
208
+ field_count += 1 if exp_size > 0
209
+
190
210
  size_buffer
191
- 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)
192
212
  write_key(key)
193
213
  write_predexp(policy.predexp, predexp_size)
214
+ write_filter_exp(@policy.filter_exp, exp_size)
194
215
  end_cmd
195
216
  end
196
217
 
@@ -199,10 +220,12 @@ module Aerospike
199
220
  if bin_names && bin_names.length > 0
200
221
  begin_cmd
201
222
  field_count = estimate_key_size(key)
202
-
223
+
203
224
  predexp_size = estimate_predexp(policy.predexp)
204
225
  field_count += 1 if predexp_size > 0
205
226
 
227
+ exp_size = estimate_expression_size(@policy.filter_exp)
228
+ field_count += 1 if exp_size > 0
206
229
 
207
230
  bin_names.each do |bin_name|
208
231
  estimate_operation_size_for_bin_name(bin_name)
@@ -212,6 +235,7 @@ module Aerospike
212
235
  write_header(policy, INFO1_READ, 0, field_count, bin_names.length)
213
236
  write_key(key)
214
237
  write_predexp(policy.predexp, predexp_size)
238
+ write_filter_exp(@policy.filter_exp, exp_size)
215
239
 
216
240
  bin_names.each do |bin_name|
217
241
  write_operation_for_bin_name(bin_name, Aerospike::Operation::READ)
@@ -227,11 +251,14 @@ module Aerospike
227
251
  def set_read_header(policy, key)
228
252
  begin_cmd
229
253
  field_count = estimate_key_size(key)
230
-
254
+
231
255
  predexp_size = estimate_predexp(policy.predexp)
232
256
  field_count += 1 if predexp_size > 0
233
257
 
234
- estimate_operation_size_for_bin_name('')
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("")
235
262
  size_buffer
236
263
 
237
264
  # The server does not currently return record header data with _INFO1_NOBINDATA attribute set.
@@ -242,70 +269,35 @@ module Aerospike
242
269
 
243
270
  write_key(key)
244
271
  write_predexp(policy.predexp, predexp_size)
245
- write_operation_for_bin_name('', Aerospike::Operation::READ)
272
+ write_filter_exp(@policy.filter_exp, exp_size)
273
+ write_operation_for_bin_name("", Aerospike::Operation::READ)
246
274
  end_cmd
247
275
  end
248
276
 
249
277
  # Implements different command operations
250
- def set_operate(policy, key, operations)
278
+ def set_operate(policy, key, args)
251
279
  begin_cmd
252
280
  field_count = estimate_key_size(key, policy)
253
-
281
+
254
282
  predexp_size = estimate_predexp(policy.predexp)
255
283
  field_count += 1 if predexp_size > 0
256
284
 
257
- read_attr = 0
258
- write_attr = 0
259
- read_header = false
260
- record_bin_multiplicity = policy.record_bin_multiplicity == RecordBinMultiplicity::ARRAY
261
-
262
- operations.each do |operation|
263
- case operation.op_type
264
- when Aerospike::Operation::READ, Aerospike::Operation::CDT_READ,
265
- Aerospike::Operation::HLL_READ, Aerospike::Operation::BIT_READ
266
- read_attr |= INFO1_READ
267
-
268
- # Read all bins if no bin is specified.
269
- read_attr |= INFO1_GET_ALL unless operation.bin_name
270
-
271
- when Aerospike::Operation::READ_HEADER
272
- # The server does not currently return record header data with _INFO1_NOBINDATA attribute set.
273
- # The workaround is to request a non-existent bin.
274
- # TODO: Fix this on server.
275
- # read_attr |= _INFO1_READ | _INFO1_NOBINDATA
276
- read_attr |= INFO1_READ
277
- read_header = true
278
-
279
- else
280
- write_attr = INFO2_WRITE
281
- end
285
+ exp_size = estimate_expression_size(policy.filter_exp)
286
+ field_count += 1 if exp_size > 0
282
287
 
283
- if [Aerospike::Operation::HLL_MODIFY, Aerospike::Operation::HLL_READ,
284
- Aerospike::Operation::BIT_MODIFY, Aerospike::Operation::BIT_READ].include?(operation.op_type)
285
- record_bin_multiplicity = true
286
- end
288
+ @data_offset += args.size
287
289
 
288
- estimate_operation_size_for_operation(operation)
289
- end
290
290
  size_buffer
291
291
 
292
-
293
- write_attr |= INFO2_RESPOND_ALL_OPS if write_attr != 0 && record_bin_multiplicity
294
-
295
- if write_attr != 0
296
- write_header_with_policy(policy, read_attr, write_attr, field_count, operations.length)
297
- else
298
- write_header(policy, read_attr, write_attr, field_count, operations.length)
299
- end
292
+ write_header_with_policy(policy, args.read_attr, args.write_attr, field_count, args.operations.length)
300
293
  write_key(key, policy)
301
294
  write_predexp(policy.predexp, predexp_size)
295
+ write_filter_exp(policy.filter_exp, exp_size)
302
296
 
303
- operations.each do |operation|
297
+ args.operations.each do |operation|
304
298
  write_operation_for_operation(operation)
305
299
  end
306
300
 
307
- write_operation_for_bin(nil, Aerospike::Operation::READ) if read_header
308
-
309
301
  end_cmd
310
302
  mark_compressed(policy)
311
303
  end
@@ -313,10 +305,13 @@ module Aerospike
313
305
  def set_udf(policy, key, package_name, function_name, args)
314
306
  begin_cmd
315
307
  field_count = estimate_key_size(key, policy)
316
-
308
+
317
309
  predexp_size = estimate_predexp(policy.predexp)
318
310
  field_count += 1 if predexp_size > 0
319
311
 
312
+ exp_size = estimate_expression_size(@policy.filter_exp)
313
+ field_count += 1 if exp_size > 0
314
+
320
315
  arg_bytes = args.to_bytes
321
316
 
322
317
  field_count += estimate_udf_size(package_name, function_name, arg_bytes)
@@ -325,6 +320,7 @@ module Aerospike
325
320
  write_header(policy, 0, INFO2_WRITE, field_count, 0)
326
321
  write_key(key, policy)
327
322
  write_predexp(policy.predexp, predexp_size)
323
+ write_filter_exp(@policy.filter_exp, exp_size)
328
324
  write_field_string(package_name, Aerospike::FieldType::UDF_PACKAGE_NAME)
329
325
  write_field_string(function_name, Aerospike::FieldType::UDF_FUNCTION)
330
326
  write_field_bytes(arg_bytes, Aerospike::FieldType::UDF_ARGLIST)
@@ -333,11 +329,15 @@ module Aerospike
333
329
  mark_compressed(policy)
334
330
  end
335
331
 
336
- def set_scan(policy, namespace, set_name, bin_names)
332
+ def set_scan(policy, namespace, set_name, bin_names, node_partitions)
337
333
  # Estimate buffer size
338
334
  begin_cmd
339
335
  field_count = 0
340
336
 
337
+ parts_full_size = node_partitions.parts_full.length * 2
338
+ parts_partial_size = node_partitions.parts_partial.length * 20
339
+ max_records = node_partitions.record_max
340
+
341
341
  if namespace
342
342
  @data_offset += namespace.bytesize + FIELD_HEADER_SIZE
343
343
  field_count += 1
@@ -347,7 +347,22 @@ module Aerospike
347
347
  @data_offset += set_name.bytesize + FIELD_HEADER_SIZE
348
348
  field_count += 1
349
349
  end
350
-
350
+
351
+ if parts_full_size > 0
352
+ @data_offset += parts_full_size + FIELD_HEADER_SIZE
353
+ field_count += 1
354
+ end
355
+
356
+ if parts_partial_size > 0
357
+ @data_offset += parts_partial_size + FIELD_HEADER_SIZE
358
+ field_count += 1
359
+ end
360
+
361
+ if max_records > 0
362
+ @data_offset += 8 + FIELD_HEADER_SIZE
363
+ field_count += 1
364
+ end
365
+
351
366
  if policy.records_per_second > 0
352
367
  @data_offset += 4 + FIELD_HEADER_SIZE
353
368
  field_count += 1
@@ -356,9 +371,12 @@ module Aerospike
356
371
  predexp_size = estimate_predexp(policy.predexp)
357
372
  field_count += 1 if predexp_size > 0
358
373
 
374
+ exp_size = estimate_expression_size(@policy.filter_exp)
375
+ field_count += 1 if exp_size > 0
376
+
359
377
  # Estimate scan options size.
360
- @data_offset += 2 + FIELD_HEADER_SIZE
361
- field_count += 1
378
+ # @data_offset += 2 + FIELD_HEADER_SIZE
379
+ # field_count += 1
362
380
 
363
381
  # Estimate scan timeout size.
364
382
  @data_offset += 4 + FIELD_HEADER_SIZE
@@ -373,7 +391,7 @@ module Aerospike
373
391
  size_buffer
374
392
  read_attr = INFO1_READ
375
393
 
376
- if !policy.include_bin_data
394
+ unless policy.include_bin_data
377
395
  read_attr |= INFO1_NOBINDATA
378
396
  end
379
397
 
@@ -392,26 +410,49 @@ module Aerospike
392
410
  write_field_string(set_name, Aerospike::FieldType::TABLE)
393
411
  end
394
412
 
413
+ if parts_full_size > 0
414
+ write_field_header(parts_full_size, Aerospike::FieldType::PID_ARRAY)
415
+
416
+ node_partitions.parts_full.each do |part|
417
+ @data_buffer.write_uint16_little_endian(part.id, @data_offset)
418
+ @data_offset += 2
419
+ end
420
+ end
421
+
422
+ if parts_partial_size > 0
423
+ write_field_header(parts_partial_size, Aerospike::FieldType::DIGEST_ARRAY)
424
+
425
+ node_partitions.parts_partial.each do |part|
426
+ @data_buffer.write_binary(part.digest, @data_offset)
427
+ @data_offset += part.digest.length
428
+ end
429
+ end
430
+
431
+ if max_records > 0
432
+ write_field_int64(max_records, Aerospike::FieldType::MAX_RECORDS)
433
+ end
434
+
395
435
  if policy.records_per_second > 0
396
436
  write_field_int(policy.records_per_second, Aerospike::FieldType::RECORDS_PER_SECOND)
397
437
  end
398
438
 
399
439
  write_predexp(policy.predexp, predexp_size)
440
+ write_filter_exp(@policy.filter_exp, exp_size)
400
441
 
401
- write_field_header(2, Aerospike::FieldType::SCAN_OPTIONS)
442
+ # write_field_header(2, Aerospike::FieldType::SCAN_OPTIONS)
402
443
 
403
- priority = policy.priority & 0xFF
404
- priority <<= 4
405
- if policy.fail_on_cluster_change
406
- priority |= 0x08
407
- end
444
+ # priority = policy.priority & 0xFF
445
+ # priority <<= 4
446
+ # if policy.fail_on_cluster_change
447
+ # priority |= 0x08
448
+ # end
408
449
 
409
- @data_buffer.write_byte(priority, @data_offset)
410
- @data_offset += 1
411
- @data_buffer.write_byte(policy.scan_percent.to_i.ord, @data_offset)
412
- @data_offset += 1
450
+ # @data_buffer.write_byte(priority, @data_offset)
451
+ # @data_offset += 1
452
+ # @data_buffer.write_byte(policy.scan_percent.to_i.ord, @data_offset)
453
+ # @data_offset += 1
413
454
 
414
- write_field_header(4, Aerospike::FieldType::SCAN_TIMEOUT)
455
+ write_field_header(4, Aerospike::FieldType::SOCKET_TIMEOUT)
415
456
  @data_buffer.write_uint32(policy.socket_timeout.to_i, @data_offset)
416
457
  @data_offset += 4
417
458
 
@@ -434,7 +475,7 @@ module Aerospike
434
475
  while true
435
476
  # too many retries
436
477
  iterations += 1
437
- break if (@policy.max_retries > 0) && (iterations > @policy.max_retries+1)
478
+ break if (@policy.max_retries > 0) && (iterations > @policy.max_retries + 1)
438
479
 
439
480
  # Sleep before trying again, after the first iteration
440
481
  sleep(@policy.sleep_between_retries) if iterations > 1 && @policy.sleep_between_retries > 0
@@ -522,7 +563,6 @@ module Aerospike
522
563
  ensure
523
564
  Buffer.put(@data_buffer)
524
565
  end
525
-
526
566
  end # while
527
567
 
528
568
  # execution timeout
@@ -531,7 +571,6 @@ module Aerospike
531
571
 
532
572
  protected
533
573
 
534
-
535
574
  def estimate_key_size(key, policy = nil)
536
575
  field_count = 0
537
576
 
@@ -601,6 +640,15 @@ module Aerospike
601
640
  return 0
602
641
  end
603
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
+
604
652
  # Generic header write.
605
653
  def write_header(policy, read_attr, write_attr, field_count, operation_count)
606
654
  read_attr |= INFO1_CONSISTENCY_ALL if policy.consistency_level == Aerospike::ConsistencyLevel::CONSISTENCY_ALL
@@ -672,7 +720,6 @@ module Aerospike
672
720
  @data_buffer.write_byte(0, 24)
673
721
  @data_buffer.write_byte(0, 25)
674
722
 
675
-
676
723
  @data_buffer.write_int16(field_count, 26)
677
724
  @data_buffer.write_int16(operation_count, 28)
678
725
 
@@ -694,15 +741,14 @@ module Aerospike
694
741
  if policy && policy.respond_to?(:send_key) && policy.send_key == true
695
742
  write_field_value(key.user_key_as_value, Aerospike::FieldType::KEY)
696
743
  end
697
-
698
744
  end
699
745
 
700
746
  def write_operation_for_bin(bin, operation)
701
- name_length = @data_buffer.write_binary(bin.name, @data_offset+OPERATION_HEADER_SIZE)
702
- 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)
703
749
 
704
750
  # Buffer.Int32ToBytes(name_length+value_length+4, @data_buffer, @data_offset)
705
- @data_buffer.write_int32(name_length+value_length+4, @data_offset)
751
+ @data_buffer.write_int32(name_length + value_length + 4, @data_offset)
706
752
 
707
753
  @data_offset += 4
708
754
  @data_buffer.write_byte(operation, @data_offset)
@@ -719,13 +765,13 @@ module Aerospike
719
765
  def write_operation_for_operation(operation)
720
766
  name_length = 0
721
767
  if operation.bin_name
722
- 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)
723
769
  end
724
770
 
725
- 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)
726
772
 
727
773
  # Buffer.Int32ToBytes(name_length+value_length+4, @data_buffer, @data_offset)
728
- @data_buffer.write_int32(name_length+value_length+4, @data_offset)
774
+ @data_buffer.write_int32(name_length + value_length + 4, @data_offset)
729
775
 
730
776
  @data_offset += 4
731
777
  @data_buffer.write_byte(operation.op_type, @data_offset)
@@ -740,9 +786,9 @@ module Aerospike
740
786
  end
741
787
 
742
788
  def write_operation_for_bin_name(name, operation)
743
- 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)
744
790
  # Buffer.Int32ToBytes(name_length+4, @data_buffer, @data_offset)
745
- @data_buffer.write_int32(name_length+4, @data_offset)
791
+ @data_buffer.write_int32(name_length + 4, @data_offset)
746
792
 
747
793
  @data_offset += 4
748
794
  @data_buffer.write_byte(operation, @data_offset)
@@ -781,25 +827,37 @@ module Aerospike
781
827
  end
782
828
 
783
829
  def write_field_string(str, ftype)
784
- len = @data_buffer.write_binary(str, @data_offset+FIELD_HEADER_SIZE)
830
+ len = @data_buffer.write_binary(str, @data_offset + FIELD_HEADER_SIZE)
785
831
  write_field_header(len, ftype)
786
832
  @data_offset += len
787
833
  end
788
834
 
835
+ def write_u16_little_endian(i, ftype)
836
+ @data_buffer.write_uint16_little_endian(i, @data_offset + FIELD_HEADER_SIZE)
837
+ write_field_header(2, ftype)
838
+ @data_offset += 2
839
+ end
840
+
789
841
  def write_field_int(i, ftype)
790
- @data_buffer.write_int32(i, @data_offset+FIELD_HEADER_SIZE)
842
+ @data_buffer.write_int32(i, @data_offset + FIELD_HEADER_SIZE)
791
843
  write_field_header(4, ftype)
792
844
  @data_offset += 4
793
845
  end
794
846
 
847
+ def write_field_int64(i, ftype)
848
+ @data_buffer.write_int64(i, @data_offset + FIELD_HEADER_SIZE)
849
+ write_field_header(8, ftype)
850
+ @data_offset += 8
851
+ end
852
+
795
853
  def write_field_bytes(bytes, ftype)
796
- @data_buffer.write_binary(bytes, @data_offset+FIELD_HEADER_SIZE)
854
+ @data_buffer.write_binary(bytes, @data_offset + FIELD_HEADER_SIZE)
797
855
  write_field_header(bytes.bytesize, ftype)
798
856
  @data_offset += bytes.bytesize
799
857
  end
800
858
 
801
859
  def write_field_header(size, ftype)
802
- @data_buffer.write_int32(size+1, @data_offset)
860
+ @data_buffer.write_int32(size + 1, @data_offset)
803
861
  @data_offset += 4
804
862
  @data_buffer.write_byte(ftype, @data_offset)
805
863
  @data_offset += 1
@@ -807,13 +865,20 @@ module Aerospike
807
865
 
808
866
  def write_predexp(predexp, predexp_size)
809
867
  if predexp && predexp.size > 0
810
- write_field_header(predexp_size, Aerospike::FieldType::PREDEXP)
868
+ write_field_header(predexp_size, Aerospike::FieldType::FILTER_EXP)
811
869
  @data_offset = Aerospike::PredExp.write(
812
870
  predexp, @data_buffer, @data_offset
813
871
  )
814
872
  end
815
873
  end
816
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
+
817
882
  def begin_cmd
818
883
  @data_offset = MSG_TOTAL_HEADER_SIZE
819
884
  end
@@ -823,17 +888,11 @@ module Aerospike
823
888
  end
824
889
 
825
890
  def size_buffer_sz(size)
826
- # Corrupted data streams can result in a hug.length.
827
- # Do a sanity check here.
828
- if size > Buffer::MAX_BUFFER_SIZE
829
- raise Aerospike::Exceptions::Parse.new("Invalid size for buffer: #{size}")
830
- end
831
-
832
891
  @data_buffer.resize(size)
833
892
  end
834
893
 
835
894
  def end_cmd
836
- 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)
837
896
  @data_buffer.write_int64(size, 0)
838
897
  end
839
898
 
@@ -847,13 +906,13 @@ module Aerospike
847
906
 
848
907
  # write original size as header
849
908
  proto_s = "%08d" % 0
850
- proto_s[0, 8] = [@data_offset].pack('q>')
909
+ proto_s[0, 8] = [@data_offset].pack("q>")
851
910
  compressed.prepend(proto_s)
852
911
 
853
912
  # write proto
854
- 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)
855
914
  proto_s = "%08d" % 0
856
- proto_s[0, 8] = [proto].pack('q>')
915
+ proto_s[0, 8] = [proto].pack("q>")
857
916
  compressed.prepend(proto_s)
858
917
 
859
918
  @data_buffer = Buffer.new(-1, compressed)
@@ -878,7 +937,5 @@ module Aerospike
878
937
  def mark_compressed(policy)
879
938
  @compress = policy.use_compression
880
939
  end
881
-
882
940
  end # class
883
-
884
941
  end # module