aerospike 0.1.6 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +22 -0
  3. data/lib/aerospike.rb +5 -0
  4. data/lib/aerospike/atomic/atomic.rb +3 -1
  5. data/lib/aerospike/client.rb +98 -32
  6. data/lib/aerospike/cluster/cluster.rb +25 -8
  7. data/lib/aerospike/cluster/connection.rb +1 -1
  8. data/lib/aerospike/cluster/node.rb +16 -3
  9. data/lib/aerospike/cluster/node_validator.rb +16 -4
  10. data/lib/aerospike/cluster/partition.rb +1 -1
  11. data/lib/aerospike/cluster/partition_tokenizer_new.rb +4 -2
  12. data/lib/aerospike/cluster/partition_tokenizer_old.rb +1 -1
  13. data/lib/aerospike/command/admin_command.rb +353 -0
  14. data/lib/aerospike/command/batch_command.rb +12 -42
  15. data/lib/aerospike/command/batch_command_exists.rb +1 -1
  16. data/lib/aerospike/command/batch_command_get.rb +1 -1
  17. data/lib/aerospike/command/batch_item.rb +1 -1
  18. data/lib/aerospike/command/batch_node.rb +1 -1
  19. data/lib/aerospike/command/command.rb +9 -14
  20. data/lib/aerospike/command/delete_command.rb +1 -1
  21. data/lib/aerospike/command/execute_command.rb +1 -1
  22. data/lib/aerospike/command/exists_command.rb +1 -1
  23. data/lib/aerospike/command/operate_command.rb +1 -1
  24. data/lib/aerospike/command/read_command.rb +12 -38
  25. data/lib/aerospike/command/read_header_command.rb +2 -2
  26. data/lib/aerospike/command/roles.rb +36 -0
  27. data/lib/aerospike/command/single_command.rb +1 -1
  28. data/lib/aerospike/command/touch_command.rb +1 -1
  29. data/lib/aerospike/command/write_command.rb +1 -1
  30. data/lib/aerospike/info.rb +1 -1
  31. data/lib/aerospike/loggable.rb +1 -1
  32. data/lib/aerospike/policy/admin_policy.rb +33 -0
  33. data/lib/aerospike/policy/batch_policy.rb +5 -5
  34. data/lib/aerospike/policy/client_policy.rb +15 -4
  35. data/lib/aerospike/policy/generation_policy.rb +0 -5
  36. data/lib/aerospike/policy/policy.rb +6 -6
  37. data/lib/aerospike/policy/query_policy.rb +2 -2
  38. data/lib/aerospike/policy/scan_policy.rb +6 -6
  39. data/lib/aerospike/policy/write_policy.rb +8 -8
  40. data/lib/aerospike/query/query_command.rb +1 -1
  41. data/lib/aerospike/query/scan_command.rb +1 -1
  42. data/lib/aerospike/query/stream_command.rb +1 -1
  43. data/lib/aerospike/record.rb +2 -3
  44. data/lib/aerospike/result_code.rb +11 -1
  45. data/lib/aerospike/user_role.rb +30 -0
  46. data/lib/aerospike/utils/buffer.rb +22 -2
  47. data/lib/aerospike/utils/epoc.rb +3 -1
  48. data/lib/aerospike/utils/pool.rb +1 -1
  49. data/lib/aerospike/value/value.rb +12 -13
  50. data/lib/aerospike/version.rb +1 -1
  51. metadata +6 -2
@@ -27,11 +27,6 @@ module Aerospike
27
27
  # This is useful for restore after backup.
28
28
  EXPECT_GEN_GT = 2
29
29
 
30
- # Create duplicate record if expected generation is not equal to server generation.
31
- # Duplicates are only created when the server configuration option "allow-versions"
32
- # is true (default is false).
33
- DUPLICATE = 3
34
-
35
30
  end # module
36
31
 
37
32
  end # module
@@ -24,34 +24,34 @@ module Aerospike
24
24
 
25
25
  attr_accessor :priority, :timeout, :max_retries, :sleep_between_retries, :consistency_level
