aerospike 2.11.0 → 2.16.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.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +50 -1
  3. data/README.md +1 -1
  4. data/lib/aerospike.rb +17 -4
  5. data/lib/aerospike/aerospike_exception.rb +7 -1
  6. data/lib/aerospike/atomic/atomic.rb +1 -1
  7. data/lib/aerospike/bin.rb +1 -1
  8. data/lib/aerospike/cdt/bit_operation.rb +376 -0
  9. data/lib/aerospike/cdt/bit_overflow_action.rb +46 -0
  10. data/lib/aerospike/cdt/bit_policy.rb +36 -0
  11. data/lib/aerospike/cdt/bit_resize_flags.rb +44 -0
  12. data/lib/aerospike/cdt/bit_write_flags.rb +51 -0
  13. data/lib/aerospike/cdt/context.rb +101 -0
  14. data/lib/aerospike/cdt/hll_operation.rb +200 -0
  15. data/lib/aerospike/cdt/hll_policy.rb +34 -0
  16. data/lib/aerospike/cdt/hll_write_flags.rb +53 -0
  17. data/lib/aerospike/cdt/list_operation.rb +127 -97
  18. data/lib/aerospike/cdt/list_sort_flags.rb +10 -2
  19. data/lib/aerospike/cdt/map_operation.rb +154 -93
  20. data/lib/aerospike/cdt/map_order.rb +1 -1
  21. data/lib/aerospike/cdt/map_policy.rb +1 -1
  22. data/lib/aerospike/cdt/map_return_type.rb +1 -1
  23. data/lib/aerospike/cdt/map_write_mode.rb +1 -1
  24. data/lib/aerospike/client.rb +33 -17
  25. data/lib/aerospike/cluster.rb +139 -17
  26. data/lib/aerospike/cluster/partition.rb +1 -1
  27. data/lib/aerospike/cluster/partition_parser.rb +169 -0
  28. data/lib/aerospike/cluster/rack_parser.rb +117 -0
  29. data/lib/aerospike/command/admin_command.rb +1 -1
  30. data/lib/aerospike/command/batch_direct_command.rb +2 -1
  31. data/lib/aerospike/command/batch_direct_exists_command.rb +1 -1
  32. data/lib/aerospike/command/batch_direct_node.rb +3 -3
  33. data/lib/aerospike/command/batch_index_command.rb +11 -2
  34. data/lib/aerospike/command/batch_index_node.rb +2 -2
  35. data/lib/aerospike/command/batch_item.rb +1 -1
  36. data/lib/aerospike/command/command.rb +168 -12
  37. data/lib/aerospike/command/delete_command.rb +21 -5
  38. data/lib/aerospike/command/execute_command.rb +1 -1
  39. data/lib/aerospike/command/exists_command.rb +21 -5
  40. data/lib/aerospike/command/field_type.rb +2 -1
  41. data/lib/aerospike/command/multi_command.rb +55 -5
  42. data/lib/aerospike/command/operate_command.rb +6 -1
  43. data/lib/aerospike/command/read_command.rb +63 -20
  44. data/lib/aerospike/command/read_header_command.rb +18 -6
  45. data/lib/aerospike/command/roles.rb +1 -1
  46. data/lib/aerospike/command/single_command.rb +9 -3
  47. data/lib/aerospike/command/touch_command.rb +48 -4
  48. data/lib/aerospike/command/unsupported_particle_type_validator.rb +1 -1
  49. data/lib/aerospike/command/write_command.rb +13 -4
  50. data/lib/aerospike/connection/create.rb +1 -1
  51. data/lib/aerospike/features.rb +6 -1
  52. data/lib/aerospike/geo_json.rb +1 -1
  53. data/lib/aerospike/host.rb +1 -1
  54. data/lib/aerospike/info.rb +1 -1
  55. data/lib/aerospike/key.rb +1 -1
  56. data/lib/aerospike/language.rb +1 -1
  57. data/lib/aerospike/node.rb +21 -7
  58. data/lib/aerospike/node/rebalance.rb +50 -0
  59. data/lib/aerospike/node/refresh/info.rb +4 -1
  60. data/lib/aerospike/node/refresh/partitions.rb +6 -15
  61. data/lib/aerospike/node/refresh/racks.rb +47 -0
  62. data/lib/aerospike/node/refresh/reset.rb +1 -0
  63. data/lib/aerospike/node/verify/rebalance_generation.rb +43 -0
  64. data/lib/aerospike/node_validator.rb +4 -19
  65. data/lib/aerospike/operation.rb +13 -3
  66. data/lib/aerospike/policy/admin_policy.rb +1 -1
  67. data/lib/aerospike/policy/batch_policy.rb +1 -1
  68. data/lib/aerospike/policy/client_policy.rb +16 -1
  69. data/lib/aerospike/policy/commit_level.rb +1 -1
  70. data/lib/aerospike/policy/consistency_level.rb +1 -1
  71. data/lib/aerospike/policy/generation_policy.rb +1 -1
  72. data/lib/aerospike/policy/operate_policy.rb +1 -1
  73. data/lib/aerospike/policy/policy.rb +64 -2
  74. data/lib/aerospike/policy/priority.rb +1 -1
  75. data/lib/aerospike/policy/query_policy.rb +8 -1
  76. data/lib/aerospike/policy/record_bin_multiplicity.rb +1 -1
  77. data/lib/aerospike/policy/record_exists_action.rb +1 -1
  78. data/lib/aerospike/policy/replica.rb +45 -0
  79. data/lib/aerospike/policy/scan_policy.rb +8 -1
  80. data/lib/aerospike/policy/write_policy.rb +1 -1
  81. data/lib/aerospike/query/filter.rb +1 -1
  82. data/lib/aerospike/query/query_command.rb +16 -5
  83. data/lib/aerospike/query/recordset.rb +1 -1
  84. data/lib/aerospike/query/scan_command.rb +1 -1
  85. data/lib/aerospike/query/statement.rb +9 -2
  86. data/lib/aerospike/query/stream_command.rb +1 -1
  87. data/lib/aerospike/record.rb +1 -1
  88. data/lib/aerospike/result_code.rb +26 -7
  89. data/lib/aerospike/socket/base.rb +4 -3
  90. data/lib/aerospike/task/execute_task.rb +1 -1
  91. data/lib/aerospike/task/index_task.rb +1 -1
  92. data/lib/aerospike/task/task.rb +1 -1
  93. data/lib/aerospike/task/udf_register_task.rb +1 -1
  94. data/lib/aerospike/task/udf_remove_task.rb +1 -1
  95. data/lib/aerospike/ttl.rb +1 -1
  96. data/lib/aerospike/udf.rb +1 -1
  97. data/lib/aerospike/user_role.rb +1 -1
  98. data/lib/aerospike/utils/buffer.rb +14 -4
  99. data/lib/aerospike/utils/packer.rb +1 -1
  100. data/lib/aerospike/utils/pool.rb +1 -1
  101. data/lib/aerospike/utils/unpacker.rb +1 -1
  102. data/lib/aerospike/value/particle_type.rb +2 -2
  103. data/lib/aerospike/value/value.rb +165 -33
  104. data/lib/aerospike/version.rb +1 -1
  105. metadata +20 -8
  106. data/lib/aerospike/cluster/partition_tokenizer_new.rb +0 -130
  107. data/lib/aerospike/cluster/partition_tokenizer_old.rb +0 -135
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- # Copyright 2014-2017 Aerospike, Inc.
2
+ # Copyright 2014-2020 Aerospike, Inc.
3
3
  #
