aerospike 1.0.12 → 2.0.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +54 -18
- data/README.md +7 -2
- data/lib/aerospike.rb +8 -0
- data/lib/aerospike/cdt/list_operation.rb +199 -0
- data/lib/aerospike/cdt/map_operation.rb +352 -0
- data/lib/aerospike/cdt/map_order.rb +38 -0
- data/lib/aerospike/cdt/map_policy.rb +37 -0
- data/lib/aerospike/cdt/map_return_type.rb +74 -0
- data/lib/aerospike/cdt/map_write_mode.rb +41 -0
- data/lib/aerospike/client.rb +84 -119
- data/lib/aerospike/cluster/cluster.rb +4 -4
- data/lib/aerospike/command/admin_command.rb +325 -325
- data/lib/aerospike/command/command.rb +2 -2
- data/lib/aerospike/command/roles.rb +13 -13
- data/lib/aerospike/key.rb +24 -5
- data/lib/aerospike/operation.rb +2 -0
- data/lib/aerospike/policy/admin_policy.rb +10 -10
- data/lib/aerospike/policy/consistency_level.rb +4 -4
- data/lib/aerospike/query/stream_command.rb +1 -1
- data/lib/aerospike/result_code.rb +1 -1
- data/lib/aerospike/task/execute_task.rb +68 -68
- data/lib/aerospike/task/task.rb +2 -6
- data/lib/aerospike/utils/packer.rb +47 -0
- data/lib/aerospike/utils/unpacker.rb +106 -0
- data/lib/aerospike/value/value.rb +19 -51
- data/lib/aerospike/version.rb +1 -1
- metadata +17 -7
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright 2016 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
|
+
module MapOrder
|
20
|
+
|
21
|
+
##
|
22
|
+
# Map is not ordered. This is the default.
|
23
|
+
UNORDERED = 0
|
24
|
+
|
25
|
+
##
|
26
|
+
# Order map by key.
|
27
|
+
KEY_ORDERED = 1
|
28
|
+
|
29
|
+
##
|
30
|
+
# Order map by key, then value.
|
31
|
+
KEY_VALUE_ORDERED = 3
|
32
|
+
|
33
|
+
##
|
34
|
+
# Default order
|
35
|
+
DEFAULT = UNORDERED
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright 2016 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
|
+
class MapPolicy
|
21
|
+
|
22
|
+
attr_accessor :order, :write_mode
|
23
|
+
|
24
|
+
def initialize(order: nil, write_mode: nil)
|
25
|
+
@order = order || MapOrder::DEFAULT
|
26
|
+
@write_mode = write_mode || MapWriteMode::DEFAULT
|
27
|
+
end
|
28
|
+
|
29
|
+
DEFAULT = MapPolicy.new
|
30
|
+
|
31
|
+
def value
|
32
|
+
order.to_int
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright 2016 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
|
+
module MapReturnType
|
20
|
+
|
21
|
+
##
|
22
|
+
# Do not return a result.
|
23
|
+
NONE = 0
|
24
|
+
|
25
|
+
##
|
26
|
+
# Return key index order.
|
27
|
+
# 0 = first key
|
28
|
+
# N = Nth key
|
29
|
+
# -1 = last key
|
30
|
+
INDEX = 1
|
31
|
+
|
32
|
+
##
|
33
|
+
# Return reverse key order.
|
34
|
+
# 0 = last key
|
35
|
+
# -1 = first key
|
36
|
+
REVERSE_INDEX = 2
|
37
|
+
|
38
|
+
##
|
39
|
+
# Return value order.
|
40
|
+
# 0 = smalles value
|
41
|
+
# N = Nth smalles value
|
42
|
+
# -1 = largest value
|
43
|
+
RANK = 3
|
44
|
+
|
45
|
+
##
|
46
|
+
# Return reverse value order.
|
47
|
+
# 0 = largest value
|
48
|
+
# N = Nth largest value
|
49
|
+
# -1 = smallest values
|
50
|
+
REVERSE_RANK = 4
|
51
|
+
|
52
|
+
##
|
53
|
+
# Return count of items selected.
|
54
|
+
COUNT = 5
|
55
|
+
|
56
|
+
##
|
57
|
+
# Return key for single read and key list for range read.
|
58
|
+
KEY = 6
|
59
|
+
|
60
|
+
##
|
61
|
+
# Return value for single key read and value list for range read.
|
62
|
+
VALUE = 7
|
63
|
+
|
64
|
+
##
|
65
|
+
# Return key/value items.
|
66
|
+
KEY_VALUE = 8
|
67
|
+
|
68
|
+
##
|
69
|
+
# Default return type: NONE
|
70
|
+
DEFAULT_RETURN_TYPE = NONE
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright 2016 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
|
+
module MapWriteMode
|
20
|
+
|
21
|
+
##
|
22
|
+
# If the key already exists, the item will be overwritten.
|
23
|
+
# If the key does not exist, a new item will be created.
|
24
|
+
UPDATE = 0
|
25
|
+
|
26
|
+
##
|
27
|
+
# If the key already exists, the item will be overwritten.
|
28
|
+
# If the key does not exist, the write will fail.
|
29
|
+
UPDATE_ONLY = 1
|
30
|
+
|
31
|
+
##
|
32
|
+
# If the key already exists, the write will fail.
|
33
|
+
# If the key does not exist, a new item will be created.
|
34
|
+
CREATE_ONLY = 2
|
35
|
+
|
36
|
+
##
|
37
|
+
# Default write mode
|
38
|
+
DEFAULT = UPDATE
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/aerospike/client.rb
CHANGED
@@ -29,7 +29,7 @@ module Aerospike
|
|
29
29
|
# Examples:
|
30
30
|
#
|
31
31
|
# # connect to the database
|
32
|
-
# client = Client.new('192.168.0.1'
|
32
|
+
# client = Client.new('192.168.0.1')
|
33
33
|
#
|
34
34
|
# #=> raises Aerospike::Exceptions::Timeout if a +:timeout+ is specified and
|
35
35
|
# +:fail_if_not_connected+ set to true
|
@@ -39,40 +39,27 @@ module Aerospike
|
|
39
39
|
attr_accessor :default_policy, :default_write_policy,
|
40
40
|
:default_scan_policy, :default_query_policy, :default_admin_policy
|
41
41
|
|
42
|
-
def initialize(
|
42
|
+
def initialize(hosts = nil, policy: ClientPolicy.new, connect: true)
|
43
43
|
@default_policy = Policy.new
|
44
44
|
@default_write_policy = WritePolicy.new
|
45
45
|
@default_scan_policy = ScanPolicy.new
|
46
46
|
@default_query_policy = QueryPolicy.new
|
47
47
|
@default_admin_policy = QueryPolicy.new
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
@cluster = Cluster.new(policy,
|
49
|
+
hosts = parse_hosts(hosts || ENV["AEROSPIKE_HOSTS"] || "localhost")
|
50
|
+
policy = create_policy(policy, ClientPolicy)
|
51
|
+
@cluster = Cluster.new(policy, *hosts)
|
52
52
|
@cluster.add_cluster_config_change_listener(self)
|
53
|
-
@cluster.connect
|
54
53
|
|
54
|
+
self.connect if connect
|
55
55
|
self
|
56
56
|
end
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
client = Client.allocate
|
61
|
-
|
62
|
-
client.default_policy = Policy.new
|
63
|
-
client.default_write_policy = WritePolicy.new
|
64
|
-
client.default_scan_policy = ScanPolicy.new
|
65
|
-
client.default_query_policy = QueryPolicy.new
|
66
|
-
client.default_admin_policy = QueryPolicy.new
|
67
|
-
|
68
|
-
policy = client.send(:opt_to_client_policy , options)
|
69
|
-
|
70
|
-
cluster = Cluster.new(policy, *hosts)
|
71
|
-
cluster.add_cluster_config_change_listener(client)
|
72
|
-
client.send(:cluster=, cluster)
|
73
|
-
cluster.connect
|
58
|
+
##
|
59
|
+
# Connect to the cluster.
|
74
60
|
|
75
|
-
|
61
|
+
def connect
|
62
|
+
@cluster.connect
|
76
63
|
end
|
77
64
|
|
78
65
|
##
|
@@ -106,6 +93,10 @@ module Aerospike
|
|
106
93
|
end
|
107
94
|
end
|
108
95
|
|
96
|
+
def supports_feature?(feature)
|
97
|
+
@cluster.supports_feature?(feature)
|
98
|
+
end
|
99
|
+
|
109
100
|
#-------------------------------------------------------
|
110
101
|
# Write Record Operations
|
111
102
|
#-------------------------------------------------------
|
@@ -122,7 +113,7 @@ module Aerospike
|
|
122
113
|
# client.put key, {'bin', 'value string'}, :timeout => 0.001
|
123
114
|
|
124
115
|
def put(key, bins, options={})
|
125
|
-
policy =
|
116
|
+
policy = create_policy(options, WritePolicy)
|
126
117
|
command = WriteCommand.new(@cluster, policy, key, hash_to_bins(bins), Aerospike::Operation::WRITE)
|
127
118
|
execute_command(command)
|
128
119
|
end
|
@@ -145,7 +136,7 @@ module Aerospike
|
|
145
136
|
# client.append key, {'bin', 'value to append'}, :timeout => 0.001
|
146
137
|
|
147
138
|
def append(key, bins, options={})
|
148
|
-
policy =
|
139
|
+
policy = create_policy(options, WritePolicy)
|
149
140
|
command = WriteCommand.new(@cluster, policy, key, hash_to_bins(bins), Aerospike::Operation::APPEND)
|
150
141
|
execute_command(command)
|
151
142
|
end
|
@@ -164,7 +155,7 @@ module Aerospike
|
|
164
155
|
# client.prepend key, {'bin', 'value to prepend'}, :timeout => 0.001
|
165
156
|
|
166
157
|
def prepend(key, bins, options={})
|
167
|
-
policy =
|
158
|
+
policy = create_policy(options, WritePolicy)
|
168
159
|
command = WriteCommand.new(@cluster, policy, key, hash_to_bins(bins), Aerospike::Operation::PREPEND)
|
169
160
|
execute_command(command)
|
170
161
|
end
|
@@ -187,7 +178,7 @@ module Aerospike
|
|
187
178
|
# client.add key, {'bin', -1}, :timeout => 0.001
|
188
179
|
|
189
180
|
def add(key, bins, options={})
|
190
|
-
policy =
|
181
|
+
policy = create_policy(options, WritePolicy)
|
191
182
|
command = WriteCommand.new(@cluster, policy, key, hash_to_bins(bins), Aerospike::Operation::ADD)
|
192
183
|
execute_command(command)
|
193
184
|
end
|
@@ -209,7 +200,7 @@ module Aerospike
|
|
209
200
|
# existed = client.delete key, :timeout => 0.001
|
210
201
|
|
211
202
|
def delete(key, options={})
|
212
|
-
policy =
|
203
|
+
policy = create_policy(options, WritePolicy)
|
213
204
|
command = DeleteCommand.new(@cluster, policy, key)
|
214
205
|
execute_command(command)
|
215
206
|
command.existed
|
@@ -230,7 +221,7 @@ module Aerospike
|
|
230
221
|
# client.touch key, :timeout => 0.001
|
231
222
|
|
232
223
|
def touch(key, options={})
|
233
|
-
policy =
|
224
|
+
policy = create_policy(options, WritePolicy)
|
234
225
|
command = TouchCommand.new(@cluster, policy, key)
|
235
226
|
execute_command(command)
|
236
227
|
end
|
@@ -243,7 +234,7 @@ module Aerospike
|
|
243
234
|
# Determines if a record key exists.
|
244
235
|
# The policy can be used to specify timeouts.
|
245
236
|
def exists(key, options={})
|
246
|
-
policy =
|
237
|
+
policy = create_policy(options, Policy)
|
247
238
|
command = ExistsCommand.new(@cluster, policy, key)
|
248
239
|
execute_command(command)
|
249
240
|
command.exists
|
@@ -253,7 +244,7 @@ module Aerospike
|
|
253
244
|
# The returned array bool is in positional order with the original key array order.
|
254
245
|
# The policy can be used to specify timeouts.
|
255
246
|
def batch_exists(keys, options={})
|
256
|
-
policy =
|
247
|
+
policy = create_policy(options, Policy)
|
257
248
|
|
258
249
|
# same array can be used without sychronization;
|
259
250
|
# when a key exists, the corresponding index will be marked true
|
@@ -276,7 +267,7 @@ module Aerospike
|
|
276
267
|
# Read record header and bins for specified key.
|
277
268
|
# The policy can be used to specify timeouts.
|
278
269
|
def get(key, bin_names=[], options={})
|
279
|
-
policy =
|
270
|
+
policy = create_policy(options, Policy)
|
280
271
|
|
281
272
|
command = ReadCommand.new(@cluster, policy, key, bin_names)
|
282
273
|
execute_command(command)
|
@@ -286,7 +277,7 @@ module Aerospike
|
|
286
277
|
# Read record generation and expiration only for specified key. Bins are not read.
|
287
278
|
# The policy can be used to specify timeouts.
|
288
279
|
def get_header(key, options={})
|
289
|
-
policy =
|
280
|
+
policy = create_policy(options, Policy)
|
290
281
|
command = ReadHeaderCommand.new(@cluster, policy, key)
|
291
282
|
execute_command(command)
|
292
283
|
command.record
|
@@ -301,7 +292,7 @@ module Aerospike
|
|
301
292
|
# If a key is not found, the positional record will be nil.
|
302
293
|
# The policy can be used to specify timeouts.
|
303
294
|
def batch_get(keys, bin_names=[], options={})
|
304
|
-
policy =
|
295
|
+
policy = create_policy(options, Policy)
|
305
296
|
|
306
297
|
# wait until all migrations are finished
|
307
298
|
# TODO: implement
|
@@ -326,7 +317,7 @@ module Aerospike
|
|
326
317
|
# If a key is not found, the positional record will be nil.
|
327
318
|
# The policy can be used to specify timeouts.
|
328
319
|
def batch_get_header(keys, options={})
|
329
|
-
policy =
|
320
|
+
policy = create_policy(options, Policy)
|
330
321
|
|
331
322
|
# wait until all migrations are finished
|
332
323
|
# TODO: Fix this and implement
|
@@ -357,7 +348,7 @@ module Aerospike
|
|
357
348
|
# Write operations are always performed first, regardless of operation order
|
358
349
|
# relative to read operations.
|
359
350
|
def operate(key, operations, options={})
|
360
|
-
policy =
|
351
|
+
policy = create_policy(options, WritePolicy)
|
361
352
|
|
362
353
|
command = OperateCommand.new(@cluster, policy, key, operations)
|
363
354
|
execute_command(command)
|
@@ -373,7 +364,8 @@ module Aerospike
|
|
373
364
|
#
|
374
365
|
# This method is only supported by Aerospike 3 servers.
|
375
366
|
def get_large_list(key, bin_name, user_module=nil, options={})
|
376
|
-
|
367
|
+
policy = create_policy(options, WritePolicy)
|
368
|
+
LargeList.new(self, policy, key, bin_name, user_module)
|
377
369
|
end
|
378
370
|
|
379
371
|
# Initialize large map operator. This operator can be used to create and manage a map
|
@@ -382,7 +374,8 @@ module Aerospike
|
|
382
374
|
# This method is only supported by Aerospike 3 servers.
|
383
375
|
# DEPRECATED. This method will be removed from the client in the future.
|
384
376
|
def get_large_map(key, bin_name, user_module=nil, options={})
|
385
|
-
|
377
|
+
policy = create_policy(options, WritePolicy)
|
378
|
+
LargeMap.new(self, policy, key, bin_name, user_module)
|
386
379
|
end
|
387
380
|
|
388
381
|
# Initialize large set operator. This operator can be used to create and manage a set
|
@@ -391,7 +384,8 @@ module Aerospike
|
|
391
384
|
# This method is only supported by Aerospike 3 servers.
|
392
385
|
# DEPRECATED. This method will be removed from the client in the future.
|
393
386
|
def get_large_set(key, bin_name, user_module=nil, options={})
|
394
|
-
|
387
|
+
policy = create_policy(options, WritePolicy)
|
388
|
+
LargeSet.new(self, policy, key, bin_name, user_module)
|
395
389
|
end
|
396
390
|
|
397
391
|
# Initialize large stack operator. This operator can be used to create and manage a stack
|
@@ -400,7 +394,8 @@ module Aerospike
|
|
400
394
|
# This method is only supported by Aerospike 3 servers.
|
401
395
|
# DEPRECATED. This method will be removed from the client in the future.
|
402
396
|
def get_large_stack(key, bin_name, user_module=nil, options={})
|
403
|
-
|
397
|
+
policy = create_policy(options, WritePolicy)
|
398
|
+
LargeStack.new(self, policy, key, bin_name, user_module)
|
404
399
|
end
|
405
400
|
|
406
401
|
#---------------------------------------------------------------
|
@@ -508,7 +503,7 @@ module Aerospike
|
|
508
503
|
#
|
509
504
|
# This method is only supported by Aerospike 3 servers.
|
510
505
|
def execute_udf(key, package_name, function_name, args=[], options={})
|
511
|
-
policy =
|
506
|
+
policy = create_policy(options, WritePolicy)
|
512
507
|
|
513
508
|
command = ExecuteCommand.new(@cluster, policy, key, package_name, function_name, args)
|
514
509
|
execute_command(command)
|
@@ -542,7 +537,7 @@ module Aerospike
|
|
542
537
|
# This method is only supported by Aerospike 3 servers.
|
543
538
|
# If the policy is nil, the default relevant policy will be used.
|
544
539
|
def execute_udf_on_query(statement, package_name, function_name, function_args=[], options={})
|
545
|
-
policy =
|
540
|
+
policy = create_policy(options, QueryPolicy)
|
546
541
|
|
547
542
|
nodes = @cluster.nodes
|
548
543
|
if nodes.length == 0
|
@@ -555,7 +550,7 @@ module Aerospike
|
|
555
550
|
# Use a thread per node
|
556
551
|
nodes.each do |node|
|
557
552
|
Thread.new do
|
558
|
-
abort_on_exception = true
|
553
|
+
Thread.current.abort_on_exception = true
|
559
554
|
begin
|
560
555
|
command = QueryCommand.new(node, policy, statement, nil)
|
561
556
|
execute_command(command)
|
@@ -578,7 +573,7 @@ module Aerospike
|
|
578
573
|
# This method is only supported by Aerospike 3 servers.
|
579
574
|
# index_type should be :string, :numeric or :geo2dsphere (requires server version 3.7 or later)
|
580
575
|
def create_index(namespace, set_name, index_name, bin_name, index_type, options={})
|
581
|
-
policy =
|
576
|
+
policy = create_policy(options, WritePolicy)
|
582
577
|
str_cmd = "sindex-create:ns=#{namespace}"
|
583
578
|
str_cmd << ";set=#{set_name}" unless set_name.to_s.strip.empty?
|
584
579
|
str_cmd << ";indexname=#{index_name};numbins=1;indexdata=#{bin_name},#{index_type.to_s.upcase}"
|
@@ -605,7 +600,7 @@ module Aerospike
|
|
605
600
|
# Delete secondary index.
|
606
601
|
# This method is only supported by Aerospike 3 servers.
|
607
602
|
def drop_index(namespace, set_name, index_name, options={})
|
608
|
-
policy =
|
603
|
+
policy = create_policy(options, WritePolicy)
|
609
604
|
str_cmd = "sindex-delete:ns=#{namespace}"
|
610
605
|
str_cmd << ";set=#{set_name}" unless set_name.to_s.strip.empty?
|
611
606
|
str_cmd << ";indexname=#{index_name}"
|
@@ -620,7 +615,7 @@ module Aerospike
|
|
620
615
|
# Index did not previously exist. Return without error.
|
621
616
|
return if response.start_with?('FAIL:201')
|
622
617
|
|
623
|
-
raise Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::
|
618
|
+
raise Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::INDEX_GENERIC, "Drop index failed: #{response}")
|
624
619
|
end
|
625
620
|
|
626
621
|
def request_info(*commands)
|
@@ -632,7 +627,7 @@ module Aerospike
|
|
632
627
|
#-------------------------------------------------------
|
633
628
|
|
634
629
|
def scan_all(namespace, set_name, bin_names=[], options={})
|
635
|
-
policy =
|
630
|
+
policy = create_policy(options, ScanPolicy)
|
636
631
|
|
637
632
|
# wait until all migrations are finished
|
638
633
|
# TODO: implement
|
@@ -653,12 +648,12 @@ module Aerospike
|
|
653
648
|
# Use a thread per node
|
654
649
|
nodes.each do |node|
|
655
650
|
Thread.new do
|
656
|
-
abort_on_exception = true
|
651
|
+
Thread.current.abort_on_exception = true
|
657
652
|
command = ScanCommand.new(node, new_policy, namespace, set_name, bin_names, recordset)
|
658
653
|
begin
|
659
654
|
execute_command(command)
|
660
655
|
rescue => e
|
661
|
-
Aerospike.logger.error(e.backtrace.join("\n")) unless e == SCAN_TERMINATED_EXCEPTION
|
656
|
+
Aerospike.logger.error(e.backtrace.join("\n")) unless e == SCAN_TERMINATED_EXCEPTION
|
662
657
|
recordset.cancel(e)
|
663
658
|
ensure
|
664
659
|
recordset.thread_finished
|
@@ -667,13 +662,13 @@ module Aerospike
|
|
667
662
|
end
|
668
663
|
else
|
669
664
|
Thread.new do
|
670
|
-
abort_on_exception = true
|
665
|
+
Thread.current.abort_on_exception = true
|
671
666
|
nodes.each do |node|
|
672
667
|
command = ScanCommand.new(node, new_policy, namespace, set_name, bin_names, recordset)
|
673
668
|
begin
|
674
669
|
execute_command(command)
|
675
670
|
rescue => e
|
676
|
-
Aerospike.logger.error(e.backtrace.join("\n")) unless e == SCAN_TERMINATED_EXCEPTION
|
671
|
+
Aerospike.logger.error(e.backtrace.join("\n")) unless e == SCAN_TERMINATED_EXCEPTION
|
677
672
|
recordset.cancel(e)
|
678
673
|
ensure
|
679
674
|
recordset.thread_finished
|
@@ -688,7 +683,7 @@ module Aerospike
|
|
688
683
|
# ScanNode reads all records in specified namespace and set, from one node only.
|
689
684
|
# The policy can be used to specify timeouts.
|
690
685
|
def scan_node(node, namespace, set_name, bin_names=[], options={})
|
691
|
-
policy =
|
686
|
+
policy = create_policy(options, ScanPolicy)
|
692
687
|
# wait until all migrations are finished
|
693
688
|
# TODO: implement
|
694
689
|
# @cluster.WaitUntillMigrationIsFinished(policy.timeout)
|
@@ -703,12 +698,12 @@ module Aerospike
|
|
703
698
|
recordset = Recordset.new(policy.record_queue_size, 1, :scan)
|
704
699
|
|
705
700
|
Thread.new do
|
706
|
-
abort_on_exception = true
|
701
|
+
Thread.current.abort_on_exception = true
|
707
702
|
command = ScanCommand.new(node, new_policy, namespace, set_name, bin_names, recordset)
|
708
703
|
begin
|
709
704
|
execute_command(command)
|
710
705
|
rescue => e
|
711
|
-
Aerospike.logger.error(e.backtrace.join("\n")) unless e == SCAN_TERMINATED_EXCEPTION
|
706
|
+
Aerospike.logger.error(e.backtrace.join("\n")) unless e == SCAN_TERMINATED_EXCEPTION
|
712
707
|
recordset.cancel(e)
|
713
708
|
ensure
|
714
709
|
recordset.thread_finished
|
@@ -730,7 +725,7 @@ module Aerospike
|
|
730
725
|
# This method is only supported by Aerospike 3 servers.
|
731
726
|
# If the policy is nil, a default policy will be generated.
|
732
727
|
def query(statement, options={})
|
733
|
-
policy =
|
728
|
+
policy = create_policy(options, QueryPolicy)
|
734
729
|
new_policy = policy.clone
|
735
730
|
|
736
731
|
nodes = @cluster.nodes
|
@@ -743,12 +738,12 @@ module Aerospike
|
|
743
738
|
# Use a thread per node
|
744
739
|
nodes.each do |node|
|
745
740
|
Thread.new do
|
746
|
-
abort_on_exception = true
|
741
|
+
Thread.current.abort_on_exception = true
|
747
742
|
command = QueryCommand.new(node, new_policy, statement, recordset)
|
748
743
|
begin
|
749
744
|
execute_command(command)
|
750
745
|
rescue => e
|
751
|
-
Aerospike.logger.error(e.backtrace.join("\n")) unless e == QUERY_TERMINATED_EXCEPTION
|
746
|
+
Aerospike.logger.error(e.backtrace.join("\n")) unless e == QUERY_TERMINATED_EXCEPTION
|
752
747
|
recordset.cancel(e)
|
753
748
|
ensure
|
754
749
|
recordset.thread_finished
|
@@ -766,7 +761,7 @@ module Aerospike
|
|
766
761
|
# Create user with password and roles. Clear-text password will be hashed using bcrypt
|
767
762
|
# before sending to server.
|
768
763
|
def create_user(user, password, roles, options={})
|
769
|
-
policy =
|
764
|
+
policy = create_policy(options, AdminPolicy)
|
770
765
|
hash = AdminCommand.hash_password(password)
|
771
766
|
command = AdminCommand.new
|
772
767
|
command.create_user(@cluster, policy, user, hash, roles)
|
@@ -774,14 +769,14 @@ module Aerospike
|
|
774
769
|
|
775
770
|
# Remove user from cluster.
|
776
771
|
def drop_user(user, options={})
|
777
|
-
policy =
|
772
|
+
policy = create_policy(options, AdminPolicy)
|
778
773
|
command = AdminCommand.new
|
779
774
|
command.drop_user(@cluster, policy, user)
|
780
775
|
end
|
781
776
|
|
782
777
|
# Change user's password. Clear-text password will be hashed using bcrypt before sending to server.
|
783
778
|
def change_password(user, password, options={})
|
784
|
-
policy =
|
779
|
+
policy = create_policy(options, AdminPolicy)
|
785
780
|
if @cluster.user == ''
|
786
781
|
return NewAerospikeError(INVALID_USER)
|
787
782
|
end
|
@@ -802,28 +797,28 @@ module Aerospike
|
|
802
797
|
|
803
798
|
# Add roles to user's list of roles.
|
804
799
|
def grant_roles(user, roles, options={})
|
805
|
-
policy =
|
800
|
+
policy = create_policy(options, AdminPolicy)
|
806
801
|
command = AdminCommand.new
|
807
802
|
command.grant_roles(@cluster, policy, user, roles)
|
808
803
|
end
|
809
804
|
|
810
805
|
# Remove roles from user's list of roles.
|
811
806
|
def revoke_roles(user, roles, options={})
|
812
|
-
policy =
|
807
|
+
policy = create_policy(options, AdminPolicy)
|
813
808
|
command = AdminCommand.new
|
814
809
|
command.revoke_roles(@cluster, policy, user, roles)
|
815
810
|
end
|
816
811
|
|
817
812
|
# Retrieve roles for a given user.
|
818
813
|
def query_user(user, options={})
|
819
|
-
policy =
|
814
|
+
policy = create_policy(options, AdminPolicy)
|
820
815
|
command = AdminCommand.new
|
821
816
|
command.query_user(@cluster, policy, user)
|
822
817
|
end
|
823
818
|
|
824
819
|
# Retrieve all users and their roles.
|
825
820
|
def query_users(options={})
|
826
|
-
policy =
|
821
|
+
policy = create_policy(options, AdminPolicy)
|
827
822
|
command = AdminCommand.new
|
828
823
|
command.query_users(@cluster, policy)
|
829
824
|
end
|
@@ -847,63 +842,33 @@ module Aerospike
|
|
847
842
|
end
|
848
843
|
end
|
849
844
|
|
850
|
-
def
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
def opt_to_policy(options)
|
861
|
-
if options.nil? || options == {}
|
862
|
-
@default_policy
|
863
|
-
elsif options.is_a?(Policy)
|
864
|
-
options
|
865
|
-
elsif options.is_a?(Hash)
|
866
|
-
Policy.new(options)
|
867
|
-
end
|
868
|
-
end
|
869
|
-
|
870
|
-
def opt_to_write_policy(options)
|
871
|
-
if options.nil? || options == {}
|
872
|
-
@default_write_policy
|
873
|
-
elsif options.is_a?(WritePolicy)
|
874
|
-
options
|
875
|
-
elsif options.is_a?(Hash)
|
876
|
-
WritePolicy.new(options)
|
877
|
-
end
|
878
|
-
end
|
879
|
-
|
880
|
-
def opt_to_scan_policy(options)
|
881
|
-
if options.nil? || options == {}
|
882
|
-
@default_scan_policy
|
883
|
-
elsif options.is_a?(ScanPolicy)
|
884
|
-
options
|
885
|
-
elsif options.is_a?(Hash)
|
886
|
-
ScanPolicy.new(options)
|
887
|
-
end
|
888
|
-
end
|
889
|
-
|
890
|
-
def opt_to_query_policy(options)
|
891
|
-
if options.nil? || options == {}
|
892
|
-
@default_query_policy
|
893
|
-
elsif options.is_a?(QueryPolicy)
|
894
|
-
options
|
895
|
-
elsif options.is_a?(Hash)
|
896
|
-
QueryPolicy.new(options)
|
845
|
+
def create_policy(policy, policy_klass)
|
846
|
+
case policy
|
847
|
+
when nil
|
848
|
+
policy_klass.new
|
849
|
+
when policy_klass
|
850
|
+
policy
|
851
|
+
when Hash
|
852
|
+
policy_klass.new(policy)
|
853
|
+
else
|
854
|
+
fail TypeError, "policy should be a #{policy_klass.name} instance or a Hash"
|
897
855
|
end
|
898
856
|
end
|
899
857
|
|
900
|
-
def
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
858
|
+
def parse_hosts(hosts)
|
859
|
+
case hosts
|
860
|
+
when Host
|
861
|
+
[hosts]
|
862
|
+
when Array
|
863
|
+
hosts
|
864
|
+
when String
|
865
|
+
hosts.split(?,).map { |host|
|
866
|
+
(addr, port) = host.split(?:)
|
867
|
+
port ||= 3000
|
868
|
+
Host.new(addr, port.to_i)
|
869
|
+
}
|
870
|
+
else
|
871
|
+
fail TypeError, "hosts should be a Host object, an Array of Host objects, or a String"
|
907
872
|
end
|
908
873
|
end
|
909
874
|
|
@@ -951,7 +916,7 @@ module Aerospike
|
|
951
916
|
bn = batch_node
|
952
917
|
bn.batch_namespaces.each do |bns|
|
953
918
|
threads << Thread.new do
|
954
|
-
abort_on_exception=true
|
919
|
+
Thread.current.abort_on_exception = true
|
955
920
|
command = cmd_gen.call(bn.node, bns)
|
956
921
|
execute_command(command)
|
957
922
|
end
|