aerospike 2.5.1 → 2.6.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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -0
  3. data/README.md +3 -3
  4. data/lib/aerospike.rb +33 -6
  5. data/lib/aerospike/aerospike_exception.rb +9 -26
  6. data/lib/aerospike/client.rb +7 -22
  7. data/lib/aerospike/{cluster/cluster.rb → cluster.rb} +122 -161
  8. data/lib/aerospike/cluster/create_connection.rb +42 -0
  9. data/lib/aerospike/cluster/find_node.rb +35 -0
  10. data/lib/aerospike/connection/authenticate.rb +35 -0
  11. data/lib/aerospike/connection/create.rb +36 -0
  12. data/lib/aerospike/host.rb +7 -4
  13. data/lib/aerospike/host/parse.rb +50 -0
  14. data/lib/aerospike/node.rb +232 -0
  15. data/lib/aerospike/node/generation.rb +50 -0
  16. data/lib/aerospike/node/refresh/failed.rb +34 -0
  17. data/lib/aerospike/node/refresh/friends.rb +100 -0
  18. data/lib/aerospike/node/refresh/info.rb +60 -0
  19. data/lib/aerospike/node/refresh/partitions.rb +60 -0
  20. data/lib/aerospike/node/refresh/peers.rb +83 -0
  21. data/lib/aerospike/node/refresh/reset.rb +36 -0
  22. data/lib/aerospike/node/verify/cluster_name.rb +35 -0
  23. data/lib/aerospike/node/verify/name.rb +43 -0
  24. data/lib/aerospike/node/verify/partition_generation.rb +43 -0
  25. data/lib/aerospike/node/verify/peers_generation.rb +41 -0
  26. data/lib/aerospike/{cluster/node_validator.rb → node_validator.rb} +29 -47
  27. data/lib/aerospike/peer.rb +24 -0
  28. data/lib/aerospike/peers.rb +44 -0
  29. data/lib/aerospike/peers/fetch.rb +36 -0
  30. data/lib/aerospike/peers/parse.rb +88 -0
  31. data/lib/aerospike/policy/client_policy.rb +16 -9
  32. data/lib/aerospike/socket/base.rb +86 -0
  33. data/lib/aerospike/socket/ssl.rb +70 -0
  34. data/lib/aerospike/socket/tcp.rb +57 -0
  35. data/lib/aerospike/utils/buffer.rb +7 -6
  36. data/lib/aerospike/utils/string_parser.rb +53 -0
  37. data/lib/aerospike/value/value.rb +7 -8
  38. data/lib/aerospike/version.rb +1 -1
  39. metadata +30 -7
  40. data/lib/aerospike/cluster/connection.rb +0 -124
  41. data/lib/aerospike/cluster/node.rb +0 -274
@@ -1,17 +1,21 @@
1
1
  # encoding: utf-8
2
- # Copyright 2014-2017 Aerospike, Inc.
2
+
3
+ # Copyright 2014-2018 Aerospike, Inc.
4
+ #
5
+ # Portions may be licensed to Aerospike, Inc. under one or more contributor
6
+ # license agreements.
3
7
  #
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
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
7
11
  #
8
- # http:#www.apache.org/licenses/LICENSE-2.0
12
+ # http://www.apache.org/licenses/LICENSE-2.0
9
13
  #
10
14
  # 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
+ # 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.
15
19
 
16
20
  module Aerospike
17
21
 
@@ -21,6 +25,7 @@ module Aerospike
21
25
  attr_accessor :user, :password
22
26
  attr_accessor :timeout, :connection_queue_size, :fail_if_not_connected, :tend_interval
23
27
  attr_accessor :cluster_name
28
+ attr_accessor :ssl_options
24
29
 
25
30
  def initialize(opt={})
26
31
  # Initial host connection timeout in seconds. The timeout when opening a connection
@@ -45,6 +50,8 @@ module Aerospike
45
50
 
46
51
  # Cluster Name
47
52
  @cluster_name = opt[:cluster_name]
53
+
54
+ @ssl_options = opt[:ssl_options]
48
55
  end
49
56
 