4
4
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
5
5
  # license agreements.
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- # Copyright 2014-2017 Aerospike, Inc.
2
+ # Copyright 2014-2020 Aerospike, Inc.
3
3
  #
4
4
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
5
5
  # license agreements.
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- # Copyright 2014-2017 Aerospike, Inc.
2
+ # Copyright 2014-2020 Aerospike, Inc.
3
3
  #
4
4
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
5
5
  # license agreements.
@@ -43,7 +43,14 @@ module Aerospike
43
43
  # aggregation function.
44
44
  @filters = []
45
45
 
46
- # Predicate expressions
46
+ # Predicate expressions in postfix notation. If the expression is evaluated to false,
47
+ # the record will be ommited in the results.
48
+ #
49
+ # This method is redundant because PredExp can now be set in the base Policy for
50
+ # any transaction (including queries).
51
+ #
52
+ # NOTE : Policy.predexp takes precedence to this value. This value will be
53
+ # deprecated in the future.
47
54
  @predexp = nil
48
55
 
49
56
  @package_name = nil
@@ -1,4 +1,4 @@
1
- # Copyright 2014-2018 Aerospike, Inc.
1
+ # Copyright 2014-2020 Aerospike, Inc.
2
2
  #
3
3
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
4
4
  # license agreements.
