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
@@ -20,7 +20,7 @@ module Aerospike
20
20
 
21
21
  private
22
22
 
23
- class BatchCommandExists < BatchCommand
23
+ class BatchCommandExists < BatchCommand #:nodoc:
24
24
 
25
25
  def initialize(node, batch_namespace, policy, key_map, exists_array)
26
26
  super(node)
@@ -20,7 +20,7 @@ module Aerospike
20
20
 
21
21
  private
22
22
 
23
- class BatchCommandGet < BatchCommand
23
+ class BatchCommandGet < BatchCommand #:nodoc:
24
24
 
25
25
  def initialize(node, batch_namespace, policy, key_map, bin_names, records, read_attr)
26
26
  super(node)
@@ -24,7 +24,7 @@ module Aerospike
24
24
 
25
25
  private
26
26
 
27
- class BatchItem
27
+ class BatchItem #:nodoc:
28
28
 
29
29
  def self.generate_map(keys)
30
30
  key_map = {}
@@ -26,7 +26,7 @@ module Aerospike
26
26
 
27
27
  BatchNamespace = Struct.new :namespace, :keys
28
28
 
29
- class BatchNode
29
+ class BatchNode #:nodoc:
30
30
 
31
31
  attr_accessor :node, :batch_namespaces, :key_capacity
32
32
 
@@ -73,7 +73,7 @@ module Aerospike
73
73
  CL_MSG_VERSION = 2
74
74
  AS_MSG_TYPE = 3
75
75
 
76
- class Command
76
+ class Command #:nodoc:
77
77
 
78
78
  def initialize(node)
79
79
  @node = node
@@ -431,7 +431,7 @@ module Aerospike
431
431
 
432
432
  # All runtime exceptions are considered fatal. Do not retry.
433
433
  # Close socket to flush out possible garbage. Do not put back in pool.
434
- @conn.close
434
+ @conn.close if @conn
435
435
  raise e
436
436
  end
437
437
 
@@ -444,7 +444,7 @@ module Aerospike
444
444
  rescue => e
445
445
  # IO errors are considered temporary anomalies. Retry.
446
446
  # Close socket to flush out possible garbage. Do not put back in pool.
447
- @conn.close
447
+ @conn.close if @conn
448
448
 
449
449
  Aerospike.logger.error("Node #{@node.to_s}: #{e}")
450
450
  # IO error means connection to server @node is unhealthy.
@@ -463,7 +463,7 @@ module Aerospike
463
463
  # cancelling/closing the batch/multi commands will return an error, which will
464
464
  # close the connection to throw away its data and signal the server about the
465
465
  # situation. We will not put back the connection in the buffer.
466
- @conn.close
466
+ @conn.close if @conn
467
467
  raise e
468
468
  end
469
469
 
@@ -550,8 +550,10 @@ module Aerospike
550
550
  @data_buffer.write_byte(read_attr, 9)
551
551
  @data_buffer.write_byte(write_attr, 10)
552
552
 
553
- for i in 11..25
553
+ i = 11
554
+ while i <= 25
554
555
  @data_buffer.write_byte(0, i)
556
+ i = i.succ
555
557
  end
556
558
 
557
559
  @data_buffer.write_int16(field_count, 26)
@@ -586,9 +588,6 @@ module Aerospike
586
588
  when Aerospike::GenerationPolicy::EXPECT_GEN_GT
587
589
  generation = policy.generation
588
590
  write_attr |= INFO2_GENERATION_GT
589
- when Aerospike::GenerationPolicy::DUPLICATE
590
- generation = policy.generation
591
- write_attr |= INFO2_GENERATION_DUP
592
591
  end
593
592
 
594
593
  info_attr |= INFO3_COMMIT_MASTER if policy.commit_level == Aerospike::CommitLevel::COMMIT_MASTER
@@ -601,10 +600,8 @@ module Aerospike
601
600
  @data_buffer.write_byte(info_attr, 11)