50
57
  def requires_authentication
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2014-2018 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 Socket
22
+ module Base
23
+ def initialize(*args)
24
+ super(*args)
25
+ @timeout = nil
26
+ end
27
+
28
+ def read(buffer, length)
29
+ bytes_read = 0
30
+ until bytes_read >= length
31
+ result = read_from_socket(length - bytes_read)
32
+ buffer.write_binary(result, bytes_read)
33
+ bytes_read += result.bytesize
34
+ end
35
+ end
36
+
37
+ def read_from_socket(length)
38
+ begin
39
+ read_nonblock(length)
40
+ rescue ::IO::WaitReadable => e
41
+ if ::IO::select([self], nil, nil, @timeout)
42
+ retry
43
+ else
44
+ raise ::Aerospike::Exceptions::Connection.new("#{e}")
45
+ end
46
+ rescue => e
47
+ raise ::Aerospike::Exceptions::Connection.new("#{e}")
48
+ end
49
+ end
50
+
51
+ def write(buffer, length)
52
+ bytes_written = 0
53
+ until bytes_written >= length
54
+ bytes_written += write_to_socket(buffer.read(bytes_written, length - bytes_written))
55
+ end
56
+ end
57
+
58
+ def write_to_socket(data)
59
+ begin
60
+ write_nonblock(data)
61
+ rescue ::IO::WaitWritable => e
62
+ if ::IO::select(nil, [self], nil, @timeout)
63
+ retry
64
+ else
65
+ raise ::Aerospike::Exceptions::Connection.new("#{e}")
66
+ end
67
+ rescue => e
68
+ raise ::Aerospike::Exceptions::Connection.new("#{e}")
69
+ end
70
+ end
71
+
72
+ def timeout=(timeout)
73
+ @timeout = timeout && timeout > 0 ? timeout : nil
74
+ end
75
+
76
+ def connected?
77
+ !closed?
78
+ end
79
+
80
+ def close
81
+ return if closed?
82
+ super()
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2018 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 Socket
22
+ class SSL < ::OpenSSL::SSL::SSLSocket
23
+ include Base
24
+
25
+ SUPPORTED_SSL_PARAMS = %i[ca_file ca_path min_version max_version].freeze
26
+ DEFAULT_SSL_PARAMS = {
27
+ min_version: :TLS1_2
28
+ }.freeze
29
+
30
+ class << self
31
+ def connect(host, port, timeout, tls_name, ssl_options)
32
+ Aerospike.logger.debug("Connecting to #{host}:#{tls_name}:#{port} using SSL options #{ssl_options}")
33
+ tcp_sock = TCP.connect(host, port, timeout)
34
+ ctx = build_ssl_context(ssl_options)
35
+ new(tcp_sock, ctx).tap do |ssl_sock|
36
+ ssl_sock.hostname = tls_name
37
+ ssl_sock.connect
38
+ ssl_sock.post_connection_check(tls_name)
39
+ end
40
+ end
41
+
42
+ def build_ssl_context(ssl_options)
43
+ ssl_options[:context] || create_context(ssl_options)
44
+ end
45
+
46
+ def create_context(ssl_options)
47
+ OpenSSL::SSL::SSLContext.new.tap do |ctx|
48
+ if ssl_options[:cert_file] && ssl_options[:pkey_file]
49
+ cert = OpenSSL::X509::Certificate.new(File.read(ssl_options[:cert_file]))
50
+ pkey = OpenSSL::PKey.read(File.read(ssl_options[:pkey_file]), ssl_options[:pkey_pass])
51
+ if ctx.respond_to?(:add_certificate)
52
+ ctx.add_certificate(cert, pkey)
53
+ else
54
+ ctx.cert = cert
55
+ ctx.key = pkey
56
+ end
57
+ end
58
+
59
+ params = DEFAULT_SSL_PARAMS.merge(filter_params(ssl_options))
60
+ ctx.set_params(params) unless params.empty?
61
+ end
62
+ end
63
+
64
+ def filter_params(params)
65
+ params.select { |key| SUPPORTED_SSL_PARAMS.include?(key) }
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2018 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
+ require 'socket'
21
+
22
+ module Aerospike
23
+ module Socket
24
+ class TCP < ::Socket
25
+ include Base
26
+
27
+ def self.connect(host, port, timeout)
28
+ Aerospike.logger.debug("Trying to connect to #{host}:#{port} with #{timeout}s timeout")
29
+ sock = new(::Socket::AF_INET, ::Socket::SOCK_STREAM, 0)
30
+ sockaddr = ::Socket.sockaddr_in(port, host)
31
+
32
+ begin
33
+ sock.connect_nonblock(sockaddr)
34
+ rescue IO::WaitWritable, Errno::EINPROGRESS
35
+ ::IO.select(nil, [sock], nil, timeout)
36
+
37
+ # Because IO.select behaves (return values are different) differently on
38
+ # different rubies, lets just try `connect_noblock` again. An exception
39
+ # is raised to indicate the current state of the connection, and at this
40
+ # point, we are ready to decide if this is a success or a timeout.
41
+ begin
42
+ sock.connect_nonblock(sockaddr)
43
+ rescue Errno::EISCONN
44
+ # Good, we're connected.
45
+ rescue Errno::EINPROGRESS, Errno::EALREADY
46
+ # Bad, we're still waiting to connect.
47
+ raise ::Aerospike::Exceptions::Connection, "Connection attempt to #{host}:#{port} timed out after #{timeout} secs"
48
+ rescue => e
49
+ raise ::Aerospike::Exceptions::Connection, e.message
50
+ end
51
+ end
52
+
53
+ sock
54
+ end
55
+ end
56
+ end
57
+ end
@@ -1,12 +1,15 @@
1
1
  # encoding: utf-8
