cassandra-driver 1.0.0.beta.3 → 1.0.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +13 -5
  2. data/README.md +8 -6
  3. data/lib/cassandra.rb +99 -13
  4. data/lib/cassandra/address_resolution.rb +36 -0
  5. data/lib/cassandra/address_resolution/policies.rb +2 -0
  6. data/lib/cassandra/address_resolution/policies/ec2_multi_region.rb +56 -0
  7. data/lib/cassandra/address_resolution/policies/none.rb +35 -0
  8. data/lib/cassandra/auth.rb +1 -1
  9. data/lib/cassandra/auth/providers/password.rb +1 -1
  10. data/lib/cassandra/client.rb +2 -2
  11. data/lib/cassandra/client/batch.rb +3 -3
  12. data/lib/cassandra/client/client.rb +12 -12
  13. data/lib/cassandra/client/connection_manager.rb +2 -2
  14. data/lib/cassandra/client/connector.rb +6 -10
  15. data/lib/cassandra/client/prepared_statement.rb +4 -4
  16. data/lib/cassandra/client/request_runner.rb +1 -2
  17. data/lib/cassandra/cluster.rb +15 -5
  18. data/lib/cassandra/cluster/client.rb +158 -96
  19. data/lib/cassandra/cluster/connector.rb +42 -27
  20. data/lib/cassandra/cluster/control_connection.rb +384 -132
  21. data/lib/cassandra/cluster/options.rb +5 -2
  22. data/lib/cassandra/cluster/registry.rb +19 -9
  23. data/lib/cassandra/compression.rb +1 -1
  24. data/lib/cassandra/compression/compressors/lz4.rb +1 -1
  25. data/lib/cassandra/compression/compressors/snappy.rb +1 -1
  26. data/lib/cassandra/driver.rb +28 -20
  27. data/lib/cassandra/errors.rb +325 -35
  28. data/lib/cassandra/future.rb +3 -3
  29. data/lib/cassandra/load_balancing/policies/dc_aware_round_robin.rb +7 -3
  30. data/lib/cassandra/load_balancing/policies/token_aware.rb +1 -1
  31. data/lib/cassandra/protocol.rb +0 -16
  32. data/lib/cassandra/protocol/cql_byte_buffer.rb +18 -18
  33. data/lib/cassandra/protocol/cql_protocol_handler.rb +74 -8
  34. data/lib/cassandra/protocol/frame_decoder.rb +2 -2
  35. data/lib/cassandra/protocol/frame_encoder.rb +1 -1
  36. data/lib/cassandra/protocol/response.rb +1 -1
  37. data/lib/cassandra/protocol/responses/detailed_error_response.rb +16 -1
  38. data/lib/cassandra/protocol/responses/error_response.rb +17 -0
  39. data/lib/cassandra/protocol/responses/event_response.rb +1 -1
  40. data/lib/cassandra/protocol/responses/raw_rows_result_response.rb +1 -1
  41. data/lib/cassandra/protocol/responses/result_response.rb +1 -1
  42. data/lib/cassandra/protocol/responses/rows_result_response.rb +1 -1
  43. data/lib/cassandra/protocol/type_converter.rb +4 -3
  44. data/lib/cassandra/reconnection.rb +1 -1
  45. data/lib/cassandra/retry.rb +3 -5
  46. data/lib/cassandra/session.rb +11 -5
  47. data/lib/cassandra/table.rb +1 -1
  48. data/lib/cassandra/time_uuid.rb +21 -83
  49. data/lib/cassandra/util.rb +1 -1
  50. data/lib/cassandra/uuid.rb +6 -4
  51. data/lib/cassandra/uuid/generator.rb +207 -0
  52. data/lib/cassandra/version.rb +1 -1
  53. metadata +24 -19
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: dd171d621192a4a0e4bbebd4601a9e5c2dab6654
4
- data.tar.gz: b779c047aef25ed28329f4237f677f13b985c494
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NTA3NTE1Y2M2Y2U5MmJmNGVlODZlZmI4YjI1NWE3OGNhOTY4OTgzOA==
5
+ data.tar.gz: !binary |-
6
+ ZDg0NTUxZTFmNDBjYmVjZDFlYjE1MzUwODc3MGFkODkwNTBjZmZjOQ==
5
7
  SHA512:
