aerospike 2.13.0 → 2.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +44 -1
  3. data/lib/aerospike.rb +14 -0
  4. data/lib/aerospike/cdt/bit_operation.rb +376 -0
  5. data/lib/aerospike/cdt/bit_overflow_action.rb +46 -0
  6. data/lib/aerospike/cdt/bit_policy.rb +36 -0
  7. data/lib/aerospike/cdt/bit_resize_flags.rb +44 -0
  8. data/lib/aerospike/cdt/bit_write_flags.rb +51 -0
  9. data/lib/aerospike/cdt/context.rb +113 -0
  10. data/lib/aerospike/cdt/hll_operation.rb +200 -0
  11. data/lib/aerospike/cdt/hll_policy.rb +34 -0
  12. data/lib/aerospike/cdt/hll_write_flags.rb +53 -0
  13. data/lib/aerospike/cdt/list_operation.rb +155 -96
  14. data/lib/aerospike/cdt/list_order.rb +7 -0
  15. data/lib/aerospike/cdt/list_sort_flags.rb +10 -2
  16. data/lib/aerospike/cdt/map_operation.rb +179 -92
  17. data/lib/aerospike/cdt/map_order.rb +3 -3
  18. data/lib/aerospike/client.rb +24 -7
  19. data/lib/aerospike/cluster.rb +47 -0
  20. data/lib/aerospike/cluster/rack_parser.rb +117 -0
  21. data/lib/aerospike/command/batch_direct_command.rb +1 -0
  22. data/lib/aerospike/command/batch_index_command.rb +1 -0
  23. data/lib/aerospike/command/command.rb +76 -7
  24. data/lib/aerospike/command/multi_command.rb +44 -1
  25. data/lib/aerospike/command/read_command.rb +34 -2
  26. data/lib/aerospike/command/touch_command.rb +34 -1
  27. data/lib/aerospike/features.rb +5 -0
  28. data/lib/aerospike/node.rb +18 -1
  29. data/lib/aerospike/node/rebalance.rb +50 -0
  30. data/lib/aerospike/node/refresh/info.rb +4 -1
  31. data/lib/aerospike/node/refresh/racks.rb +47 -0
  32. data/lib/aerospike/node/refresh/reset.rb +1 -0
  33. data/lib/aerospike/node/verify/rebalance_generation.rb +43 -0
  34. data/lib/aerospike/operation.rb +7 -2
  35. data/lib/aerospike/policy/client_policy.rb +15 -0
  36. data/lib/aerospike/policy/policy.rb +11 -3
  37. data/lib/aerospike/policy/replica.rb +7 -0
  38. data/lib/aerospike/result_code.rb +102 -0
  39. data/lib/aerospike/socket/base.rb +3 -2
  40. data/lib/aerospike/utils/buffer.rb +13 -3
  41. data/lib/aerospike/utils/unpacker.rb +2 -2
  42. data/lib/aerospike/value/particle_type.rb +1 -1
  43. data/lib/aerospike/value/value.rb +107 -5
  44. data/lib/aerospike/version.rb +1 -1
  45. metadata +15 -2
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2020 Aerospike, Inc.
4
+ #
5
+ # Portions may be licensed to Aerospike, Inc. under one or more contributor
6
+ # license agreements.
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
9
+ # use this file except in compliance with the License. You may obtain a copy of
10
+ # the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17
+ # License for the specific language governing permissions and limitations under
18
+ # the License.
19
+
20
+ module Aerospike
21
+ module CDT
22
+
23
+ # BitOverflowAction specifies the action to take when bitwise add/subtract results in overflow/underflow.
24
+ module BitOverflowAction
25
+
26
+ ##
27
+ # Fail specifies to fail operation with error.
28
+ FAIL = 0
29
+
30
+ ##
31
+ # SATURATE specifies that in add/subtract overflows/underflows, set to max/min value.
32
+ # Example: MAXINT + 1 = MAXINT
33
+ SATURATE = 2
34
+
35
+ ##
36
+ # Wrap specifies that in add/subtract overflows/underflows, WRAP the value.
37
+ # Example: MAXINT + 1 = -1
38
+ WRAP = 4
39
+
40
+ ##
41
+ # Default behavior
42
+ DEFAULT = FAIL
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2020 Aerospike, Inc.
4
+ #
5
+ # Portions may be licensed to Aerospike, Inc. under one or more contributor
6
+ # license agreements.
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
9
+ # use this file except in compliance with the License. You may obtain a copy of
10
+ # the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17
+ # License for the specific language governing permissions and limitations under
18
+ # the License.
19
+
20
+ module Aerospike
21
+ module CDT
22
+
23
+ # BitPolicy determines the Bit operation policy.
24
+ class BitPolicy
25
+
26
+ attr_accessor :flags
27
+
28
+ def initialize(flags = BitWriteFlags::DEFAULT)
29
+ @flags = flags
30
+ end
31
+
32
+ DEFAULT = BitPolicy.new
33
+
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2020 Aerospike, Inc.
4
+ #
5
+ # Portions may be licensed to Aerospike, Inc. under one or more contributor
6
+ # license agreements.
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
9
+ # use this file except in compliance with the License. You may obtain a copy of
10
+ # the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17
+ # License for the specific language governing permissions and limitations under
18
+ # the License.
19
+
20
+ module Aerospike
21
+ module CDT
22
+
23
+ ##
24
+ # BitResizeFlags specifies the bitwise operation flags for resize.
25
+ module BitResizeFlags
26
+
27
+ ##
28
+ # Default specifies the defalt flag.
29
+ DEFAULT = 0
30
+
31
+ ##
32
+ # Adds/removes bytes from the beginning instead of the end.
33
+ FROM_FRONT = 1
34
+
35
+ ##
36
+ # only allow the byte array size to increase.
37
+ GROW_ONLY = 2
38
+
39
+ ##
40
+ # only allow the byte array size to decrease.
41
+ SHRINK_ONLY = 4
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2020 Aerospike, Inc.
4
+ #
5
+ # Portions may be licensed to Aerospike, Inc. under one or more contributor
6
+ # license agreements.
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
9
+ # use this file except in compliance with the License. You may obtain a copy of
10
+ # the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17
+ # License for the specific language governing permissions and limitations under
18
+ # the License.
19
+
20
+ module Aerospike
21
+ module CDT
22
+
23
+ ##
24
+ # BitWriteFlags specify bitwise operation policy write flags.
25
+ module BitWriteFlags
26
+
27
+ ##
28
+ # Default allows create or update.
29
+ DEFAULT = 0
30
+
31
+ ##
32
+ # If the bin already exists, the operation will be denied.
33
+ # If the bin does not exist, a new bin will be created.
34
+ CREATE_ONLY = 1
35
+
36
+ ##
37
+ # If the bin already exists, the bin will be overwritten.
38
+ # If the bin does not exist, the operation will be denied.
39
+ UPDATE_ONLY = 2
40
+
41
+ ##
42
+ # Will not raise error if operation is denied.
43
+ NO_FAIL = 4
44
+
45
+ ##
46
+ # Partial allows other valid operations to be committed if this operations is
47
+ # denied due to flag constraints.
48
+ PARTIAL = 8
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,113 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2020 Aerospike, Inc.
4
+ #
5
+ # Portions may be licensed to Aerospike, Inc. under one or more contributor
6
+ # license agreements.
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
9
+ # use this file except in compliance with the License. You may obtain a copy of
10
+ # the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17
+ # License for the specific language governing permissions and limitations under
18
+ # the License.
19
+
20
+ module Aerospike
21
+ module CDT
22
+
23
+ ##
24
+ # Nested CDT context. Identifies the location of nested list/map to apply the operation.
25
+ # for the current level.
26
+ # An array of CTX identifies location of the list/map on multiple
27
+ # levels on nesting.
28
+ class Context
29
+
30
+ attr_accessor :id, :value
31
+
32
+ def initialize(id, value)
33
+ @id = id
34
+ @value = value
35
+ end
36
+
37
+ ##
38
+ # Create list with given type at index offset, given an order and pad.
39
+ def self.list_index_create(index, order, pad)
40
+ Context.new(0x10 | ListOrder.flag(order, pad), index)
41
+ end
42
+
43
+ ##
44
+ # Lookup list by index offset.
45
+ # If the index is negative, the resolved index starts backwards from end of list.
46
+ # If an index is out of bounds, a parameter error will be returned.
47
+ # Examples:
48
+ # 0: First item.
49
+ # 4: Fifth item.
50
+ # -1: Last item.
51
+ # -3: Third to last item.
52
+ def self.list_index(index)
53
+ Context.new(0x10, index)
54
+ end
55
+
56
+ ##
57
+ # Lookup list by rank.
58
+ # 0 = smallest value
59
+ # N = Nth smallest value
60
+ # -1 = largest value
61
+ def self.list_rank(rank)
62
+ Context.new(0x11, rank)
63
+ end
64
+
65
+ ##
66
+ # Lookup list by value.
67
+ def self.list_value(key)
68
+ Context.new(0x13, key)
69
+ end
70
+
71
+ ##
72
+ # Lookup map by index offset.
73
+ # If the index is negative, the resolved index starts backwards from end of list.
74
+ # If an index is out of bounds, a parameter error will be returned.
75
+ # Examples:
76
+ # 0: First item.
77
+ # 4: Fifth item.
78
+ # -1: Last item.
79
+ # -3: Third to last item.
80
+ def self.map_index(index)
81
+ Context.new(0x20, index)
82
+ end
83
+
84
+ ##
85
+ # Lookup map by rank.
86
+ # 0 = smallest value
87
+ # N = Nth smallest value
88
+ # -1 = largest value
89
+ def self.map_rank(rank)
90
+ Context.new(0x21, rank)
91
+ end
92
+
93
+ ##
94
+ # Lookup map by key.
95
+ def self.map_key(key)
96
+ Context.new(0x22, key)
97
+ end
98
+
99
+ ##
100
+ # Create map with given type at map key.
101
+ def self.map_key_create(key, order)
102
+ Context.new(0x22 | order[:flag], key)
103
+ end
104
+
105
+ ##
106
+ # Lookup map by value.
107
+ def self.map_value(key)
108
+ Context.new(0x23, key)
109
+ end
110
+
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,200 @@
1
+ # encoding: utf-8
2
+ # Copyright 2016-2020 Aerospike, Inc.
3
+ #
4
+ # Portions may be licensed to Aerospike, Inc. under one or more contributor
5
+ # license agreements.
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
8
+ # use this file except in compliance with the License. You may obtain a copy of
9
+ # the License at http:#www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ # License for the specific language governing permissions and limitations under
15
+ # the License.
16
+
17
+ module Aerospike
18
+ module CDT
19
+
20
+ # HyperLogLog (HLL) operations.
21
+ # Requires server versions >= 4.9.
22
+ #
23
+ # HyperLogLog operations on HLL items nested in lists/maps are not currently
24
+ # supported by the server.
25
+ class HLLOperation < Operation
26
+
27
+ INIT = 0
28
+ ADD = 1
29
+ SET_UNION = 2
30
+ SET_COUNT = 3
31
+ FOLD = 4
32
+ COUNT = 50
33
+ UNION = 51
34
+ UNION_COUNT = 52
35
+ INTERSECT_COUNT = 53
36
+ SIMILARITY = 54
37
+ DESCRIBE = 55
38
+
39
+ attr_reader :hll_op, :values, :return_type, :policy, :index_bit_count, :minhash_bit_count
40
+
41
+ def initialize(op_type, hll_op, bin_name, values: nil, index_bit_count: nil, minhash_bit_count: nil, policy: nil)
42
+ @policy = policy
43
+ @op_type = op_type
44
+ @bin_name = bin_name
45
+ @bin_value = nil
46
+ @hll_op = hll_op
47
+ @index_bit_count = index_bit_count
48
+ @minhash_bit_count = minhash_bit_count
49
+ @values = values
50
+
51
+ self
52
+ end
53
+
54
+ ##
55
+ # Create HLL init operation with minhash bits.
56
+ # Server creates a new HLL or resets an existing HLL.
57
+ # Server does not return a value.
58
+ #
59
+ # policy write policy, HLLPolicy::DEFAULT is default
60
+ # bin_name name of bin
61
+ # index_bit_count number of index bits. Must be between 4 and 16 inclusive.
62
+ # minhash_bit_count number of min hash bits. Must be between 4 and 58 inclusive.
63
+ def self.init(bin_name, index_bit_count, minhash_bit_count, policy = HLLPolicy::DEFAULT)
64
+ HLLOperation.new(Operation::HLL_MODIFY, INIT, bin_name, index_bit_count: index_bit_count, minhash_bit_count: minhash_bit_count, policy: policy)
65
+ end
66
+
67
+ ##
68
+ # Create HLL add operation with minhash bits.
69
+ # Server adds values to HLL set. If HLL bin does not exist, use index_bit_count and minhash_bit_count
70
+ # to create HLL bin. Server returns number of entries that caused HLL to update a register.
71
+ #
72
+ # policy write policy, HLLPolicy::DEFAULT is default
73
+ # bin_name name of bin
74
+ # list list of values to be added
75
+ # index_bit_count number of index bits. Must be between 4 and 16 inclusive.
76
+ # minhash_bit_count number of min hash bits. Must be between 4 and 58 inclusive.
77
+ def self.add(bin_name, *values, policy: HLLPolicy::DEFAULT, index_bit_count: -1, minhash_bit_count: -1)
78
+ HLLOperation.new(Operation::HLL_MODIFY, ADD, bin_name, index_bit_count: index_bit_count, minhash_bit_count: minhash_bit_count, values: values, policy: policy)
79
+ end
80
+
81
+ ##
82
+ # Create HLL set union operation.
83
+ # Server sets union of specified HLL objects with HLL bin.
84
+ # Server does not return a value.
85
+ #
86
+ # policy write policy, HLLPolicy::DEFAULT is default
87
+ # bin_name name of bin
88
+ # list list of HLL objects
89
+ def self.set_union(bin_name, *values, policy: HLLPolicy::DEFAULT)
90
+ HLLOperation.new(Operation::HLL_MODIFY, SET_UNION, bin_name, values: values, policy: policy)
91
+ end
92
+
93
+ ##
94
+ # Create HLL refresh operation.
95
+ # Server updates the cached count (if stale) and returns the count.
96
+ #
97
+ # bin_name name of bin
98
+ def self.refresh_count(bin_name)
99
+ HLLOperation.new(Operation::HLL_MODIFY, SET_COUNT, bin_name)
100
+ end
101
+
102
+ ##
103
+ # Create HLL fold operation.
104
+ # Servers folds index_bit_count to the specified value.
105
+ # This can only be applied when minhash_bit_count on the HLL bin is 0.
106
+ # Server does not return a value.
107
+ #
108
+ # bin_name name of bin
109
+ # index_bit_count number of index bits. Must be between 4 and 16 inclusive.
110
+ def self.fold(bin_name, index_bit_count)
111
+ HLLOperation.new(Operation::HLL_MODIFY, FOLD, bin_name, index_bit_count: index_bit_count)
112
+ end
113
+
114
+ ##
115
+ # Create HLL getCount operation.
116
+ # Server returns estimated number of elements in the HLL bin.
117
+ #
118
+ # bin_name name of bin
119
+ def self.get_count(bin_name)
120
+ HLLOperation.new(Operation::HLL_READ, COUNT, bin_name)
121
+ end
122
+
123
+ ##
124
+ # Create HLL getUnion operation.
125
+ # Server returns an HLL object that is the union of all specified HLL objects in the list
126
+ # with the HLL bin.
127
+ #
128
+ # bin_name name of bin
129
+ # list list of HLL objects
130
+ def self.get_union(bin_name, *values)
131
+ HLLOperation.new(Operation::HLL_READ, UNION, bin_name, values: values)
132
+ end
133
+
134
+ ##
135
+ # Create HLL getUnionCount operation.
136
+ # Server returns estimated number of elements that would be contained by the union of these
137
+ # HLL objects.
138
+ # bin_name name of bin
139
+ # list list of HLL objects
140
+ def self.get_union_count(bin_name, *values)
141
+ HLLOperation.new(Operation::HLL_READ, UNION_COUNT, bin_name, values: values)
142
+ end
143
+
144
+ ##
145
+ # Create HLL getIntersectCount operation.
146
+ # Server returns estimated number of elements that would be contained by the intersection of
147
+ # these HLL objects.
148
+ #
149
+ # bin_name name of bin
150
+ # list list of HLL objects
151
+ def self.get_intersect_count(bin_name, *values)
152
+ HLLOperation.new(Operation::HLL_READ, INTERSECT_COUNT, bin_name, values: values)
153
+ end
154
+
155
+ ##
156
+ # Create HLL getSimilarity operation.
157
+ # Server returns estimated similarity of these HLL objects. Return type is a double.
158
+ #
159
+ # bin_name name of bin
160
+ # list list of HLL objects
161
+ def self.get_similarity(bin_name, *values)
162
+ HLLOperation.new(Operation::HLL_READ, SIMILARITY, bin_name, values: values)
163
+ end
164
+
165
+ ##
166
+ # Create HLL describe operation.
167
+ # Server returns index_bit_count and minhash_bit_count used to create HLL bin in a list of longs.
168
+ # The list size is 2.
169
+ #
170
+ # bin_name name of bin
171
+ def self.describe(bin_name)
172
+ HLLOperation.new(Operation::HLL_READ, DESCRIBE, bin_name)
173
+ end
174
+
175
+ def bin_value
176
+ @bin_value ||= pack_bin_value
177
+ end
178
+
179
+ private
180
+
181
+ def pack_bin_value
182
+ bytes = nil
183
+ Packer.use do |packer|
184
+ args = [hll_op]
185
+ args << values if values
186
+ args << index_bit_count if index_bit_count
187
+ args << minhash_bit_count if minhash_bit_count
188
+ args << policy.flags if policy
189
+
190
+ vv = ListValue.new(args)
191
+ vv.pack(packer)
192
+ bytes = packer.bytes
193
+ end
194
+ BytesValue.new(bytes)
195
+ end
196
+
197
+ end
198
+
199
+ end
200
+ end