602
601
  @data_buffer.write_byte(0, 12) # unused
603
602
  @data_buffer.write_byte(0, 13) # clear the result code
604
- # Buffer.Int32ToBytes(generation, @data_buffer, 14)
605
- @data_buffer.write_int32(generation, 14)
606
- # Buffer.Int32ToBytes(policy.expiration, @data_buffer, 18)
607
- @data_buffer.write_int32(policy.expiration, 18)
603
+ @data_buffer.write_uint32(generation, 14)
604
+ @data_buffer.write_uint32(policy.expiration, 18)
608
605
 
609
606
  # Initialize timeout. It will be written later.
610
607
  @data_buffer.write_byte(0, 22)
@@ -613,9 +610,7 @@ module Aerospike
613
610
  @data_buffer.write_byte(0, 25)
614
611
 
615
612
 
616
- # Buffer.Int16ToBytes(field_count, @data_buffer, 26)
617
613
  @data_buffer.write_int16(field_count, 26)
618
- # Buffer.Int16ToBytes(operation_count, @data_buffer, 28)
619
614
  @data_buffer.write_int16(operation_count, 28)
620
615
 
621
616
  @data_offset = MSG_TOTAL_HEADER_SIZE
@@ -21,7 +21,7 @@ module Aerospike
21
21
 
22
22
  private
23
23
 
24
- class DeleteCommand < SingleCommand
24
+ class DeleteCommand < SingleCommand #:nodoc:
25
25
 
26
26
  attr_reader :existed
27
27
 
@@ -21,7 +21,7 @@ module Aerospike
21
21
 
22
22
  private
23
23
 
24
- class ExecuteCommand < ReadCommand
24
+ class ExecuteCommand < ReadCommand #:nodoc:
25
25
 
26
26
  def initialize(cluster, policy, key, package_name, function_name, args)
27
27
  super(cluster, policy, key, nil)
@@ -21,7 +21,7 @@ module Aerospike
21
21
 
22
22
  private
23
23
 
24
- class ExistsCommand < SingleCommand
24
+ class ExistsCommand < SingleCommand #:nodoc:
25
25
 
26
26
  attr_reader :exists
27
27
 
@@ -20,7 +20,7 @@ module Aerospike
20
20
 
21
21
  private
22
22
 
23
- class OperateCommand < ReadCommand
23
+ class OperateCommand < ReadCommand #:nodoc:
24
24
 
25
25
  def initialize(cluster, policy, key, operations)
26
26
  super(cluster, policy, key, nil)
@@ -24,7 +24,7 @@ module Aerospike
24
24
 
25
25
  private
26
26
 
27
- class ReadCommand < SingleCommand
27
+ class ReadCommand < SingleCommand #:nodoc:
28
28
 
29
29
  attr_reader :record
30
30
 
@@ -93,7 +93,7 @@ module Aerospike
93
93
 
94
94
  if op_count == 0
95
95
  # data Bin was not returned.
96
- @record = Record.new(@node, @key, nil, nil, generation, expiration)
96
+ @record = Record.new(@node, @key, generation, expiration)
97
97
  return
98
98
  end
99
99
 
@@ -107,24 +107,25 @@ module Aerospike
107
107
  end
108
108
 
109
109
  def parse_record(op_count, field_count, generation, expiration)
110
- bins = nil
111
- duplicates = nil
110
+ bins = op_count > 0 ? {} : nil
112
111
  receive_offset = 0
113
112
 
114
113
  # There can be fields in the response (setname etc).
115
114
  # But for now, ignore them. Expose them to the API if needed in the future.
116
- if field_count != 0
115
+ if field_count > 0
117
116
  # Just skip over all the fields
118
- for i in 0...field_count
117
+ i = 0
118
+ while i < field_count
119
119
  field_size = @data_buffer.read_int32(receive_offset)