@@ -1,4 +1,4 @@
1
- # Copyright 2014-2018 Aerospike, Inc.
1
+ # Copyright 2014-2020 Aerospike, Inc.
2
2
  #
3
3
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
4
4
  # license agreements.
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- # Copyright 2014-2017 Aerospike, Inc.
2
+ # Copyright 2014-2020 Aerospike, Inc.
3
3
  #
4
4
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
5
5
  # license agreements.
@@ -60,6 +60,10 @@ module Aerospike
60
60
  # exists.
61
61
  KEY_EXISTS_ERROR = 5
62
62
 
63
+ # Bin already exists on a create-only operation.
64
+ BIN_EXISTS_ERROR = 6
65
+
66
+
63
67
  # Expected cluster ID was not received.
64
68
  CLUSTER_KEY_MISMATCH = 7
65
69
 
@@ -91,6 +95,9 @@ module Aerospike
91
95
  # Unsupported Server Feature (e.g. Scan + UDF)
92
96
  UNSUPPORTED_FEATURE = 16
93
97
 
98
+ # Bin not found on update-only operation.
99
+ BIN_NOT_FOUND = 17
100
+
94
101
  # Specified bin name does not exist in record.
95
102
  DEVICE_OVERLOAD = 18
96
103
 
@@ -116,6 +123,12 @@ module Aerospike
116
123
  # Enterprise-only feature not supported by the community edition
117
124
  ENTERPRISE_ONLY = 25
118
125
 
126
+ # The operation cannot be applied to the current bin value on the server.
127
+ OP_NOT_APPLICABLE = 26
128
+
129
+ # The transaction was not performed because the predexp was false.
130
+ FILTERED_OUT = 27
131
+
119
132
  # There are no more records left for query.
120
133
  QUERY_END = 50
121
134
 
@@ -167,9 +180,6 @@ module Aerospike
167
180
  # A user defined function returned an error code.
168
181
  UDF_BAD_RESPONSE = 100
169
182
 
170
- # The requested item in a large collection was not found.
171
- LARGE_ITEM_NOT_FOUND = 125
172
-
173
183
  # Secondary index already exists.
174
184
  INDEX_FOUND = 200
175
185
 
@@ -241,6 +251,9 @@ module Aerospike
241
251
  when KEY_EXISTS_ERROR
242
252
  "Key already exists"
243
253
 
254
+ when BIN_EXISTS_ERROR
255
+ "Bin already exists on a create-only operation"
256
+
244
257
  when CLUSTER_KEY_MISMATCH
245
258
  "Cluster key mismatch"
246
259
 
@@ -271,6 +284,9 @@ module Aerospike
271
284
  when UNSUPPORTED_FEATURE
272
285
  "Unsupported Server Feature"
273
286
 
287
+ when BIN_NOT_FOUND
288
+ "Bin not found on update-only operation"
289
+
274
290
  when DEVICE_OVERLOAD