6
- metadata.gz: 97de07b2338b3d68cd89ca452121666e638775fde7237f33f3c7e2a4db4ae364ad4ce799bf30e4c671befa8dd921a141cb8980ef4d9a95009c3bd3728b1f0dd9
7
- data.tar.gz: be2236c32cf4dabbcb4ea7ed8597f8dec6cf03ef55cabbbe7b5bf13a20150cd854382d8609dd91ec0f0f2e9d8759890b3cfbf3a5e291e7aadceb7032fb6c980e
8
+ metadata.gz: !binary |-
9
+ OGI2NTA0NDQ2ZTk2ODlmNDFkNTkyMTYxZDBmY2I3OTNhNjQ3Y2ExNGQzZDlh
10
+ YzkzZDA0MGIwM2MzODRkMmJjYjI1OTRjNzYzYzg1MTNiNzFjMmJmOGUyZWEz
11
+ MjczMzZmNzg1OTZjN2NjY2JhMjc3YjYxMTJhOTc2MTVjOTI1MTQ=
12
+ data.tar.gz: !binary |-
13
+ MTc1ZDhiYmMyZDYzMDhjZDQzZmUxM2MzMzQ0NDNjNWFhOTIxZGY4ZjNiZDRm
14
+ Y2I2YmYzYmNkZmY0NGIyNzNkOGU3YWM4MTg3MDhjYTZhOTYyNWY2YWQ4ODI2
15
+ YmU3OTQ4ZjQ4NGU4NWY0MTkzOTQ4MWFiM2U0YzRiYTI4MzVjZmE=
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Datastax Ruby Driver for Apache Cassandra
2
2
 