2
- # Copyright 2014-2017 Aerospike, Inc.
2
+
3
+ # Copyright 2014-2018 Aerospike, Inc.
3
4
  #
4
5
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
5
6
  # license agreements.
6
7
  #
7
8
  # Licensed under the Apache License, Version 2.0 (the "License"); you may not
8
9
  # 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
+ # the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
10
13
  #
11
14
  # Unless required by applicable law or agreed to in writing, software
12
15
  # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
@@ -111,12 +114,10 @@ module Aerospike
111
114
  end
112
115
 
113
116
  def read(offset, len=nil)
114
- start = offset
115
-
116
117
  if len
117
- @buf[start, len]
118
+ @buf[offset, len]
118
119
  else
119
- @buf.getbyte(start)
120
+ @buf.getbyte(offset)
120
121
  end
121
122
  end
122
123
 
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2018 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 Utils
22
+ class StringParser
23
+ attr_reader :io
24
+ def initialize(str)
25
+ @io = ::StringIO.new(str)
26
+ end
27
+
28
+ def current
29
+ @io.string[@io.tell]
30
+ end
31
+
32
+ # Reads next character and raise if not matching desired one
33
+ def expect(char)
34
+ raise ::Aerospike::Exceptions::Parse unless @io.read(1) == char
35
+ end
36
+
37
+ def read_until(char)
38
+ [].tap do |result|
39
+ loop do
40
+ chr = @io.read(1)
41
+ break if chr == char
42
+ result << chr
43
+ end
44
+ end.join
45
+ end
46
+
47
+ def step(count = 1)
48
+ @io.read(count)
49
+ end
50
+
51
+ end
52
+ end
53
+ end
@@ -1,12 +1,15 @@
1
1
  # encoding: utf-8
2
- # Copyright 2014-2017 Aerospike, Inc.
2
+
3
+ # Copyright 2014-2018 Aerospike, Inc.
3
4
  #
4
5
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
5
6
  # license agreements.
6
7
  #
7
8
  # Licensed under the Apache License, Version 2.0 (the "License"); you may not
8
9
  # 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
+ # the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
10
13
  #
11
14
  # Unless required by applicable law or agreed to in writing, software
12
15
  # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
@@ -14,22 +17,19 @@
14
17
  # License for the specific language governing permissions and limitations under
15
18
  # the License.
16
19
 
17
-
18
20
  require 'aerospike/aerospike_exception'
19
21
 
20
22
  module Aerospike
21
-
22
- private
23
-
24
23
  # Polymorphic value classes used to efficiently serialize objects into the wire protocol.
25
24
  class Value #:nodoc:
25
+ INTEGER_RANGE = Range.new(-2**63, 2**63 - 1).freeze
26
26
 
27
27
  def self.of(value)
28
28
  case value
29
29
  when nil
30
30
  res = NullValue.new
31
31
  when Integer
32
- if value < 2**63
32
+ if INTEGER_RANGE.cover?(value)
33
33
  res = IntegerValue.new(value)
34
34
  else
35
35
  # big nums > 2**63 are not supported
@@ -480,5 +480,4 @@ module Aerospike
480
480
  nil
481
481
  end
482
482
  end
