aerospike 2.12.0 → 2.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +44 -0
  3. data/lib/aerospike.rb +17 -4
  4. data/lib/aerospike/aerospike_exception.rb +7 -1
  5. data/lib/aerospike/atomic/atomic.rb +1 -1
  6. data/lib/aerospike/bin.rb +1 -1
  7. data/lib/aerospike/cdt/bit_operation.rb +376 -0
  8. data/lib/aerospike/cdt/bit_overflow_action.rb +46 -0
  9. data/lib/aerospike/cdt/bit_policy.rb +36 -0
  10. data/lib/aerospike/cdt/bit_resize_flags.rb +44 -0
  11. data/lib/aerospike/cdt/bit_write_flags.rb +51 -0
  12. data/lib/aerospike/cdt/context.rb +113 -0
  13. data/lib/aerospike/cdt/hll_operation.rb +200 -0
  14. data/lib/aerospike/cdt/hll_policy.rb +34 -0
  15. data/lib/aerospike/cdt/hll_write_flags.rb +53 -0
  16. data/lib/aerospike/cdt/list_operation.rb +156 -97
  17. data/lib/aerospike/cdt/list_order.rb +7 -0
  18. data/lib/aerospike/cdt/list_sort_flags.rb +10 -2
  19. data/lib/aerospike/cdt/map_operation.rb +180 -93
  20. data/lib/aerospike/cdt/map_order.rb +4 -4
  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 -16
  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 +1 -0
  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 +90 -8
  37. data/lib/aerospike/command/delete_command.rb +5 -1
  38. data/lib/aerospike/command/execute_command.rb +1 -1
  39. data/lib/aerospike/command/exists_command.rb +5 -1
  40. data/lib/aerospike/command/field_type.rb +2 -1
  41. data/lib/aerospike/command/multi_command.rb +49 -2
  42. data/lib/aerospike/command/operate_command.rb +6 -1
  43. data/lib/aerospike/command/read_command.rb +39 -3
  44. data/lib/aerospike/command/read_header_command.rb +5 -1
  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 +39 -2
  48. data/lib/aerospike/command/unsupported_particle_type_validator.rb +1 -1
  49. data/lib/aerospike/command/write_command.rb +5 -1
  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 +8 -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 +19 -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 +10 -1
  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 +1 -1
  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 +14 -1
  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 +3 -3
  102. data/lib/aerospike/value/particle_type.rb +2 -2
  103. data/lib/aerospike/value/value.rb +108 -6
  104. data/lib/aerospike/version.rb +1 -1
  105. metadata +19 -6
  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 2016-2017 Aerospike, Inc.
2
+ # Copyright 2016-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.
@@ -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.
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+ # Copyright 2014-2020 Aerospike, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http:#www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ module Aerospike
17
+
18
+ module Replica
19
+
20
+ # Read from node containing key's master partition. This is the default behavior.
21
+ MASTER = 0
22
+
23
+ # Distribute reads across nodes containing key's master and replicated partitions
24
+ # in round-robin fashion.
25
+ MASTER_PROLES = 1
26
+
27
+ # Always try node containing master partition first. If connection fails and
28
+ # Policy#retryOnTimeout is true, try nodes containing prole partition.
29
+ SEQUENCE = 2
30
+
31
+ # Try node on the same rack as the client first. If there are no nodes on the
32
+ # same rack, use SEQUENCE instead.
33
+ #
34
+ # ClientPolicy#rack_aware, ClientPolicy#rack_id, and server rack
35
+ # configuration must also be set to enable this functionality.
36
+ PREFER_RACK = 3
37
+
38
+ # Distribute reads across all nodes in cluster in round-robin fashion.
39
+ # This option is useful when the replication factor equals the number
40
+ # of nodes in the cluster and the overhead of requesting proles is not desired.
41
+ RANDOM = 4
42
+
43
+ end # module
44
+
45
+ end # module
@@ -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.
@@ -28,6 +28,7 @@ module Aerospike
28
28
  attr_accessor :fail_on_cluster_change
29
29
  attr_accessor :socket_timeout
30
30
  attr_accessor :record_queue_size
31
+ attr_accessor :records_per_second
31
32
 
32
33
  def initialize(opt={})
33
34
  super(opt)
@@ -59,6 +60,12 @@ module Aerospike
59
60
  # Default is 5000.