120
120
  receive_offset += (4 + field_size)
121
+ i = i.succ
121
122
  end
122
123
  end
123
124
 
124
- for i in 0...op_count
125
+ i = 0
126
+ while i < op_count
125
127
  op_size = @data_buffer.read_int32(receive_offset)
126
128
  particle_type = @data_buffer.read(receive_offset+5).ord
127
- version = @data_buffer.read(receive_offset+6).ord
128
129
  name_size = @data_buffer.read(receive_offset+7).ord
129
130
  name = @data_buffer.read(receive_offset+8, name_size).force_encoding('utf-8')
130
131
  receive_offset += 4 + 4 + name_size
@@ -134,39 +135,12 @@ module Aerospike
134
135
  value = Aerospike.bytes_to_particle(particle_type, @data_buffer, receive_offset, particle_bytes_size)
135
136
  receive_offset += particle_bytes_size
136
137
 
137
- vmap = {}
138
-
139
- if version > 0 || duplicates != nil
140
- unless duplicates
141
- duplicates = []
142
- duplicates << bins
143
- bins = nil
144
-
145
- for j in 0..version-1
146
- duplicates << nil
147
- end
148
- else
149
- for j in duplicates.length..version
150
- duplicates << nil
151
- end
152
- end
138
+ bins[name] = value
153
139
 
154
- vmap = duplicates[version]
155
- unless vmap
156
- vmap = {}
157
- duplicates[version] = vmap
158
- end
159
- else
160
- bins = {} unless bins
161
- vmap = bins
162
- end
163
- vmap[name] = value
140
+ i = i.succ
164
141
  end
165
142
 
166
- # Remove nil duplicates just in case there were holes in the version number space.
167
- duplicates.compact! if duplicates
168
-
169
- Record.new(@node, @key, bins, duplicates, generation, expiration)
143
+ Record.new(@node, @key, bins, generation, expiration)
170
144
  end
171
145
 
172
146
  end # class
@@ -21,7 +21,7 @@ module Aerospike
21
21
 
22
22
  private
23
23
 
24
- class ReadHeaderCommand < SingleCommand
24
+ class ReadHeaderCommand < SingleCommand #:nodoc:
25
25
 
26
26
  attr_reader :record
27
27
 
@@ -46,7 +46,7 @@ module Aerospike
46
46
  if result_code == 0
47
47
  generation = @data_buffer.read_int32(14)
48
48
  expiration = Aerospike.TTL(@data_buffer.read_int32(18))
49
- @record = Record.new(@node, @key, nil, nil, generation, expiration)
49
+ @record = Record.new(@node, @key, nil, generation, expiration)
50
50
  else
51
51
  if result_code == Aerospike::ResultCode::KEY_NOT_FOUND_ERROR
52
52
  @record = nil
@@ -0,0 +1,36 @@
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
+ # Pre-defined user roles.
20
+ module Role
21
+
22
+ # Manage users their roles.
23
+ USER_ADMIN = 'user-admin'
24
+
25
+ # Manage indicies, user defined functions and server configuration.
26
+ SYS_ADMIN = 'sys-admin'
27
+
28
+ # Allow read and write transactions with the database.
29
+ READ_WRITE = 'read-write'
30
+
31
+ # Allow read transactions with the database.
32
+ READ = 'Read'
33
+
34
+ end # module
35
+
36
+ end # module
@@ -21,7 +21,7 @@ module Aerospike
21
21
 
22
22
  private
23
23
 
24
- class SingleCommand < Command
24
+ class SingleCommand < Command #:nodoc:
25
25
 
26
26
  def initialize(cluster, key)
27
27
  @cluster = cluster
@@ -20,7 +20,7 @@ module Aerospike
20
20
 
21
21
  private
22
22
 
23
- class TouchCommand < SingleCommand
23
+ class TouchCommand < SingleCommand #:nodoc:
24
24
 