483
-
484
483
  end # module
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Aerospike
3
- VERSION = "2.5.1"
3
+ VERSION = "2.6.0"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aerospike
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.1
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Khosrow Afroozeh
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-01-25 00:00:00.000000000 Z
12
+ date: 2018-03-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: msgpack
@@ -62,10 +62,9 @@ files:
62
62
  - lib/aerospike/cdt/map_return_type.rb
63
63
  - lib/aerospike/cdt/map_write_mode.rb
64
64
  - lib/aerospike/client.rb
65
- - lib/aerospike/cluster/cluster.rb
66
- - lib/aerospike/cluster/connection.rb
67
- - lib/aerospike/cluster/node.rb
68
- - lib/aerospike/cluster/node_validator.rb
65
+ - lib/aerospike/cluster.rb
66
+ - lib/aerospike/cluster/create_connection.rb
67
+ - lib/aerospike/cluster/find_node.rb
69
68
  - lib/aerospike/cluster/partition.rb
70
69
  - lib/aerospike/cluster/partition_tokenizer_new.rb
71
70
  - lib/aerospike/cluster/partition_tokenizer_old.rb
@@ -88,13 +87,33 @@ files:
88
87
  - lib/aerospike/command/touch_command.rb
89
88
  - lib/aerospike/command/unsupported_particle_type_validator.rb
90
89
  - lib/aerospike/command/write_command.rb
90
+ - lib/aerospike/connection/authenticate.rb
91
+ - lib/aerospike/connection/create.rb
91
92
  - lib/aerospike/geo_json.rb
92
93
  - lib/aerospike/host.rb
94
+ - lib/aerospike/host/parse.rb
93
95
  - lib/aerospike/info.rb
94
96
  - lib/aerospike/key.rb
95
97
  - lib/aerospike/language.rb
96
98
  - lib/aerospike/loggable.rb
99
+ - lib/aerospike/node.rb
100
+ - lib/aerospike/node/generation.rb
101
+ - lib/aerospike/node/refresh/failed.rb
102
+ - lib/aerospike/node/refresh/friends.rb
103
+ - lib/aerospike/node/refresh/info.rb
104
+ - lib/aerospike/node/refresh/partitions.rb
105
+ - lib/aerospike/node/refresh/peers.rb
106
+ - lib/aerospike/node/refresh/reset.rb
107
+ - lib/aerospike/node/verify/cluster_name.rb
108
+ - lib/aerospike/node/verify/name.rb
109
+ - lib/aerospike/node/verify/partition_generation.rb
110
+ - lib/aerospike/node/verify/peers_generation.rb
111
+ - lib/aerospike/node_validator.rb
97
112
  - lib/aerospike/operation.rb
113
+ - lib/aerospike/peer.rb
114
+ - lib/aerospike/peers.rb
115
+ - lib/aerospike/peers/fetch.rb
116
+ - lib/aerospike/peers/parse.rb
98
117
  - lib/aerospike/policy/admin_policy.rb
99
118
  - lib/aerospike/policy/batch_policy.rb
100
119
  - lib/aerospike/policy/client_policy.rb
@@ -117,6 +136,9 @@ files:
117
136
  - lib/aerospike/query/stream_command.rb
118
137
  - lib/aerospike/record.rb
119
138
  - lib/aerospike/result_code.rb
139
+ - lib/aerospike/socket/base.rb
140
+ - lib/aerospike/socket/ssl.rb
141
+ - lib/aerospike/socket/tcp.rb
120
142
  - lib/aerospike/task/execute_task.rb
121
143
  - lib/aerospike/task/index_task.rb
122
144
  - lib/aerospike/task/task.rb
@@ -128,6 +150,7 @@ files:
128
150
  - lib/aerospike/utils/buffer.rb
129
151
  - lib/aerospike/utils/packer.rb
130
152
  - lib/aerospike/utils/pool.rb
153
+ - lib/aerospike/utils/string_parser.rb
131
154
  - lib/aerospike/utils/unpacker.rb
132
155
  - lib/aerospike/value/particle_type.rb
133
156
  - lib/aerospike/value/value.rb
@@ -146,7 +169,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
146
169
  requirements:
147
170
  - - ">="
148
171
  - !ruby/object:Gem::Version
149
- version: 2.2.0
172
+ version: 2.3.0
150
173
  required_rubygems_version: !ruby/object:Gem::Requirement
151
174
  requirements:
152
175
  - - ">="