26
26
 
27
- def initialize(priority=nil, timeout=nil, max_retiries=nil, sleep_between_retries=nil, consistency_level=nil)
27
+ def initialize(opt={})
28
28
  # Container object for transaction policy attributes used in all database
29
29
  # operation calls.
30
30
 
31
31
  # Priority of request relative to other transactions.
32
32
  # Currently, only used for scans.
33
- @priority = priority || Priority::DEFAULT
33
+ @priority = opt[:priority] || Priority::DEFAULT
34
34
 
35
35
  # How replicas should be consulted in a read operation to provide the desired
36
36
  # consistency guarantee. Default to allowing one replica to be used in the
37
37
  # read operation.
38
- @consistency_level = consistency_level || Aerospike::ConsistencyLevel::CONSISTENCY_ONE
38
+ @consistency_level = opt[:consistency_level] || Aerospike::ConsistencyLevel::CONSISTENCY_ONE
39
39
 
40
40
  # Transaction timeout.
41
41
  # This timeout is used to set the socket timeout and is also sent to the
42
42
  # server along with the transaction in the wire protocol.
43
43
  # Default to no timeout (0).
44
- @timeout = timeout || 0
44
+ @timeout = opt[:timeout] || 0
45
45
 
46
46
  # Maximum number of retries before aborting the current transaction.
47
47
  # A retry is attempted when there is a network error other than timeout.
48
48
  # If max_retries is exceeded, the abort will occur even if the timeout
49
49
  # has not yet been exceeded.
50
- @max_retries = max_retiries || 2
50
+ @max_retries = opt[:max_retiries] || 2
51
51
 
52
52
  # Duration to sleep between retries if a transaction fails and the
53
53
  # timeout was not exceeded. Enter zero to skip sleep.
54
- @sleep_between_retries = sleep_between_retries || 0.5
54
+ @sleep_between_retries = opt[:sleep_between_retries] || 0.5
55
55
  end
56
56
 
57
57
 
@@ -20,8 +20,8 @@ module Aerospike
20
20
  # Container object for scan policy command.
21
21
  class QueryPolicy < BatchPolicy
22
22
 
23
- def initialize()
24
- super()
23
+ def initialize(opt={})
24
+ super(opt)
25
25
 
26
26
  @max_retries = 0
27
27
 
@@ -23,13 +23,13 @@ module Aerospike
23
23
  attr_accessor :scan_percent, :concurrent_nodes,
24
24
  :include_bin_data, :fail_on_cluster_change
25
25
 
26
- def initialize(scan_percent=nil, concurrent_nodes=nil, include_bin_data=nil, fail_on_cluster_change=nil)
27
- super()
26
+ def initialize(opt={})
27
+ super(opt)
28
28
 
29
- @scan_percent = scan_percent || 100
30
- @concurrent_nodes = concurrent_nodes.nil? ? true : concurrent_nodes
31
- @include_bin_data = include_bin_data.nil? ? true : include_bin_data
32
- @fail_on_cluster_change = fail_on_cluster_change.nil? ? true : fail_on_cluster_change
29
+ @scan_percent = opt[:scan_percent] || 100
30
+ @concurrent_nodes = opt[:concurrent_nodes].nil? ? true : concurrent_nodes
31
+ @include_bin_data = opt[:include_bin_data].nil? ? true : include_bin_data
32
+ @fail_on_cluster_change = opt[:fail_on_cluster_change].nil? ? true : fail_on_cluster_change
33
33
 
34
34
  @max_retries = 0
35
35
 
@@ -26,25 +26,25 @@ module Aerospike
26
26
  attr_accessor :record_exists_action, :generation_policy,
27
27
  :generation, :expiration, :send_key, :commit_level
28
28
 
29
- def initialize(record_exists_action=nil, gen_policy=nil, generation=nil, expiration=nil, send_key=nil, commit_level=nil)
30
- super()
29
+ def initialize(opt={})
30
+ super(opt)
31
31
 
32
32
  # Qualify how to handle writes where the record already exists.