25
25
  def initialize(cluster, policy, key)
26
26
  super(cluster, key)
@@ -20,7 +20,7 @@ module Aerospike
20
20
 
21
21
  private
22
22
 
23
- class WriteCommand < SingleCommand
23
+ class WriteCommand < SingleCommand #:nodoc:
24
24
 
25
25
  def initialize(cluster, policy, key, bins, operation)
26
26
 
@@ -85,7 +85,7 @@ module Aerospike
85
85
  return length
86
86
  rescue => e
87
87
  Aerospike.logger.error(e)
88
- conn.close
88
+ conn.close if conn
89
89
  raise e
90
90
  end
91
91
  end
@@ -42,7 +42,7 @@ module Aerospike
42
42
 
43
43
  def default_logger
44
44
  logger = Logger.new(STDOUT)
45
- logger.level = Logger::ERROR
45
+ logger.level = Logger::FATAL
46
46
  logger
47
47
  end
48
48
 
@@ -0,0 +1,33 @@
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
+ # Policy attributes used for user administration commands.
20
+ class AdminPolicy
21
+
22
+ # User administration command socket timeout in milliseconds.
23
+ # Default is one second timeout.
24
+ attr_accessor :timeout
25
+
26
+ # NewAdminPolicy generates a new AdminPolicy with default values.
27
+ def initialize(opt={})
28
+ @timeout = opt[:timeout] || 1
29
+ end
30
+
31
+ end # class
32
+
33
+ end # module
@@ -23,12 +23,12 @@ module Aerospike
23
23
  attr_accessor :max_concurrent_nodes, :record_queue_size,
24
24
  :wait_until_migrations_are_over
25
25
 
26
- def initialize(max_concurrent_nodes=nil, record_queue_size=nil, wait_until_migrations_are_over=nil)
27
- super()
26
+ def initialize(opt={})
27
+ super(opt)
28
28
 
29
- @max_concurrent_nodes = max_concurrent_nodes || 0
30
- @record_queue_size = record_queue_size || 5000
31
- @wait_until_migrations_are_over = wait_until_migrations_are_over.nil? ? false : wait_until_migrations_are_over
29
+ @max_concurrent_nodes = opt[:max_concurrent_nodes] || 0
30
+ @record_queue_size = opt[:record_queue_size] || 5000
31
+ @wait_until_migrations_are_over = opt[:wait_until_migrations_are_over].nil? ? false : wait_until_migrations_are_over
32
32
 
33
33
  self
34
34
  end
@@ -18,18 +18,29 @@ module Aerospike
18
18
  # Container object for client policy command.
19
19
  class ClientPolicy
20
20
 
21
+ attr_accessor :user, :password
21
22
  attr_accessor :timeout, :connection_queue_size, :fail_if_not_connected
22
23
 
23
- def initialize(timeout=nil, connection_queue_size=nil, fail_if_not_connected=nil)
24
+ def initialize(opt={})
24
25
  # Initial host connection timeout in seconds. The timeout when opening a connection
25
26
  # to the server host for the first time.
26
- @timeout = timeout || 1.0 # 1 second
27
+ @timeout = opt[:timeout] || 1.0 # 1 second
27
28
 
28
29
  # Size of the Connection Queue cache.
29
- @connection_queue_size = connection_queue_size || 64
30
+ @connection_queue_size = opt[:connection_queue_size] || 64
30
31
 
31
32
  # Throw exception if host connection fails during add_host.
32
- @fail_if_not_connected = fail_if_not_connected || true
33
+ @fail_if_not_connected = opt[:fail_if_not_connected] || true
34
+
35
+ # user name
36
+ @user = opt[:user]
37
+
38
+ # password
39
+ @password = opt[:password]
40
+ end
41
+
42
+ def requires_authentication
43
+ (@user && @user != '') || (@password && @password != '')
33
44
  end
34
45
 
35
46
  end # class