275
291
  "Device overload"
276
292
 
@@ -295,6 +311,12 @@ module Aerospike
295
311
  when ENTERPRISE_ONLY
296
312
  "Enterprise-only feature not supported by community edition"
297
313
 
314
+ when OP_NOT_APPLICABLE
315
+ "The operation cannot be applied to the current bin value on the server."
316
+
317
+ when FILTERED_OUT
318
+ "The transaction was not performed because the predexp was false."
319
+
298
320
  when QUERY_END
299
321
  "Query end"
300
322
 
@@ -352,9 +374,6 @@ module Aerospike
352
374
  when UDF_BAD_RESPONSE
353
375
  "UDF d error"
354
376
 
355
- when LARGE_ITEM_NOT_FOUND
356
- "Large collection item not found"
357
-
358
377
  when INDEX_FOUND
359
378
  "Index already exists"
360
379
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2014-2018 Aerospike, Inc.
3
+ # Copyright 2014-2020 Aerospike, Inc.
4
4
  #
5
5
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
6
6
  # license agreements.
@@ -25,13 +25,14 @@ module Aerospike
25
25
  @timeout = nil
26
26
  end
27
27
 
28
- def read(buffer, length)
28
+ def read(buffer, length, offset = 0)
29
29
  bytes_read = 0
30
30
  until bytes_read >= length
31
31
  result = read_from_socket(length - bytes_read)
32
- buffer.write_binary(result, bytes_read)
32
+ buffer.write_binary(result, offset + bytes_read)
33
33
  bytes_read += result.bytesize
34
34
  end
35
+ bytes_read
35
36
  end
36
37
 
37
38
  def read_from_socket(length)
@@ -1,4 +1,4 @@
1
- # Copyright 2013-2017 Aerospike, Inc.
1
+ # Copyright 2013-2020 Aerospike, Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- # Copyright 2014-2017 Aerospike, Inc.
2
+ # Copyright 2014-2020 Aerospike, Inc.
3
3
  #
4
4
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
5
5
  # license agreements.
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- # Copyright 2014-2017 Aerospike, Inc.
2
+ # Copyright 2014-2020 Aerospike, Inc.
3
3
  #
4
4
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
5
5
  # license agreements.
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- # Copyright 2014-2017 Aerospike, Inc.
2
+ # Copyright 2014-2020 Aerospike, Inc.
3
3
  #
4
4
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
5
5
  # license agreements.
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- # Copyright 2014-2017 Aerospike, Inc.
2
+ # Copyright 2014-2020 Aerospike, Inc.
3
3
  #
4
4
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
5
5
  # license agreements.
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- # Copyright 2016-2017 Aerospike, Inc.
2
+ # Copyright 2016-2020 Aerospike, Inc.
3
3
  #
4
4
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
5
5
  # license agreements.
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- # Copyright 2014-2017 Aerospike, Inc.
2
+ # Copyright 2014-2020 Aerospike, Inc.
3
3
  #
4
4
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
5
5
  # license agreements.
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- # Copyright 2014-2017 Aerospike, Inc.
2
+ # Copyright 2014-2020 Aerospike, Inc.
3
3
  #
4
4
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
5
5
  # license agreements.
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- # Copyright 2014-2018 Aerospike, Inc.
3
+ # Copyright 2014-2020 Aerospike, Inc.
4
4
  #
5
5
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
6
6
  # license agreements.
@@ -42,9 +42,9 @@ module Aerospike
42
42
  DEFAULT_BUFFER_SIZE = 16 * 1024
43
43
  MAX_BUFFER_SIZE = 10 * 1024 * 1024
44
44
 
45
- def initialize(size=DEFAULT_BUFFER_SIZE)
46
- @buf = "%0#{size}d" % 0
47
-
45
+ def initialize(size=DEFAULT_BUFFER_SIZE, buf = nil)
46
+ @buf = (buf ? buf : ("%0#{size}d" % 0))
47
+ @buf.force_encoding('binary')
48
48
  @slice_end = @buf.bytesize
