cassandra-driver 3.0.3 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +8 -8
  2. data/README.md +46 -31
  3. data/lib/cassandra.rb +35 -44
  4. data/lib/cassandra/cluster.rb +40 -11
  5. data/lib/cassandra/cluster/client.rb +193 -159
  6. data/lib/cassandra/cluster/connector.rb +12 -10
  7. data/lib/cassandra/cluster/control_connection.rb +38 -10
  8. data/lib/cassandra/cluster/options.rb +8 -4
  9. data/lib/cassandra/cluster/registry.rb +1 -2
  10. data/lib/cassandra/cluster/schema/fetchers.rb +122 -26
  11. data/lib/cassandra/column_container.rb +9 -4
  12. data/lib/cassandra/custom_data.rb +24 -22
  13. data/lib/cassandra/driver.rb +30 -13
  14. data/lib/cassandra/errors.rb +12 -2
  15. data/lib/cassandra/execution/options.rb +52 -16
  16. data/lib/cassandra/execution/profile.rb +150 -0
  17. data/lib/cassandra/execution/profile_manager.rb +71 -0
  18. data/lib/cassandra/execution/trace.rb +5 -4
  19. data/lib/cassandra/executors.rb +1 -1
  20. data/lib/cassandra/index.rb +1 -1
  21. data/lib/cassandra/keyspace.rb +36 -1
  22. data/lib/cassandra/protocol.rb +5 -0
  23. data/lib/cassandra/protocol/coder.rb +2 -1
  24. data/lib/cassandra/protocol/cql_byte_buffer.rb +21 -0
  25. data/lib/cassandra/protocol/responses/read_failure_error_response.rb +10 -4
  26. data/lib/cassandra/protocol/responses/write_failure_error_response.rb +14 -8
  27. data/lib/cassandra/protocol/v3.rb +2 -1
  28. data/lib/cassandra/protocol/v4.rb +58 -20
  29. data/lib/cassandra/result.rb +1 -1
  30. data/lib/cassandra/session.rb +43 -16
  31. data/lib/cassandra/statements/bound.rb +5 -1
  32. data/lib/cassandra/statements/prepared.rb +8 -3
  33. data/lib/cassandra/table.rb +72 -0
  34. data/lib/cassandra/trigger.rb +67 -0
  35. data/lib/cassandra/types.rb +12 -24
  36. data/lib/cassandra/udt.rb +3 -6
  37. data/lib/cassandra/uuid/generator.rb +6 -3
  38. data/lib/cassandra/version.rb +1 -1
  39. metadata +5 -2
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjZmNzhmODM4ZDExNTc4YWY0MDEzMTcwMmRiYjJiYzhhMmIwNzBjOQ==
4
+ ZDhmZDc1ZjlhMzA5ZTU1ZGE4MWJhNGM5OTNiNjI3NmI5YzBlMDhiOQ==
5
5
  data.tar.gz: !binary |-
6
- OWY4MjRmNjhiMDQyMzQ0NmJiZGQ1N2JhYzM2MzkwYzc2NmEwNDZmMw==
6
+ ZmQzYWZiZDM4OTRlZTFlYmRhNDNmMzgxODRhN2QzZGFhYzg5ZThmNQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZGZhOTkxYmVlZDhmM2QzYjI0YjgxZjQzYzU5MTU2MTQwMzJmNzRmYmQ0MWE5
10
- MTRkOGZmMzA5YjIzOTlkNWRlYTBlODdlYjM4NTRmYjNlN2MwNzM1ZGViNDMx
11
- MTUwNWZlZGRiMDA1MWFhNjEzY2UzMTNlMGFiYWVhNzY0ZjNlZWI=
9
+ NzY3ZjE1M2RjZTQxMDE3NmJhZGRmZjEzMzY0ZTBlOTZjNmRhY2VmZTY1M2Qw
10
+ Mjk0NmFlYTQ4MDE3MDIwNTBiZWRlYTRlNzJjNzU0MDhjNDcxMTg0NDc0NGM0
11
+ NGI2NWY1N2I4MjQyZjQyNmVlY2M3NDNjYTlmNGQwYjViNjJmOTY=
12
12
  data.tar.gz: !binary |-