3
+ *If you're reading this on GitHub, please note that this is the readme for the development version and that some features described here might not yet have been released. You can [find the documentation for latest version through ruby driver docs](http://datastax.github.io/ruby-driver/) or via the release tags, [e.g. v1.0.0-beta.3](https://github.com/datastax/ruby-driver/tree/v1.0.0-beta.3).*
4
+
3
5
  [![Build Status](https://travis-ci.org/datastax/ruby-driver.svg?branch=master)](https://travis-ci.org/datastax/ruby-driver)
4
6
 
5
7
  A Ruby client driver for Apache Cassandra. This driver works exclusively with
@@ -10,7 +12,7 @@ the Cassandra Query Language version 3 (CQL3) and Cassandra's native protocol.
10
12
  - JIRA: https://datastax-oss.atlassian.net/browse/RUBY
11
13
  - MAILING LIST: https://groups.google.com/a/lists.datastax.com/forum/#!forum/ruby-driver-user
12
14
  - IRC: #datastax-drivers on [irc.freenode.net](http://freenode.net>)
13
- - TWITTER: Follow the latest news about DataStax Drivers - [@avalanche123](http://twitter.com/avalanche123), [@mfiguiere](http://twitter.com/mfiguiere), [@al3xandru](https://twitter.com/al3xandru)
15
+ - TWITTER: Follow the latest news about DataStax Drivers - [@avalanche123](http://twitter.com/avalanche123), [@mfiguiere](http://twitter.com/mfiguiere), [@al3xandru](https://twitter.com/al3xandru)
14
16
 
15
17
  This driver is based on [the cql-rb gem](https://github.com/iconara/cql-rb) by [Theo Hultberg](https://github.com/iconara) and we added support for:
16
18
 
@@ -18,6 +20,7 @@ This driver is based on [the cql-rb gem](https://github.com/iconara/cql-rb) by [
18
20
  * one-off, [prepared](http://datastax.github.io/ruby-driver/features/basics/prepared_statements/) and [batch statements](http://datastax.github.io/ruby-driver/features/basics/batch_statements/)
19
21
  * automatic peer discovery and cluster metadata
20
22
  * various [load-balancing](http://datastax.github.io/ruby-driver/features/load_balancing/), [retry](http://datastax.github.io/ruby-driver/features/retry_policies/) and reconnection policies, [with ability to write your own](http://datastax.github.io/ruby-driver/features/load_balancing/implementing_a_policy/)
23
+ * [SSL encryption](http://datastax.github.io/ruby-driver/features/security/ssl_encryption/)
21
24
 
22
25
  ## Compability
23
26
 
@@ -35,7 +38,7 @@ __Note__: JRuby 1.6 is not officially supported, although 1.6.8 should work.
35
38
  ```ruby
36
39
  require 'cassandra'
37
40
 
38
- cluster = Cassandra.connect # connects to localhost by default
41
+ cluster = Cassandra.cluster # connects to localhost by default
39
42
 
40
43
  cluster.each_host do |host| # automatically discovers all peers
41
44
  puts "Host #{host.ip}: id=#{host.id} datacenter=#{host.datacenter} rack=#{host.rack}"
@@ -57,7 +60,7 @@ The host you specify is just a seed node, the driver will automatically discover
57
60
 
58
61
  Read more:
59
62
 
60
- * [`Cassandra.connect` options](http://datastax.github.io/ruby-driver/api/#connect-class_method)
63
+ * [`Cassandra.cluster` options](http://datastax.github.io/ruby-driver/api/#cluster-class_method)
61
64
  * [`Session#execute_async` options](http://datastax.github.io/ruby-driver/api/session/#execute_async-instance_method)
62
65
  * [Usage documentation](http://datastax.github.io/ruby-driver/features)
63
66
 
@@ -82,7 +85,7 @@ Note: if you want to use compression you should also install [snappy](http://rub
82
85
 
83
86
  Some of the new features added to the driver have unfortunately led to changes in the original cql-rb API. In the examples directory, you can find [an example of how to wrap the ruby driver to achieve almost complete interface parity with cql-rb](https://github.com/datastax/ruby-driver/blob/master/examples/cql-rb-wrapper.rb) to assist you with gradual upgrade.
84
87
 
85
- ## What's new in v1.0.0.beta.2
88
+ ## What's new in v1.0.0.beta.3
86
89
 
87
90
  Current release introduces the following new features:
88
91
 
@@ -108,7 +111,7 @@ Prereleases will be stable, in the sense that they will have finished and proper
108
111
 
109
112
  This driver is based on the original work of [Theo Hultberg](https://github.com/iconara) on [cql-rb](https://github.com/iconara/cql-rb/) and adds a series of advanced features that are common across all other DataStax drivers for Apache Cassandra.
110
113
 
111
- The development effort to provide an up to date, high performance, fully featured Ruby Driver for Apache Cassandra will continue on this project, while [cql-rb](https://github.com/iconara/cql-rb/) will be discontinued.
114
+ The development effort to provide an up to date, high performance, fully featured Ruby Driver for Apache Cassandra will continue on this project, while [cql-rb](https://github.com/iconara/cql-rb/) will be discontinued.
112
115
 
113
116
 
114
117
  ## Copyright
@@ -122,4 +125,3 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
122
125
  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
123
126
 
124
127
  [1]: http://datastax.github.io/ruby-driver/api
125
-
data/lib/cassandra.rb CHANGED
@@ -30,9 +30,13 @@ require 'digest'
30
30
  require 'stringio'
31
31
  require 'resolv'
32
32
  require 'openssl'
33
+ require 'securerandom'
34
+ require 'time'
33
35
 
34
36
  module Cassandra
35
37
  # A list of all supported request consistencies
38
+ # @see http://www.datastax.com/documentation/cassandra/2.0/cassandra/dml/dml_config_consistency_c.html Consistency levels in Apache Cassandra 2.0
39
+ # @see http://www.datastax.com/documentation/cassandra/1.2/cassandra/dml/dml_config_consistency_c.html Consistency levels in Apache Cassandra 1.2
36
40
  # @see Cassandra::Session#execute_async
37
41
  CONSISTENCIES = [ :any, :one, :two, :three, :quorum, :all, :local_quorum,
38
42
  :each_quorum, :serial, :local_serial, :local_one ].freeze
@@ -41,6 +45,12 @@ module Cassandra
41
45
  # @see Cassandra::Session#execute_async
42
46
  SERIAL_CONSISTENCIES = [:serial, :local_serial].freeze
43
47
 
48
+ # A list of all possible write types that a
49
+ # {Cassandra::Errors::WriteTimeoutError} can have.
50
+ #
51
+ # @see https://github.com/apache/cassandra/blob/trunk/doc/native_protocol_v1.spec#L591-L603 Description of possible types of writes in Apache Cassandra native protocol spec v1
52
+ WRITE_TYPES = [:simple, :batch, :unlogged_batch, :counter, :batch_log].freeze
53
+
44
54
  # Creates a {Cassandra::Cluster} instance
45
55
  #
46
56
  # @option options [Array<String, IPAddr>] :hosts (['127.0.0.1']) a list of
@@ -50,9 +60,28 @@ module Cassandra
50
60
  #
51
61
  # @option options [Integer] :port (9042) cassandra native protocol port.
52
62
  #
63
+ # @option options [String] :datacenter (nil) name of current datacenter.
64
+ # First datacenter found will be assumed current by default. Note that you
65
+ # can skip this option if you specify only hosts from the local datacenter
66
+ # in `:hosts` option.
67
+ #
53
68
  # @option options [Numeric] :connect_timeout (10) connection timeout in
54
69
  # seconds.
55
70
  #
71
+ # @option options [Numeric] :timeout (10) request execution timeout in
72
+ # seconds.
73
+ #
74
+ # @option options [Numeric] :heartbeat_interval (30) how often should a
75
+ # heartbeat be sent to determine if a connection is alive. Several things to
76
+ # note about this option. Only one heartbeat request will ever be
77
+ # outstanding on a given connection. Each heatbeat will be sent in at least
78
+ # `:heartbeat_interval` seconds after the last request has been sent on a
79
+ # given connection.
80
+ #
81
+ # @option options [Numeric] :idle_timeout (60) period of inactivity after
82
+ # which a connection is considered dead. Note that this value should be at
83
+ # least a few times larger than `:heartbeat_interval`.
84
+ #
56
85
  # @option options [String] :username (none) username to use for
57
86
  # authentication to cassandra. Note that you must also specify `:password`.
58
87
  #
@@ -83,12 +112,15 @@ module Cassandra
83
112
  # work, you must install 'snappy' or 'lz4-ruby' gems.
84
113
  #
85
114
  # @option options [Cassandra::LoadBalancing::Policy] :load_balancing_policy
86
- # default: {Cassandra::LoadBalancing::Policies::RoundRobin}.
115
+ # default: token aware data center aware round robin.
116
+ #
117
+ # @option options [Symbol] :address_resolution (:none) a pre-configured
118
+ # address resolver to use. Must be one of `:none` or
119
+ # `:ec2_multi_region`.
87
120
  #
88
121
  # @option options [Cassandra::Reconnection::Policy] :reconnection_policy
89
122
  # default: {Cassandra::Reconnection::Policies::Exponential}. Note that the
90
- # default policy is configured with
91
- # `Reconnection::Policies::Exponential.new(0.5, 30, 2)`.
123
+ # default policy is configured with `(0.5, 30, 2)`.
92
124
  #
93
125
  # @option options [Cassandra::Retry::Policy] :retry_policy default:
94
126
  # {Cassandra::Retry::Policies::Default}.
@@ -101,8 +133,8 @@ module Cassandra
101
133
  # initial listeners. A list of initial cluster state listeners. Note that a
102
134
  # `:load_balancing` policy is automatically registered with the cluster.
103
135
  #
104
- # @option options [Symbol] :consistency (:quorum) default consistency to use
105
- # for all requests. Must be one of {Cassandra::CONSISTENCIES}.
136
+ # @option options [Symbol] :consistency (:one) default consistency to use for
137
+ # all requests. Must be one of {Cassandra::CONSISTENCIES}.
106
138
  #
107
139
  # @option options [Boolean] :trace (false) whether or not to trace all
108
140
  # requests by default.
@@ -118,6 +150,12 @@ module Cassandra
118
150
  # compressor. Note that if you have specified `:compression`, an
119
151
  # appropriate compressor will be provided automatically.
120
152
  #
153
+ # @option options [Cassandra::AddressResolution::Policy]
154
+ # :address_resolution_policy default:
155
+ # {Cassandra::AddressResolution::Policies::None} a custom address resolution
156
+ # policy. Note that if you have specified `:address_resolution`, an
157
+ # appropriate address resolution policy will be provided automatically.
158
+ #
121
159
  # @option options [Object<#all, #error, #value, #promise>] :futures_factory
122
160
  # (none) a custom futures factory to assist with integration into existing
123
161
  # futures library. Note that promises returned by this object must conform
@@ -125,23 +163,24 @@ module Cassandra
125
163
  # use at your own risk.
126
164
  #
127
165
  # @example Connecting to localhost
128
- # cluster = Cassandra.connect
166
+ # cluster = Cassandra.cluster
129
167
  #
130
168
  # @example Configuring {Cassandra::Cluster}
131
- # cluster = Cassandra.connect(
169
+ # cluster = Cassandra.cluster(
132
170
  # username: username,
133
171
  # password: password,
134
172
  # hosts: ['10.0.1.1', '10.0.1.2', '10.0.1.3']
135
173
  # )
136
174
  #
137
175
  # @return [Cassandra::Cluster] a cluster instance
138
- def self.connect(options = {})
139
- options.select! do |key, value|
176
+ def self.cluster(options = {})
177
+ options = options.select do |key, value|
140
178
  [ :credentials, :auth_provider, :compression, :hosts, :logger, :port,
141
179
  :load_balancing_policy, :reconnection_policy, :retry_policy, :listeners,
142
180
  :consistency, :trace, :page_size, :compressor, :username, :password,
143
181
  :ssl, :server_cert, :client_cert, :private_key, :passphrase,
144
- :connect_timeout, :futures_factory
182
+ :connect_timeout, :futures_factory, :datacenter, :address_resolution,
183
+ :address_resolution_policy, :idle_timeout, :heartbeat_interval, :timeout
145
184
  ].include?(key)
146
185
  end
147
186
 
@@ -241,7 +280,7 @@ module Cassandra
241
280
  ssl = options[:ssl]
242
281
 
243
282
  unless ssl.is_a?(::TrueClass) || ssl.is_a?(::FalseClass) || ssl.is_a?(::OpenSSL::SSL::SSLContext)
244
- raise ":ssl must be a boolean or an OpenSSL::SSL::SSLContext, #{ssl.inspect} given"
283
+ raise ::ArgumentError, ":ssl must be a boolean or an OpenSSL::SSL::SSLContext, #{ssl.inspect} given"
245
284
  end
246
285
  end
247
286
 
@@ -286,6 +325,10 @@ module Cassandra
286
325
  end
287
326
  end
288
327
 
328
+ if options.has_key?(:datacenter)
329
+ options[:datacenter] = String(options[:datacenter])
330
+ end
331
+
289
332
  if options.has_key?(:connect_timeout)
290
333
  timeout = options[:connect_timeout] = Integer(options[:connect_timeout])
291
334
 
@@ -294,6 +337,30 @@ module Cassandra
294
337
  end
295
338
  end
296
339
 
340
+ if options.has_key?(:timeout)
341
+ timeout = options[:timeout] = Integer(options[:timeout])
342
+
343
+ if timeout < 0
344
+ raise ::ArgumentError, ":timeout must be a positive value, #{timeout.given}"
345
+ end
346
+ end
347
+
348
+ if options.has_key?(:heartbeat_interval)
349
+ timeout = options[:heartbeat_interval] = Integer(options[:heartbeat_interval])
350
+
351
+ if timeout < 0
352
+ raise ::ArgumentError, ":heartbeat_interval must be a positive value, #{timeout.given}"
353
+ end
354
+ end
355
+
356
+ if options.has_key?(:idle_timeout)
357
+ timeout = options[:idle_timeout] = Integer(options[:idle_timeout])
358
+
359
+ if timeout < 0
360
+ raise ::ArgumentError, ":idle_timeout must be a positive value, #{timeout.given}"
361
+ end
362
+ end
363
+
297
364
  if options.has_key?(:load_balancing_policy)
298
365
  load_balancing_policy = options[:load_balancing_policy]
299
366
  methods = [:host_up, :host_down, :host_found, :host_lost, :setup, :distance, :plan]
@@ -357,6 +424,26 @@ module Cassandra
357
424
  end
358
425
  end
359
426
 
427
+ if options.has_key?(:address_resolution)
428
+ address_resolution = options.delete(:address_resolution)
429
+
430
+ case address_resolution
431
+ when :none
432
+ when :ec2_multi_region
433
+ options[:address_resolution_policy] = AddressResolution::Policies::EC2MultiRegion.new
434
+ else
435
+ raise ::ArgumentError, ":address_resolution must be either :none or :ec2_multi_region, #{address_resolution.inspect} given"
436
+ end
437
+ end
438
+
439
+ if options.has_key?(:address_resolution_policy)
440
+ address_resolver = options[:address_resolution_policy]
441
+
442
+ unless address_resolver.respond_to?(:resolve)
443
+ raise ::ArgumentError, ":address_resolution_policy must respond to :resolve, #{address_resolver.inspect} but doesn't"
444
+ end
445
+ end
446
+
360
447
  hosts = []
361
448
 
362
449
  Array(options.fetch(:hosts, '127.0.0.1')).each do |host|
@@ -408,6 +495,7 @@ require 'cassandra/execution/trace'
408
495
  require 'cassandra/load_balancing'
409
496
  require 'cassandra/reconnection'
410
497
  require 'cassandra/retry'
498
+ require 'cassandra/address_resolution'
411
499
 
412
500
  require 'cassandra/util'
413
501
 
@@ -415,8 +503,6 @@ require 'cassandra/util'
415
503
  require 'cassandra_murmur3'
416
504
 
417
505
  module Cassandra
418
- # @private
419
- Io = Ione::Io
420
506
  # @private
421
507
  VOID_STATEMENT = Statements::Void.new
422
508
  # @private
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+
3
+ #--
4
+ # Copyright 2013-2014 DataStax, Inc.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #++
18
+
19
+ module Cassandra
20
+ # Address Resolution policy allows translating a node ip address from what is
21
+ # recorded in Cassandra's system tables to an actual ip address for the driver
22
+ # to use. It is very useful in various multi-region scenarios (e.g. on EC2).
23
+ module AddressResolution
24
+ class Policy
25
+ # Resolves a node ip address.
26
+ #
27
+ # @param address [IPAddr] node ip address from Cassandra's system table
28
+ #
29
+ # @return [IPAddr] actual ip address of the node
30
+ def resolve(address)
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ require 'cassandra/address_resolution/policies'
@@ -0,0 +1,2 @@
1
+ require 'cassandra/address_resolution/policies/none'
2
+ require 'cassandra/address_resolution/policies/ec2_multi_region'
@@ -0,0 +1,56 @@
1
+ # encoding: utf-8
2
+
3
+ #--
4
+ # Copyright 2013-2014 DataStax, Inc.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #++
18
+
19
+ module Cassandra
20
+ module AddressResolution
21
+ module Policies
22
+ # This policy resolves private ips of the hosts in the same datacenter and
23
+ # public ips of hosts in other datacenters.
24
+ #
25
+ # @note Initializing this policy is not necessary, you should just pass
26
+ # `:ec_multi_region` to the `:address_resolution` option of
27
+ # {Cassandra.cluster}
28
+ class EC2MultiRegion
29
+ # @private
30
+ def initialize(resolver = Resolv)
31
+ @resolver = resolver
32
+ end
33
+
34
+ # Returns ip address after a double DNS lookup. First, it will get
35
+ # hostname from a given ip, then resolve the resulting hostname. This
36
+ # policy works because AWS public hostnames resolve to a private ip
37
+ # address within the same datacenter.
38
+ #
39
+ # @param address [IPAddr] node ip address from Cassandra's system table
40
+ #
41
+ # @return [IPAddr] private ip withing the same datacenter, public ip
42
+ # otherwise. Returns original address if DNS lookups fail.
43
+ def resolve(address)
44
+ @resolver.each_name(Resolv::DNS::Name.create(address.reverse)) do |name|
45
+ @resolver.each_address(name) do |addr|
46
+ return ::IPAddr.new(addr)
47
+ end
48
+ end
49
+
50
+ # default to original address if reverse DNS lookup failed
51
+ address
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+
3
+ #--
4
+ # Copyright 2013-2014 DataStax, Inc.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #++
18
+
19
+ module Cassandra
20
+ module AddressResolution
21
+ module Policies
22
+ # The default address resolution policy. Always returns original address.
23
+ class None
24
+ # Returns original address.
25
+ #
26
+ # @param address [IPAddr] node ip address from Cassandra's system table
27
+ #
28
+ # @return [IPAddr] same as `address`
29
+ def resolve(address)
30
+ address
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -28,7 +28,7 @@ module Cassandra
28
28
  # @note Creating an authenticator must absolutely not block, or the whole
29
29
  # connection process will block.
30
30
  #
31
- # @abstract Auth providers given to {Cassandra.connect} don't need to be
31
+ # @abstract Auth providers given to {Cassandra.cluster} don't need to be
32
32
  # subclasses of this class, but need to implement the same methods. This
33
33
  # class exists only for documentation purposes.
34
34
  #