33
- @record_exists_action = record_exists_action || RecordExistsAction::UPDATE
33
+ @record_exists_action = opt[:record_exists_action] || RecordExistsAction::UPDATE
34
34
 
35
35
  # Qualify how to handle record writes based on record generation. The default (NONE)
36
36
  # indicates that the generation is not used to restrict writes.
37
- @generation_policy = gen_policy || GenerationPolicy::NONE
37
+ @generation_policy = opt[:gen_policy] || GenerationPolicy::NONE
38
38
 
39
39
  # Desired consistency guarantee when committing a transaction on the server. The default
40
40
  # (COMMIT_ALL) indicates that the server should wait for master and all replica commits to
41
41
  # be successful before returning success to the client.
42
- @commit_level = commit_level || Aerospike::CommitLevel::COMMIT_ALL
42
+ @commit_level = opt[:commit_level] || Aerospike::CommitLevel::COMMIT_ALL
43
43
 
44
44
  # Expected generation. Generation is the number of times a record has been modified
45
45
  # (including creation) on the server. If a write operation is creating a record,
46
46
  # the expected generation would be 0
47
- @generation = generation || 0
47
+ @generation = opt[:generation] || 0
48
48
 
49
49
  # Record expiration. Also known as ttl (time to live).
50
50
  # Seconds record will live before being removed by the server.
@@ -53,11 +53,11 @@ module Aerospike
53
53
  # versions >= 3.1.4. Do not use -1 for older servers.
54
54
  # 0: Default to namespace configuration variable "default-ttl" on the server.
55
55
  # > 0: Actual expiration in seconds.
56
- @expiration = expiration || 0
56
+ @expiration = opt[:expiration] || 0
57
57
 
58
58
  # Send user defined key in addition to hash digest on a record put.
59
59
  # The default is to send the user defined key.
60
- @send_key = send_key.nil? ? true : send_key
60
+ @send_key = opt[:send_key].nil? ? true : send_key
61
61
 
62
62
  self
63
63
  end
@@ -21,7 +21,7 @@ module Aerospike
21
21
 
22
22
  private
23
23
 
24
- class QueryCommand < StreamCommand
24
+ class QueryCommand < StreamCommand #:nodoc:
25
25
 
26
26
  def initialize(node, policy, statement, recordset)
27
27
  super(node)
@@ -21,7 +21,7 @@ module Aerospike
21
21
 
22
22
  private
23
23
 
24
- class ScanCommand < StreamCommand
24
+ class ScanCommand < StreamCommand #:nodoc:
25
25
 
26
26
  def initialize(node, policy, namespace, set_name, bin_names, recordset)
27
27
  super(node)
@@ -24,7 +24,7 @@ module Aerospike
24
24
 
25
25
  private
26
26
 
27
- class StreamCommand < BatchCommand
27
+ class StreamCommand < BatchCommand #:nodoc:
28
28
 
29
29
  def parse_record_results(receive_size)
30
30
  @data_offset = 0
@@ -20,15 +20,14 @@ module Aerospike
20
20
 
21
21
  class Record
22
22
 
23
- attr_reader :key, :bins, :generation, :expiration, :node, :dups
23
+ attr_reader :key, :bins, :generation, :expiration, :node
24
24
 
25
- def initialize(node, rec_key, rec_bins, dups, rec_gen, rec_exp)
25
+ def initialize(node, rec_key, rec_bins, rec_gen, rec_exp)
26
26
  @key = rec_key
27
27
  @bins = rec_bins
28
28
  @generation = rec_gen
29
29
  @expiration = rec_exp
30
30
  @node = node
31
- @dups = dups
32
31
  end
33
32
 
34
33
  def to_s
@@ -128,10 +128,14 @@ module Aerospike
128
128
  # User was previously created.
129
129
  USER_ALREADY_EXISTS = 61
130
130
 
131
-
132
131
  # Password is invalid.
133
132
  INVALID_PASSWORD = 62
134
133
 