60
61
  @record_queue_size = opt[:record_queue_size] || 5000
61
62
 
63
+ # Limit returned records per second (rps) rate for each server.
64
+ # Will not apply rps limit if records_per_second is zero.
65
+ # Currently only applicable to a query without a defined filter (scan).
66
+ # Default is 0
67
+ @records_per_second = opt[:records_per_second] || 0
68
+
62
69
  self
63
70
  end
64
71
 
@@ -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.
@@ -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.
@@ -82,6 +82,11 @@ module Aerospike
82
82
  fieldCount+=1
83
83
  end
84
84
  else
85
+ if @policy.records_per_second > 0
86
+ @data_offset += 4 + FIELD_HEADER_SIZE
87
+ fieldCount += 1
88
+ end
89
+
85
90
  # Calling query with no filters is more efficiently handled by a primary index scan.
86
91
  # Estimate scan options size.
87
92
  @data_offset += (2 + FIELD_HEADER_SIZE)
@@ -172,6 +177,10 @@ module Aerospike
172
177
  end
173
178
  end
174
179
  else
180
+ if @policy.records_per_second > 0
181
+ write_field_int(@policy.records_per_second, Aerospike::FieldType::RECORDS_PER_SECOND)
182
+ end
183
+
175
184
  # Calling query with no filters is more efficiently handled by a primary index scan.
176
185
  write_field_header(2, Aerospike::FieldType::SCAN_OPTIONS)
177
186
  priority = @policy.priority.ord
@@ -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,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
 
@@ -244,6 +251,9 @@ module Aerospike
244
251
  when KEY_EXISTS_ERROR
245
252
  "Key already exists"
246
253
 
254
+ when BIN_EXISTS_ERROR
255
+ "Bin already exists on a create-only operation"
256
+
247
257
  when CLUSTER_KEY_MISMATCH
248
258
  "Cluster key mismatch"
249
259
 
@@ -274,6 +284,9 @@ module Aerospike
274
284
  when UNSUPPORTED_FEATURE
275
285
  "Unsupported Server Feature"
276
286
 
287
+ when BIN_NOT_FOUND
288
+ "Bin not found on update-only operation"
289
+
277
290
  when DEVICE_OVERLOAD
278
291
  "Device overload"
279
292
 
@@ -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.
@@ -92,9 +92,9 @@ module Aerospike
92
92
  end
93
93
  value
94
94
  when Array
95
- normalize_strings_in_array(elem)
95
+ unpack_list(elem)
96
96
  when Hash
97
- normalize_strings_in_map(elem)
97
+ unpack_map(elem)
98
98
  else
99
99
  elem
100
100
  end
@@ -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.
@@ -23,14 +23,24 @@ module Aerospike
23
23
  # Polymorphic value classes used to efficiently serialize objects into the wire protocol.
24
24
  class Value #:nodoc:
25
25
 
26
- def self.of(value)
26
+ def self.of(value, allow_64bits = false)
27
27
  case value
28
28
  when Integer
29
- if value.bit_length < 64
30
- 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
31
36
  else
32
- # big nums > 2**63 are not supported
33
- 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
34
44
  end
35
45
  when Float
36
46
  res = FloatValue.new(value)
@@ -48,6 +58,8 @@ module Aerospike
48
58
  res = GeoJSONValue.new(value)
49
59
  when nil
50
60
  res = NULL
61
+ when TrueClass, FalseClass
62
+ res = BoolValue.new(value)
51
63
  else
52
64
  # throw an exception for anything that is not supported.
53
65
  raise Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::TYPE_NOT_SUPPORTED, "Value type #{value.class} not supported.")
@@ -526,6 +538,49 @@ module Aerospike
526
538
 
527
539
  end
528
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
+
529
584
  #######################################
530
585
 
531
586
  def self.encoding
@@ -572,6 +627,10 @@ module Aerospike
572
627
  hdrsz = 1 + 2 + (ncells * 8)
573
628
  Aerospike::GeoJSON.new(buf.read(offset + hdrsz, length - hdrsz))
574
629
 
630
+ when Aerospike::ParticleType::HLL
631
+ bytes = buf.read(offset,length)
632
+ Aerospike::HLLValue.new(bytes)
633
+
575
634
  else
576
635
  nil
577
636
  end
@@ -593,4 +652,47 @@ module Aerospike
593
652
  nil
594
653
  end
595
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
596
698
  end # module