13
- YjJjMTZjYmUzMzlmMWM1MWQ1OGU4YWQ0ZDlhMmYwNDk3NzNlOTUxNGRmNGZh
14
- ZmYwNDE1N2RmMTYyNDgwM2NkNzg1Njc0MTc5ZTJlOTM0ZDQyYjg4ZWNlZDUw
15
- ODQyOWFiNjg3N2RkMTA3NjRiY2U0MDVkNDNhZWQ5YzMxZWQzZjA=
13
+ YmY0MDhjNWU2MDQ0YWI4ZTQyYTZmNGU1OGQ3OGE2YzE5ODQ2ZWI2ZTcxNmFh
14
+ YWUxNmEzZWI0NDMwMGQ1M2Y1YmYwYzMwYWZiZTMxOTE4ODA4NjI1NWFkMWU5
15
+ YjA3NDg0ZDI5ZDRjNDA4M2RkNzhjYTg5MzZhZWZjOGE1YWUwOTQ=
data/README.md CHANGED
@@ -1,6 +1,8 @@
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 the latest version through ruby driver docs](http://docs.datastax.com/en/latest-ruby-driver/ruby-driver/whatsNew.html) or via the release tags, [e.g. v3.0.3](https://github.com/datastax/ruby-driver/tree/v3.0.3).*
3
+ *If you're reading this on GitHub, please note that this is the readme for the development version and that some
4
+ features described here might not yet have been released. You can view the documentation for the latest released
5
+ version [here](http://docs.datastax.com/en/developer/ruby-driver/latest).*
4
6
 
5
7
  [![Build Status](https://travis-ci.org/datastax/ruby-driver.svg?branch=master)](https://travis-ci.org/datastax/ruby-driver)
6
8
 
@@ -8,22 +10,22 @@ A Ruby client driver for Apache Cassandra. This driver works exclusively with
8
10
  the Cassandra Query Language version 3 (CQL3) and Cassandra's native protocol.
9
11
 
10
12
  - Code: https://github.com/datastax/ruby-driver
11
- - Docs: http://docs.datastax.com/en/latest-ruby-driver/ruby-driver/whatsNew.html
13
+ - Docs: http://docs.datastax.com/en/developer/ruby-driver
12
14
  - Jira: https://datastax-oss.atlassian.net/browse/RUBY
13
15
  - Mailing List: https://groups.google.com/a/lists.datastax.com/forum/#!forum/ruby-driver-user
14
16
  - IRC: #datastax-drivers on [irc.freenode.net](http://freenode.net>)
15
- - Twitter: Follow the latest news about DataStax Drivers - [@avalanche123](http://twitter.com/avalanche123), [@stamhankar999](http://twitter.com/stamhankar999), [@al3xandru](https://twitter.com/al3xandru)
17
+ - Twitter: Follow the latest news about DataStax Drivers - [@stamhankar999](http://twitter.com/stamhankar999), [@avalanche123](http://twitter.com/avalanche123), [@al3xandru](https://twitter.com/al3xandru)
16
18
 
17
19
  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:
18
20
 
19
- * [Asynchronous execution](http://docs.datastax.com/en/developer/ruby-driver/3.0/supplemental/features/asynchronous_io/)
20
- * One-off, [prepared](http://docs.datastax.com/en/developer/ruby-driver/3.0/supplemental/features/basics/prepared_statements/) and [batch statements](http://docs.datastax.com/en/developer/ruby-driver/3.0/supplemental/features/basics/batch_statements/)
21
- * Automatic peer discovery and cluster metadata with [support for change notifications](http://docs.datastax.com/en/developer/ruby-driver/3.0/supplemental/features/state_listeners/)
22
- * Various [load-balancing](http://docs.datastax.com/en/developer/ruby-driver/3.0/supplemental/features/load_balancing/), [retry](http://docs.datastax.com/en/developer/ruby-driver/3.0/supplemental/features/retry_policies/) and [reconnection](http://docs.datastax.com/en/developer/ruby-driver/3.0/supplemental/features/reconnection/) policies with [ability to write your own](http://docs.datastax.com/en/developer/ruby-driver/3.0/supplemental/features/load_balancing/implementing_a_policy/)
23
- * [SSL encryption](http://docs.datastax.com/en/developer/ruby-driver/3.0/supplemental/features/security/ssl_encryption/)
24
- * [Flexible and robust error handling](http://docs.datastax.com/en/developer/ruby-driver/3.0/supplemental/features/error_handling/)
25
- * [Per-request execution information and tracing](http://docs.datastax.com/en/developer/ruby-driver/3.0/supplemental/features/debugging/)
26
- * [Configurable address resolution](http://docs.datastax.com/en/developer/ruby-driver/3.0/supplemental/features/address_resolution/)
21
+ * [Asynchronous execution](http://docs.datastax.com/en/developer/ruby-driver/3.0/features/asynchronous_io/)
22
+ * One-off, [prepared](http://docs.datastax.com/en/developer/ruby-driver/3.0/features/basics/prepared_statements/) and [batch statements](http://docs.datastax.com/en/developer/ruby-driver/3.0/features/basics/batch_statements/)
23
+ * Automatic peer discovery and cluster metadata with [support for change notifications](http://docs.datastax.com/en/developer/ruby-driver/3.0/features/state_listeners/)
24
+ * Various [load-balancing](http://docs.datastax.com/en/developer/ruby-driver/3.0/features/load_balancing/), [retry](http://docs.datastax.com/en/developer/ruby-driver/3.0/features/retry_policies/) and [reconnection](http://docs.datastax.com/en/developer/ruby-driver/3.0/features/reconnection/) policies with [ability to write your own](http://docs.datastax.com/en/developer/ruby-driver/3.0/features/load_balancing/implementing_a_policy/)
25
+ * [SSL encryption](http://docs.datastax.com/en/developer/ruby-driver/3.0/features/security/ssl_encryption/)
26
+ * [Flexible and robust error handling](http://docs.datastax.com/en/developer/ruby-driver/3.0/features/error_handling/)
27
+ * [Per-request execution information and tracing](http://docs.datastax.com/en/developer/ruby-driver/3.0/features/debugging/)
28
+ * [Configurable address resolution](http://docs.datastax.com/en/developer/ruby-driver/3.0/features/address_resolution/)
27
29
 
28
30
  [Check out the slides from Ruby Driver Explained](https://speakerdeck.com/avalanche123/ruby-driver-explained) for a detailed overview of the Ruby Driver architecture.
29
31
 
@@ -36,10 +38,14 @@ This driver works exclusively with the Cassandra Query Language v3 (CQL3) and Ca
36
38
  * Ruby (MRI) 2.2, 2.3
37
39
  * JRuby 1.7
38
40
 
39
- __Note__: JRuby 1.6 is not officially supported, although 1.6.8 should work. Similarly,
40
- MRI 2.0 and 2.1 are not officially supported, but they should work. 1.9.3 is deprecated
41
+ __Note__: JRuby 1.6 is not officially supported, although 1.6.8 should work. Rubinius is not supported.
42
+ MRI 2.0, 2.1, and JRuby 9k are not officially supported, but they should work. 1.9.3 is deprecated
41
43
  and is likely to break in the release following 3.0.
42
44
 
45
+ ## Feedback Requested
46
+
47
+ *Help us focus our efforts!* [Provide your input](http://goo.gl/forms/pCs8PTpHLf) on the Ruby Driver Platform and Runtime Survey (we kept it short).
48
+
43
49
  ## Quick start
44
50
 
45
51
  ```ruby
@@ -51,10 +57,10 @@ cluster.each_host do |host| # automatically discovers all peers
51
57
  puts "Host #{host.ip}: id=#{host.id} datacenter=#{host.datacenter} rack=#{host.rack}"
52
58
  end
53
59
 
54
- keyspace = 'system'
60
+ keyspace = 'system_schema'
55
61
  session = cluster.connect(keyspace) # create session, optionally scoped to a keyspace, to execute queries
56
62
 
57
- future = session.execute_async('SELECT keyspace_name, table_name FROM system_schema.tables') # fully asynchronous api
63
+ future = session.execute_async('SELECT keyspace_name, table_name FROM tables') # fully asynchronous api
58
64
  future.on_success do |rows|
59
65
  rows.each do |row|
60
66
  puts "The keyspace #{row['keyspace_name']} has a table called #{row['table_name']}"
@@ -67,9 +73,9 @@ __Note__: The host you specify is just a seed node, the driver will automaticall
67
73
 
68
74
  Read more:
69
75
 
70
- * [`Cassandra.cluster` options](http://docs.datastax.com/en/developer/ruby-driver/3.0/supplemental/api/cassandra/#cluster-class_method)
71
- * [`Session#execute_async` options](http://docs.datastax.com/en/developer/ruby-driver/3.0/supplemental/api/cassandra/session/#execute_async-instance_method)
72
- * [Usage documentation](http://docs.datastax.com/en/developer/ruby-driver/3.0/supplemental/features)
76
+ * [`Cassandra.cluster` options](http://docs.datastax.com/en/developer/ruby-driver/3.0/api/cassandra/#cluster-class_method)
77
+ * [`Session#execute_async` options](http://docs.datastax.com/en/developer/ruby-driver/3.0/api/cassandra/session/#execute_async-instance_method)
78
+ * [Usage documentation](http://docs.datastax.com/en/developer/ruby-driver/3.0/features)
73
79
 
74
80
  ## Installation
75
81
 
@@ -85,16 +91,29 @@ Install via Gemfile
85
91
  gem 'cassandra-driver'
86
92
  ```
87
93
 
88
- __Note__: if you want to use compression you should also install [snappy](http://rubygems.org/gems/snappy) or [lz4-ruby](http://rubygems.org/gems/lz4-ruby). [Read more about compression.](http://docs.datastax.com/en/developer/ruby-driver/3.0/supplemental/features/#compression)
94
+ __Note__: if you want to use compression you should also install [snappy](http://rubygems.org/gems/snappy) or [lz4-ruby](http://rubygems.org/gems/lz4-ruby). [Read more about compression.](http://docs.datastax.com/en/developer/ruby-driver/3.0/features/#compression)
89
95
 
90
96
 
91
97
  ## Upgrading from cql-rb
92
98
 
93
- 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/v3.0.3/examples/cql-rb-wrapper.rb) to assist you with gradual upgrade.
99
+ Some of the new features added to the driver have unfortunately led to changes in the original cql-rb API.
100
+ In the examples directory, you can find [an example of how to wrap the ruby driver to achieve almost complete
101
+ interface parity with cql-rb](https://github.com/datastax/ruby-driver/blob/v3.1.0/examples/cql-rb-wrapper.rb)
102
+ to assist you with gradual upgrade.
94
103
 
95
- ## What's new in v3.0
104
+ ## What's new in v3.1
105
+
106
+ This minor release introduces features and fixes around resiliency, schema metadata, usability, and performance. One
107
+ of the most user-impacting of these is the introduction of
108
+ [execution profiles](http://docs.datastax.com/en/developer/ruby-driver/3.1/features/basics/execution_profiles).
109
+ Execution profiles allow you to group various execution options into a 'profile' and you reference the desired
110
+ profile at execution time. Get the scoop
111
+ [here](http://docs.datastax.com/en/developer/ruby-driver/3.1/features/basics/execution_profiles).
96
112
 
97
- See the [changelog](https://github.com/datastax/ruby-driver/blob/v3.0.3/CHANGELOG.md) for details on patch versions.
113
+ See the [changelog](https://github.com/datastax/ruby-driver/blob/v3.1.0/CHANGELOG.md) for more information on all
114
+ changes in this version and past versions.
115
+
116
+ ## What's new in v3.0
98
117
 
99
118
  ### Features:
100
119
 
@@ -150,10 +169,6 @@ batch.add(query, arguments: {p1: 'val1'})
150
169
  * [[RUBY-161](https://datastax-oss.atlassian.net/browse/RUBY-161)] Protocol version negotiation in mixed version clusters should not fall back to v1 unless it is truly warranted.
151
170
  * [[RUBY-214](https://datastax-oss.atlassian.net/browse/RUBY-214)] Ensure client timestamps have microsecond precision in JRuby. Previously, some row updates would get lost in high transaction environments.
152
171
 
153
- ## Feedback Requested
154
-
155
- *Help us focus our efforts!* [Provide your input](http://goo.gl/forms/pCs8PTpHLf) on the Ruby Driver Platform and Runtime Survey (we kept it short).
156
-
157
172
  ## Code examples
158
173
 
159
174
  The DataStax Ruby Driver uses the awesome [Cucumber Framework](http://cukes.info/) for
@@ -164,7 +179,7 @@ examples in the `features/` directory.
164
179
  ## Running tests
165
180
 
166
181
  If you don't feel like reading through the following instructions on how to run
167
- ruby-driver tests, feel free to [check out .travis.yml for the entire build code](https://github.com/datastax/ruby-driver/blob/v3.0.3/.travis.yml).
182
+ ruby-driver tests, feel free to [check out .travis.yml for the entire build code](https://github.com/datastax/ruby-driver/blob/v3.1.0/.travis.yml).
168
183
 
169
184
  * Check out the driver codebase and install test dependencies:
170
185
 
@@ -188,7 +203,7 @@ CASSANDRA_VERSION=2.0.17 bundle exec rake test # run both as well as integration
188
203
  ## Changelog & versioning
189
204
 
190
205
  Check out the [releases on GitHub](https://github.com/datastax/ruby-driver/releases) and
191
- [changelog](https://github.com/datastax/ruby-driver/blob/v3.0.3/CHANGELOG.md). Version
206
+ [changelog](https://github.com/datastax/ruby-driver/blob/v3.1.0/CHANGELOG.md). Version
192
207
  numbering follows the [semantic versioning](http://semver.org/) scheme.
193
208
 
194
209
  Private and experimental APIs, defined as whatever is not in the
@@ -212,7 +227,7 @@ the release.
212
227
  * Because the driver reactor is using `IO.select`, the maximum number of tcp connections allowed is 1024.
213
228
  * Because the driver uses `IO#write_nonblock`, Windows is not supported.
214
229
 
215
- Please [refer to the usage documentation for more information on common pitfalls](http://docs.datastax.com/en/developer/ruby-driver/3.0/supplemental/features/)
230
+ Please [refer to the usage documentation for more information on common pitfalls](http://docs.datastax.com/en/developer/ruby-driver/3.0/features/)
216
231
 
217
232
  ## Contributing
218
233
 
@@ -226,7 +241,7 @@ that are common across all other DataStax drivers for Apache Cassandra.
226
241
 
227
242
  The development effort to provide an up to date, high performance, fully featured Ruby
228
243
  Driver for Apache Cassandra will continue on this project, while
229
- [cql-rb](https://github.com/iconara/cql-rb/) will be discontinued.
244
+ [cql-rb](https://github.com/iconara/cql-rb/) has been discontinued.
230
245
 
231
246
  ## Copyright
232
247
 
@@ -242,4 +257,4 @@ License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
242
257
  either express or implied. See the License for the specific language governing permissions
243
258
  and limitations under the License.
244
259
 
245
- [1]: http://docs.datastax.com/en/developer/ruby-driver/3.0/supplemental/api
260
+ [1]: http://docs.datastax.com/en/developer/ruby-driver/3.0/api
@@ -56,6 +56,7 @@ module Cassandra
56
56
  CLUSTER_OPTIONS = [
57
57
  :address_resolution,
58
58
  :address_resolution_policy,
59
+ :allow_beta_protocol,
59
60
  :auth_provider,
60
61
  :client_cert,
61
62
  :client_timestamps,
@@ -68,6 +69,7 @@ module Cassandra
68
69
  :credentials,
69
70
  :custom_types,
70
71
  :datacenter,
72
+ :execution_profiles,
71
73
  :futures_factory,
72
74
  :heartbeat_interval,
73
75
  :hosts,
@@ -117,10 +119,14 @@ module Cassandra
117
119
  # found by the default Token-Aware Load Balancing Policy should be
118
120
  # shuffled. See {Cassandra::LoadBalancing::Policies::TokenAware#initialize Token-Aware Load Balancing Policy}.
119
121
  #
122
+ # @option options [Hash<String|Symbol, ExecutionProfile>] :execution_profiles (nil)
123
+ # Hash of {Cassandra::Execution::Profile}s that are available for client use (e.g.
124
+ # {Session#execute}, {Session#execute_async}, {Session#prepare}, and {Session#prepare_async}).
125
+ #
120
126
  # @option options [Numeric] :connect_timeout (10) connection timeout in
121
127
  # seconds. Setting value to `nil` will reset it to 5 seconds.
122
128
  #
123
- # @option options [Numeric] :timeout (10) request execution timeout in
129
+ # @option options [Numeric] :timeout (12) request execution timeout in
124
130
  # seconds. Setting value to `nil` will remove request timeout.
125
131
  #
126
132
  # @option options [Numeric] :heartbeat_interval (30) how often should a
@@ -191,6 +197,9 @@ module Cassandra
191
197
  # nodes. By default, this is auto-negotiated to the highest common protocol version
192
198
  # that all nodes in `:hosts` speak.
193
199
  #
200
+ # @option options [Boolean] :allow_beta_protocol (false) whether the driver should attempt to speak to nodes
201
+ # with a beta version of the newest protocol (which is still under development). USE WITH CAUTION!
202
+ #
194
203
  # @option options [Boolean, Cassandra::TimestampGenerator] :client_timestamps (false) whether the driver
195
204
  # should send timestamps for each executed statement and possibly which timestamp generator to use. Enabling this
196
205
  # setting helps mitigate Cassandra cluster clock skew because the timestamp of the client machine will be used.
@@ -315,6 +324,12 @@ module Cassandra
315
324
  CLUSTER_OPTIONS.include?(key)
316
325
  end
317
326
 
327
+ if options.key?(:execution_profiles)
328
+ [:load_balancing_policy, :retry_policy, :timeout, :consistency].each do |opt|
329
+ raise ::ArgumentError, "#{opt} is not allowed when execution profiles are used" if options.key?(opt)
330
+ end
331
+ end
332
+
318
333
  has_username = options.key?(:username)
319
334
  has_password = options.key?(:password)
320
335
  if has_username || has_password
@@ -503,15 +518,9 @@ module Cassandra
503
518
  end
504
519
  end
505
520
 
506
- if options.key?(:timeout)
507
- timeout = options[:timeout]
508
-
509
- unless timeout.nil?
510
- Util.assert_instance_of(::Numeric, timeout) do
511
- ":timeout must be a number of seconds, #{timeout.inspect} given"
512
- end
513
- Util.assert(timeout > 0) { ":timeout must be greater than 0, #{timeout} given" }
514
- end
521
+ if options.key?(:execution_profiles)
522
+ Util.assert_instance_of(::Hash, options[:execution_profiles],
523
+ ':execution_profiles must be a hash of <name,ExecutionProfile> entries.')
515
524
  end
516
525
 
517
526
  if options.key?(:heartbeat_interval)
@@ -562,17 +571,6 @@ module Cassandra
562
571
  end
563
572
  end
564
573
 
565
- if options.key?(:load_balancing_policy)
566
- load_balancing_policy = options[:load_balancing_policy]
567
- methods = [:host_up, :host_down, :host_found, :host_lost, :setup, :teardown,
568
- :distance, :plan]
569
-
570
- Util.assert_responds_to_all(methods, load_balancing_policy) do
571
- ":load_balancing_policy #{load_balancing_policy.inspect} must respond " \
572
- "to #{methods.inspect}, but doesn't"
573
- end
574
- end
575
-
576
574
  if options.key?(:reconnection_policy)
577
575
  reconnection_policy = options[:reconnection_policy]
578
576
 
@@ -582,30 +580,15 @@ module Cassandra
582
580
  end
583
581
  end
584
582
 
585
- if options.key?(:retry_policy)
586
- retry_policy = options[:retry_policy]
587
- methods = [:read_timeout, :write_timeout, :unavailable]
588
-
589
- Util.assert_responds_to_all(methods, retry_policy) do
590
- ":retry_policy #{retry_policy.inspect} must respond to #{methods.inspect}, " \
591
- "but doesn't"
592
- end
593
- end
583
+ # Validate options that go in an execution profile. Instantiating one
584
+ # causes validation automatically.
585
+ Cassandra::Execution::Profile.new(options)
594
586
 
595
587
  options[:listeners] = Array(options[:listeners]) if options.key?(:listeners)
596
-
597
- if options.key?(:consistency)
598
- consistency = options[:consistency]
599
-
600
- Util.assert_one_of(CONSISTENCIES, consistency) do
601
- ":consistency must be one of #{CONSISTENCIES.inspect}, " \
602
- "#{consistency.inspect} given"
603
- end
604
- end
605
-
606
588
  options[:nodelay] = !!options[:nodelay] if options.key?(:nodelay)
607
589
  options[:trace] = !!options[:trace] if options.key?(:trace)
608
590
  options[:shuffle_replicas] = !!options[:shuffle_replicas] if options.key?(:shuffle_replicas)
591
+ options[:allow_beta_protocol] = !!options[:allow_beta_protocol] if options.key?(:allow_beta_protocol)
609
592
 
610
593
  if options.key?(:page_size)
611
594
  page_size = options[:page_size]
@@ -623,12 +606,15 @@ module Cassandra
623
606
  protocol_version = options[:protocol_version]
624
607
  unless protocol_version.nil?
625
608
  Util.assert_instance_of(::Integer, protocol_version)
626
- Util.assert_one_of(1..4, protocol_version) do
627
- ":protocol_version must be a positive integer, #{protocol_version.inspect} given"
628
- end
609
+ Util.assert_one_of(1..Cassandra::Protocol::Versions::MAX_SUPPORTED_VERSION, protocol_version,
610
+ ':protocol_version must be a positive integer between 1 and ' \
611
+ "#{Cassandra::Protocol::Versions::MAX_SUPPORTED_VERSION}, #{protocol_version.inspect} given")
629
612
  end
630
613
  end
631
614
 
615
+ Util.assert(!(options[:allow_beta_protocol] && options[:protocol_version]),
616
+ 'only one of :allow_beta_protocol and :protocol_version may be specified, both given')
617
+
632
618
  if options.key?(:futures_factory)
633
619
  futures_factory = options[:futures_factory]
634
620
  methods = [:error, :value, :promise, :all]
@@ -820,9 +806,12 @@ require 'cassandra/table'
820
806
  require 'cassandra/materialized_view'
821
807
  require 'cassandra/keyspace'
822
808
  require 'cassandra/index'
809
+ require 'cassandra/trigger'
823
810
 
824
811
  require 'cassandra/execution/info'
825
812
  require 'cassandra/execution/options'
813
+ require 'cassandra/execution/profile_manager'
814
+ require 'cassandra/execution/profile'
826
815
  require 'cassandra/execution/trace'
827
816
 
828
817
  require 'cassandra/load_balancing'
@@ -845,7 +834,9 @@ module Cassandra
845
834
  # @private
846
835
  VOID_STATEMENT = Statements::Void.new
847
836
  # @private
848
- VOID_OPTIONS = Execution::Options.new(consistency: :one)
837
+ VOID_OPTIONS = Execution::Options.new(consistency: :one,
838
+ load_balancing_policy: LoadBalancing::Policies::RoundRobin.new,
839
+ retry_policy: Retry::Policies::Default.new)
849
840
  # @private
850
841
  NO_HOSTS = Errors::NoHostsAvailable.new
851
842
  end
@@ -36,9 +36,8 @@ module Cassandra
36
36
  cluster_metadata,
37
37
  execution_options,
38
38
  connection_options,
39
- load_balancing_policy,
39
+ profile_manager,
40
40
  reconnection_policy,
41
- retry_policy,
42
41
  address_resolution_policy,
43
42
  connector,
44
43
  futures_factory,
@@ -52,9 +51,8 @@ module Cassandra
52
51
  @metadata = cluster_metadata
53
52
  @execution_options = execution_options
54
53
  @connection_options = connection_options
55
- @load_balancing_policy = load_balancing_policy
54
+ @profile_manager = profile_manager
56
55
  @reconnection_policy = reconnection_policy
57
- @retry_policy = retry_policy
58
56
  @address_resolver = address_resolution_policy
59
57
  @connector = connector
60
58
  @futures = futures_factory
@@ -62,7 +60,7 @@ module Cassandra
62
60
 
63
61
  @control_connection.on_close do |_cause|
64
62
  begin
65
- @load_balancing_policy.teardown(self)
63
+ @profile_manager.teardown(self)
66
64
  rescue
67
65
  nil
68
66
  end
@@ -153,6 +151,40 @@ module Cassandra
153
151
  # @return [Boolean] true or false
154
152
  def_delegators :@schema, :keyspace, :has_keyspace?
155
153
 
154
+ # @return [Integer] Cassandra native protocol port
155
+ def port
156
+ @connection_options.port
157
+ end
158
+
159
+ # @return [Integer] the version of the native protocol used in communication with nodes
160
+ def protocol_version
161
+ @connection_options.protocol_version
162
+ end
163
+
164
+ # @param name [String] Name of profile to retrieve
165
+ # @return [Cassandra::Execution::Profile] execution profile of the given name
166
+ def execution_profile(name)
167
+ @profile_manager.profiles[name]
168
+ end
169
+
170
+ # Yield or enumerate each execution profile defined in this cluster
171
+ # @overload each_execution_profile
172
+ # @yieldparam name [String, Symbol] name of current profile
173
+ # @yieldparam profile [Cassandra::Execution::Profile] current profile
174
+ # @return [Cassandra::Cluster] self
175
+ # @overload each_execution_profile
176
+ # @return [Hash<String, Cassandra::Execution::Profile>] a hash of profiles keyed on name
177
+ def each_execution_profile(&block)
178
+ if block_given?
179
+ @profile_manager.profiles.each_pair(&block)
180
+ self
181
+ else
182
+ # Return a dup of the hash to prevent the user from adding/removing profiles from the profile-manager.
183
+ @profile_manager.profiles.dup
184
+ end
185
+ end
186
+ alias execution_profiles each_execution_profile
187
+
156
188
  # @!method refresh_schema_async
157
189
  # Trigger an asynchronous schema metadata refresh
158
190
  # @return [Cassandra::Future<nil>] a future that will be fulfilled when
@@ -201,14 +233,13 @@ module Cassandra
201
233
  @schema,
202
234
  @io_reactor,
203
235
  @connector,
204
- @load_balancing_policy,
236
+ @profile_manager,
205
237
  @reconnection_policy,
206
- @retry_policy,
207
238
  @address_resolver,
208
239
  @connection_options,
209
240
  @futures,
210
241
  @timestamp_generator)
211
- session = Session.new(client, @execution_options, @futures)
242
+ session = Session.new(client, @execution_options, @futures, @profile_manager)
212
243
  promise = @futures.promise
213
244
 
214
245
  client.connect.on_complete do |f|
@@ -282,9 +313,7 @@ module Cassandra
282
313
  "name=#{name.inspect}, " \
283
314
  "port=#{@connection_options.port}, " \
284
315
  "protocol_version=#{@connection_options.protocol_version}, " \
285
- "load_balancing_policy=#{@load_balancing_policy.inspect}, " \
286
- "consistency=#{@execution_options.consistency.inspect}, " \
287
- "timeout=#{@execution_options.timeout.inspect}, " \
316
+ "execution_profiles=#{@profile_manager.profiles.inspect}, " \
288
317
  "hosts=#{hosts.inspect}, " \
289
318
  "keyspaces=#{keyspaces.inspect}>"
290
319
  end