134
+ # Password is invalid.
135
+ EXPIRED_PASSWORD = 63
136
+
137
+ # Password is invalid.
138
+ FORBIDDEN_PASSWORD = 64
135
139
 
136
140
  # Security credential is invalid.
137
141
  INVALID_CREDENTIAL = 63
@@ -297,6 +301,12 @@ module Aerospike
297
301
  when INVALID_PASSWORD
298
302
  "Invalid password"
299
303
 
304
+ when EXPIRED_PASSWORD
305
+ "Expired password"
306
+
307
+ when FORBIDDEN_PASSWORD
308
+ "Forbidden password"
309
+
300
310
  when INVALID_CREDENTIAL
301
311
  "Invalid credential"
302
312
 
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+ # Copyright 2014 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
+
19
+ # User and assigned roles.
20
+ class UserRoles
21
+
22
+ # User name.
23
+ attr_accessor :user
24
+
25
+ # List of assigned roles.
26
+ attr_accessor :roles
27
+
28
+ end
29
+
30
+ end
@@ -21,7 +21,7 @@ module Aerospike
21
21
  private
22
22
 
23
23
  # Buffer class to ease the work around
24
- class Buffer
24
+ class Buffer #:nodoc:
25
25
 
26
26
  @@buf_pool = Pool.new
27
27
  @@buf_pool.create_block = Proc.new { Buffer.new }
@@ -29,8 +29,11 @@ module Aerospike
29
29
  attr_accessor :buf
30
30
 
31
31
  INT16 = 's>'
32
+ UINT16 = 'n'
32
33
  INT32 = 'l>'
34
+ UINT32 = 'N'
33
35
  INT64 = 'q>'
36
+ UINT64 = 'Q>'
34
37
 
35
38
  DEFAULT_BUFFER_SIZE = 16 * 1024
36
39
  MAX_BUFFER_SIZE = 10 * 1024 * 1024
@@ -76,16 +79,31 @@ module Aerospike
76
79
  2
77
80
  end
78
81
 
82
+ def write_uint16(i, offset)
83
+ @buf[offset, 2] = [i].pack(UINT16)
84
+ 2
85
+ end
86
+
79
87
  def write_int32(i, offset)
80
88
  @buf[offset, 4] = [i].pack(INT32)
81
89
  4
82
90
  end
83
91
 
92
+ def write_uint32(i, offset)
93
+ @buf[offset, 4] = [i].pack(UINT32)
94
+ 4
95
+ end
96
+
84
97
  def write_int64(i, offset)
85
98
  @buf[offset, 8] = [i].pack(INT64)
86
99
  8
87
100
  end
88
101
 
102
+ def write_uint64(i, offset)
103
+ @buf[offset, 8] = [i].pack(UINT64)
104
+ 8
105
+ end
106
+
89
107
  def read(offset, len=nil)
90
108
  start = offset
91
109
 
@@ -113,9 +131,11 @@ module Aerospike
113
131
 
114
132
  def read_var_int64(offset, len)
115
133
  val = 0
116
- for i in 0...len
134
+ i = 0
135
+ while i < len
117
136
  val <<= 8
118
137
  val |= @buf[offset+i].ord & 0xFF
138
+ i = i.succ
119
139
  end
120
140
  val
121
141
  end
@@ -18,10 +18,12 @@ require 'time'
18
18
 
19
19
  module Aerospike
20
20
 
21
+ private
22
+
21
23
  CITRUSLEAF_EPOCH = 1262304000
22
24
 
23
25
  # Converts an Expiration time to TTL in seconds
24
- def self.TTL(secs_from_citrus_leaf_epoc)
26
+ def self.TTL(secs_from_citrus_leaf_epoc) #:nodoc:
25
27
  if secs_from_citrus_leaf_epoc == 0
26
28
  0xFFFFFFFF
27
29
  else
@@ -21,7 +21,7 @@ module Aerospike
21
21
 
22
22
  private
23
23
 
24
- class Pool
24
+ class Pool #:nodoc:
25
25
 
26
26
  attr_accessor :create_block, :cleanup_block
27
27
 
@@ -25,7 +25,7 @@ module Aerospike
25
25
  private