49
49
  end
50
50
 
@@ -61,6 +61,10 @@ module Aerospike
61
61
  end
62
62
  alias_method :length, :size
63
63
 
64
+ def eat!(n)
65
+ @buf.replace(@buf[n..-1])
66
+ end
67
+
64
68
  def resize(length)
65
69
  if @buf.bytesize < length
66
70
  @buf.concat("%0#{length - @buf.bytesize}d" % 0)
@@ -156,6 +160,12 @@ module Aerospike
156
160
  @buf[0..@slice_end-1]
157
161
  end
158
162
 
163
+ def reset
164
+ for i in 0..@buf.size-1
165
+ @buf[i] = ' '
166
+ end
167
+ end
168
+
159
169
  def dump(from=nil, to=nil)
160
170
  from ||= 0
161
171
  to ||= @slice_end - 1
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- # Copyright 2016-2017 Aerospike, Inc.
2
+ # Copyright 2016-2020 Aerospike, Inc.
3
3
  #
4
4
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
5
5
  # license agreements.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- # Copyright 2014-2018 Aerospike, Inc.
2
+ # Copyright 2014-2020 Aerospike, Inc.
3
3
  #
4
4
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
5
5
  # license agreements.
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- # Copyright 2016-2018 Aerospike, Inc.
2
+ # Copyright 2016-2020 Aerospike, Inc.
3
3
  #
4
4
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
5
5
  # license agreements.
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- # Copyright 2014-2017 Aerospike, Inc.
2
+ # Copyright 2014-2020 Aerospike, Inc.
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License")
5
5
  # you may not use this file except in compliance with the License.
@@ -36,7 +36,7 @@ module Aerospike
36
36
  #RTA_DICT = 15
37
37
  #RTA_APPEND_DICT = 16
38
38
  #RTA_APPEND_LIST = 17
39
- #LUA_BLOB = 18
39
+ HLL = 18
40
40
  MAP = 19
41
41
  LIST = 20
42
42
  GEOJSON = 23
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- # Copyright 2014-2018 Aerospike, Inc.
3
+ # Copyright 2014-2020 Aerospike, Inc.
4
4
  #
5
5
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
6
6
  # license agreements.
@@ -22,18 +22,25 @@ require 'aerospike/aerospike_exception'
22
22
  module Aerospike
23
23
  # Polymorphic value classes used to efficiently serialize objects into the wire protocol.
24
24
  class Value #:nodoc:
25
- INTEGER_RANGE = Range.new(-2**63, 2**63 - 1).freeze
26
25
 
27
- def self.of(value)
26
+ def self.of(value, allow_64bits = false)
28
27
  case value
29
- when nil
30
- res = NULL
31
28
  when Integer
32
- if INTEGER_RANGE.cover?(value)
33
- res = IntegerValue.new(value)
29
+ if !allow_64bits
30
+ if value.bit_length < 64
31
+ res = IntegerValue.new(value)
32
+ else
33
+ # big nums > 2**63 are not supported
34
+ raise Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::TYPE_NOT_SUPPORTED, "Value type #{value.class} not supported with more than 64 bits.")
35
+ end
34
36
  else
35
- # big nums > 2**63 are not supported
36
- raise Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::TYPE_NOT_SUPPORTED, "Value type #{value.class} not supported.")
37
+ # used in bitwise operations
38
+ if value.bit_length <= 64
39
+ res = IntegerValue.new(value)
40
+ else
41
+ # nums with more than 64 bits are not supported
42
+ raise Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::TYPE_NOT_SUPPORTED, "Value type #{value.class} not supported with more than 64 bits.")
43
+ end
37
44
  end
38
45
  when Float
39
46
  res = FloatValue.new(value)
@@ -49,6 +56,10 @@ module Aerospike
49
56
  res = ListValue.new(value)