26
26
 
27
27
  # Polymorphic value classes used to efficiently serialize objects into the wire protocol.
28
- class Value
28
+ class Value #:nodoc:
29
29
 
30
30
  @@packer_pool = Pool.new
31
31
  @@packer_pool.create_block = Proc.new { MessagePack::Packer.new }
@@ -71,7 +71,7 @@ module Aerospike
71
71
 
72
72
 
73
73
  # Empty value.
74
- class NullValue < Value
74
+ class NullValue < Value #:nodoc:
75
75
 
76
76
  def initialize
77
77
  self
@@ -108,7 +108,7 @@ module Aerospike
108
108
  end
109
109
 
110
110
  # Byte array value.
111
- class BytesValue < Value
111
+ class BytesValue < Value #:nodoc:
112
112
 
113
113
  def initialize(value)
114
114
  @bytes = value
@@ -139,7 +139,6 @@ module Aerospike
139
139
 
140
140
  def write(buffer, offset)
141
141
  buffer.write_binary(@bytes, offset)
142
- buffer.length
143
142
  end
144
143
 
145
144
  def pack(packer)
@@ -151,7 +150,7 @@ module Aerospike
151
150
  #######################################
152
151
 
153
152
  # value string.
154
- class StringValue < Value
153
+ class StringValue < Value #:nodoc:
155
154
 
156
155
  def initialize(val)
157
156
  @value = val || ''
@@ -191,7 +190,7 @@ module Aerospike
191
190
  #######################################
192
191
 
193
192
  # Integer value.
194
- class IntegerValue < Value
193
+ class IntegerValue < Value #:nodoc:
195
194
 
196
195
  def initialize(val)
197
196
  @value = val || 0
@@ -231,7 +230,7 @@ module Aerospike
231
230
 
232
231
  # List value.
233
232
  # Supported by Aerospike 3 servers only.
234
- class ListValue < Value
233
+ class ListValue < Value #:nodoc:
235
234
 
236
235
  def initialize(list)
237
236
  @list = list || nil
@@ -281,7 +280,7 @@ module Aerospike
281
280
 
282
281
  # Map value.
283
282
  # Supported by Aerospike 3 servers only.
284
- class MapValue < Value
283
+ class MapValue < Value #:nodoc:
285
284
 
286
285
  def initialize(vmap)
287
286
  @vmap = vmap || {}
@@ -334,7 +333,7 @@ module Aerospike
334
333
 
335
334
  protected
336
335
 
337
- def self.normalize_elem(elem)
336
+ def self.normalize_elem(elem) # :nodoc:
338
337
  case elem
339
338
  when String
340
339
  elem[1..-1]
@@ -347,17 +346,17 @@ module Aerospike
347
346
  end
348
347
  end
349
348
 
350
- def self.normalize_strings_in_array(arr)
349
+ def self.normalize_strings_in_array(arr) # :nodoc:
351
350
  arr.map! { |elem| normalize_elem(elem) }
352
351
  end
353
352
 
354
- def self.normalize_strings_in_map(hash)
353
+ def self.normalize_strings_in_map(hash) # :nodoc:
355
354
  hash.inject({}) do |h, (k,v)|
356
355
  h.update({ normalize_elem(k) => normalize_elem(v) })
357
356
  end
358
357
  end
359
358
 
360
- def self.bytes_to_particle(type, buf, offset, length)
359
+ def self.bytes_to_particle(type, buf, offset, length) # :nodoc:
361
360
 
362
361
  case type
363
362
  when Aerospike::ParticleType::STRING
@@ -380,7 +379,7 @@ module Aerospike
380
379
  end
381
380
  end
382
381
 
383
- def self.bytes_to_key_value(type, buf, offset, len)
382
+ def self.bytes_to_key_value(type, buf, offset, len) # :nodoc:
384
383
 
385
384
  case type
386
385
  when Aerospike::ParticleType::STRING
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Aerospike
3
- VERSION = "0.1.6"
3
+ VERSION = "1.0.0"
4
4
  end