50
57
  when GeoJSON
51
58
  res = GeoJSONValue.new(value)
59
+ when nil
60
+ res = NULL
61
+ when TrueClass, FalseClass
62
+ res = BoolValue.new(value)
52
63
  else
53
64
  # throw an exception for anything that is not supported.
54
65
  raise Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::TYPE_NOT_SUPPORTED, "Value type #{value.class} not supported.")
@@ -57,6 +68,22 @@ module Aerospike
57
68
  res
58
69
  end
59
70
 
71
+ def self.validate_hash_key(value)
72
+ case value
73
+ when Integer
74
+ if value.bit_length >= 64
75
+ raise Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::TYPE_NOT_SUPPORTED, "Value type #{value.class} not supported as hash key.")
76
+ end
77
+ when Float
78
+ when String
79
+ when Symbol
80
+ when nil
81
+ else
82
+ # throw an exception for anything that is not supported.
83
+ raise Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::TYPE_NOT_SUPPORTED, "Value type #{value.class} not supported as hash key.")
84
+ end
85
+ end
86
+
60
87
  end # Value
61
88
 
62
89
  # Empty value.
@@ -137,7 +164,7 @@ module Aerospike
137
164
  end
138
165
  end
139
166
 
140
- INFINITY = InfinityValue.new.freeze
167
+ INFINITY = Value::INFINITY = InfinityValue.new.freeze
141
168
 
142
169
  # Wildcard value.
143
170
  class WildcardValue < Value #:nodoc:
@@ -178,7 +205,7 @@ module Aerospike
178
205
  end
179
206
  end
180
207
 
181
- WILDCARD = WildcardValue.new.freeze
208
+ WILDCARD = Value::WILDCARD = WildcardValue.new.freeze
182
209
 
183
210
  # Byte array value.
184
211
  class BytesValue < Value #:nodoc:
@@ -356,21 +383,16 @@ module Aerospike
356
383
  class ListValue < Value #:nodoc:
357
384
 
358
385
  def initialize(list)
359
- @list = list || nil
360
- Packer.use do |packer|
361
- pack(packer)
362
- @bytes = packer.bytes
363
- end
364
- self
386
+ @list = list || []
365
387
  end
366
388
 
367
389
  def estimate_size
368
- @bytes.bytesize
390
+ bytes.bytesize
369
391
  end
370
392
 
371
393
  def write(buffer, offset)
372
- buffer.write_binary(@bytes, offset)
373
- @bytes.bytesize
394
+ buffer.write_binary(bytes, offset)
395
+ bytes.bytesize
374
396
  end
375
397
 
376
398
  def pack(packer)
@@ -389,13 +411,26 @@ module Aerospike
389
411
  end
390
412
 
391
413
  def to_bytes
392
- @bytes
414
+ bytes
393
415
  end
394
416
 
395
417
  def to_s
396
418
  @list.map{|v| v.to_s}.to_s
397
419
  end
398
420
 
421
+ private
422
+
423
+ def bytes
424
+ return @bytes if @bytes
425
+
426
+ Packer.use do |packer|
427
+ pack(packer)
428
+ @bytes = packer.bytes
429
+ end
430
+
431
+ @bytes
432
+ end
433
+
399
434
  end
400
435
 
401
436
  # #######################################/
@@ -406,28 +441,22 @@ module Aerospike
406
441
 
407
442
  def initialize(vmap)
408
443
  @vmap = vmap || {}
409
-
410
- Packer.use do |packer|
411
- pack(packer)
412
- @bytes = packer.bytes
413
- end
414
-
415
- self
416
444
  end
417
445
 
418
446
  def estimate_size
419
- @bytes.bytesize
447
+ bytes.bytesize
420
448
  end
421
449
 
422
450
  def write(buffer, offset)
423
- buffer.write_binary(@bytes, offset)
424
- @bytes.bytesize
451
+ buffer.write_binary(bytes, offset)
452
+ bytes.bytesize
425
453
  end
426
454
 
427
455
  def pack(packer)
428
456
  packer.write_map_header(@vmap.length)
429
- # @vmap.each do |key, val|
430
457
  for key, val in @vmap
458
+ Value.validate_hash_key(key)
459
+
431
460
  Value.of(key).pack(packer)
432
461
  Value.of(val).pack(packer)
433
462
  end
@@ -442,13 +471,26 @@ module Aerospike
442
471
  end
443
472
 
444
473
  def to_bytes
445
- @bytes
474
+ bytes
446
475
  end
447
476
 
448
477
  def to_s
449
478
  @vmap.map{|k, v| "#{k.to_s} => #{v.to_s}" }.to_s
450
479
  end
451
480
 
481
+ private
482
+
483
+ def bytes
484
+ return @bytes if @bytes
485
+
486
+ Packer.use do |packer|
487
+ pack(packer)
488
+ @bytes = packer.bytes
489
+ end
490
+
491
+ @bytes
492
+ end
493
+
452
494
  end
453
495
 
454
496
  # #######################################/
@@ -496,6 +538,49 @@ module Aerospike
496
538
 
497
539
  end
498
540
 
541
+ # #######################################/
542
+
543
+ # HLLValue value. Encapsulates a HyperLogLog value.
544
+ # Supported by Aerospike server version 4.9 and later.
545
+ class HLLValue < Value #:nodoc:
546
+
547
+ def initialize(value)
548
+ @bytes = value
549
+ @bytes.force_encoding('binary')
550
+
551
+ self
552
+ end
553
+
554
+ def type
555
+ Aerospike::ParticleType::HLL
556
+ end
557
+
558
+ def get
559
+ self
560
+ end
561
+
562
+ def to_s
563
+ @bytes.to_s
564
+ end
565
+
566
+ def to_bytes
567
+ @bytes
568
+ end
569
+
570
+ def estimate_size
571
+ @bytes.bytesize
572
+ end
573
+
574
+ def write(buffer, offset)
575
+ buffer.write_binary(@bytes, offset)
576
+ end
577
+
578
+ def pack(packer)
579
+ packer.write(Aerospike::ParticleType::BLOB.chr + @bytes)
580
+ end
581
+
582
+ end
583
+
499
584
  #######################################
500
585
 
501
586
  def self.encoding
@@ -542,6 +627,10 @@ module Aerospike
542
627
  hdrsz = 1 + 2 + (ncells * 8)
543
628
  Aerospike::GeoJSON.new(buf.read(offset + hdrsz, length - hdrsz))
544
629
 
630
+ when Aerospike::ParticleType::HLL
631
+ bytes = buf.read(offset,length)
632
+ Aerospike::HLLValue.new(bytes)
633
+
545
634
  else
546
635
  nil
547
636
  end
@@ -563,4 +652,47 @@ module Aerospike
563
652
  nil
564
653
  end
565
654
  end
655
+
656
+ private
657
+
658
+ #######################################
659
+
660
+ # Boolean value.
661
+ # This is private, and only used internally for bitwise CDTs
662
+ class BoolValue < Value #:nodoc:
663
+
664
+ def initialize(val)
665
+ @value = val || false
666
+ self
667
+ end
668
+
669
+ def estimate_size
670
+ 1
671
+ end
672
+
673
+ def write(buffer, offset)
674
+ raise Exception.new("Unreachable")
675
+ end
676
+
677
+ def pack(packer)
678
+ packer.write(@value)
679
+ end
680
+
681
+ def type
682
+ raise Exception.new("Unreachable")
683
+ end
684
+
685
+ def get
686
+ @value
687
+ end
688
+
689
+ def to_bytes
690
+ raise Exception.new("Unreachable")
691
+ end
692
+
693
+ def to_s
694
+ @value.to_s
695
+ end
696
+
697
+ end # BoolValue
566
698
  end # module