cassandra-driver 1.0.0.beta.1 → 1.0.0.beta.2

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 (46) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +20 -12
  3. data/ext/cassandra_murmur3/cassandra_murmur3.c +178 -0
  4. data/ext/cassandra_murmur3/extconf.rb +2 -0
  5. data/lib/cassandra.rb +132 -24
  6. data/lib/cassandra/auth.rb +5 -5
  7. data/lib/cassandra/client/connector.rb +11 -6
  8. data/lib/cassandra/cluster.rb +47 -23
  9. data/lib/cassandra/cluster/client.rb +5 -4
  10. data/lib/cassandra/cluster/connector.rb +17 -4
  11. data/lib/cassandra/cluster/control_connection.rb +21 -16
  12. data/lib/cassandra/cluster/metadata.rb +124 -0
  13. data/lib/cassandra/cluster/options.rb +5 -3
  14. data/lib/cassandra/cluster/registry.rb +26 -9
  15. data/lib/cassandra/cluster/schema.rb +23 -4
  16. data/lib/cassandra/cluster/schema/partitioners.rb +21 -0
  17. data/lib/cassandra/cluster/schema/partitioners/murmur3.rb +47 -0
  18. data/lib/cassandra/cluster/schema/partitioners/ordered.rb +37 -0
  19. data/lib/cassandra/cluster/schema/partitioners/random.rb +37 -0
  20. data/lib/cassandra/cluster/schema/replication_strategies.rb +21 -0
  21. data/lib/cassandra/cluster/schema/replication_strategies/network_topology.rb +92 -0
  22. data/lib/cassandra/cluster/schema/replication_strategies/none.rb +39 -0
  23. data/lib/cassandra/cluster/schema/replication_strategies/simple.rb +44 -0
  24. data/lib/cassandra/cluster/schema/type_parser.rb +1 -1
  25. data/lib/cassandra/compression.rb +1 -1
  26. data/lib/cassandra/driver.rb +29 -4
  27. data/lib/cassandra/execution/options.rb +3 -0
  28. data/lib/cassandra/host.rb +9 -5
  29. data/lib/cassandra/keyspace.rb +17 -4
  30. data/lib/cassandra/listener.rb +3 -3
  31. data/lib/cassandra/load_balancing.rb +12 -11
  32. data/lib/cassandra/load_balancing/policies.rb +2 -1
  33. data/lib/cassandra/load_balancing/policies/dc_aware_round_robin.rb +1 -1
  34. data/lib/cassandra/load_balancing/policies/round_robin.rb +37 -0
  35. data/lib/cassandra/load_balancing/policies/token_aware.rb +119 -0
  36. data/lib/cassandra/protocol/cql_protocol_handler.rb +2 -2
  37. data/lib/cassandra/reconnection.rb +5 -5
  38. data/lib/cassandra/retry.rb +3 -3
  39. data/lib/cassandra/session.rb +7 -0
  40. data/lib/cassandra/statements/bound.rb +4 -2
  41. data/lib/cassandra/statements/prepared.rb +28 -6
  42. data/lib/cassandra/table.rb +49 -4
  43. data/lib/cassandra/time_uuid.rb +1 -0
  44. data/lib/cassandra/util.rb +0 -2
  45. data/lib/cassandra/version.rb +1 -1
  46. metadata +50 -45
@@ -219,7 +219,6 @@ module Cassandra
219
219
  complete_request(id, @current_frame.body)
220
220
  end
221
221
  @current_frame = @frame_decoder.decode_frame(@read_buffer)
222
- flush_request_queue
223
222
  end
224
223
  end
225
224
 
@@ -249,6 +248,7 @@ module Cassandra
249
248
  if response.is_a?(Protocol::SetKeyspaceResultResponse)
250
249
  @keyspace = response.keyspace
251
250
  end
251
+ flush_request_queue
252
252
  unless promise.timed_out?
253
253
  promise.fulfill(response)
254
254
  end
@@ -272,7 +272,7 @@ module Cassandra
272
272
  if @request_queue_out.any? && (id = next_stream_id)
273
273
  promise = @request_queue_out.shift
274
274
  if promise.timed_out?
275
- id = nil
275
+ next
276
276
  else
277
277
  frame = promise.frame
278
278
  @promises[id] = promise
@@ -19,7 +19,7 @@
19
19
  module Cassandra
20
20
  module Reconnection
21
21
  # Reconnection schedule
22
- # @note actual reconnection schedules returned from
22
+ # @abstract Actual reconnection schedules returned from
23
23
  # {Cassandra::Reconnection::Policy} implementation don't need to inherit
24
24
  # this class. This class exists for documentation purposes only.
25
25
  class Schedule
@@ -29,16 +29,16 @@ module Cassandra
29
29
  end
30
30
 
31
31
  # A reconnection policy
32
- # @note actual reconnection policies supplied as `:reconnection_policy`
32
+ # @abstract Actual reconnection policies supplied as `:reconnection_policy`
33
33
  # option to {Cassandra.connect} don't need to inherit this class, only
34
34
  # implement its methods. This class exists for documentation purposes
35
35
  # only.
36
36
  class Policy
37
37
  # Returns a reconnection schedule
38
38
  #
39
- # @abstract implementation should be provided by an actual policy
40
- # @note reconnection schedule doesn't need to extend
41
- # {Cassandra::Reconnection::Schedule}, only conform to its interface
39
+ # @note Reconnection schedule returned from this method doesn't need to
40
+ # extend {Cassandra::Reconnection::Schedule}, only conform to its
41
+ # interface.
42
42
  # @return [Cassandra::Reconnection::Schedule] reconnection schedule
43
43
  def schedule
44
44
  end
@@ -18,6 +18,9 @@
18
18
 
19
19
  module Cassandra
20
20
  module Retry
21
+ # @abstract Actual retry policies supplied as `:retry_policy` option to
22
+ # {Cassandra.connect} don't need to inherit this class, only implement
23
+ # its methods. This class exists for documentation purposes only.
21
24
  module Policy
22
25
  # Decides wether to retry a read and at what consistency level.
23
26
  #
@@ -35,7 +38,6 @@ module Cassandra
35
38
  # checksum) was present in the received responses.
36
39
  # @param retries [Integer] the number of retries already performed
37
40
  #
38
- # @abstract implementation should be provided by an actual policy
39
41
  # @return [Cassandra::Policies::Retry::Decision] a retry decision
40
42
  #
41
43
  # @see Cassandra::Retry::Policy#try_again
@@ -57,7 +59,6 @@ module Cassandra
57
59
  # query timed out
58
60
  # @param retries [Integer] the number of retries already performed
59
61
  #
60
- # @abstract implementation should be provided by an actual policy
61
62
  # @return [Cassandra::Policies::Retry::Decision] a retry decision
62
63
  #
63
64
  # @see Cassandra::Retry::Policy#try_again
@@ -78,7 +79,6 @@ module Cassandra
78
79
  # query timed out
79
80
  # @param retries [Integer] the number of retries already performed
80
81
  #
81
- # @abstract implementation should be provided by an actual policy
82
82
  # @return [Cassandra::Policies::Retry::Decision] a retry decision
83
83
  #
84
84
  # @see Cassandra::Retry::Policy#try_again
@@ -19,6 +19,13 @@
19
19
  module Cassandra
20
20
  # Sessions are used for query execution. Each session tracks its current keyspace. A session should be reused as much as possible, however it is ok to create several independent session for interacting with different keyspaces in the same application.
21
21
  class Session
22
+ extend Forwardable
23
+
24
+ # @!method keyspace
25
+ # Returns current keyspace
26
+ # @return [String] current keyspace
27
+ def_delegators :@client, :keyspace
28
+
22
29
  # @private
23
30
  def initialize(client, default_options, futures_factory)
24
31
  @client = client
@@ -27,14 +27,16 @@ module Cassandra
27
27
  # @return [Array<Object>] a list of positional parameters for the cql
28
28
  attr_reader :params
29
29
  # @private
30
- attr_reader :params_metadata, :result_metadata
30
+ attr_reader :params_metadata, :result_metadata, :keyspace, :partition_key
31
31
 
32
32
  # @private
33
- def initialize(cql, params_metadata, result_metadata, params)
33
+ def initialize(cql, params_metadata, result_metadata, params, keyspace = nil, partition_key = nil)
34
34
  @cql = cql
35
35
  @params_metadata = params_metadata
36
36
  @result_metadata = result_metadata
37
37
  @params = params
38
+ @keyspace = keyspace
39
+ @partition_key = partition_key
38
40
  end
39
41
 
40
42
  # @return [String] a CLI-friendly bound statement representation
@@ -23,20 +23,25 @@ module Cassandra
23
23
 
24
24
  # @return [String] original cql used to prepare this statement
25
25
  attr_reader :cql
26
- # @return [Cassandra::Execution::Info] execution info for PREPARE request
27
- attr_reader :execution_info
28
-
29
26
  # @private
30
27
  attr_reader :params_metadata
31
28
  # @private
32
29
  attr_reader :result_metadata
33
30
 
34
31
  # @private
35
- def initialize(cql, params_metadata, result_metadata, execution_info)
32
+ def initialize(cql, params_metadata, result_metadata, trace_id, keyspace, statement, options, hosts, consistency, retries, client, futures_factory, schema)
36
33
  @cql = cql
37
34
  @params_metadata = params_metadata
38
35
  @result_metadata = result_metadata
39
- @execution_info = execution_info
36
+ @trace_id = trace_id
37
+ @keyspace = keyspace
38
+ @statement = statement
39
+ @options = options
40
+ @hosts = hosts
41
+ @consistency = consistency
42
+ @retries = retries
43
+ @client = client
44
+ @schema = schema
40
45
  end
41
46
 
42
47
  # Creates a statement bound with specific arguments
@@ -47,7 +52,24 @@ module Cassandra
47
52
  def bind(*args)
48
53
  raise ::ArgumentError, "expecting exactly #{@params_metadata.size} bind parameters, #{args.size} given" if args.size != @params_metadata.size
49
54
 
50
- Bound.new(@cql, @params_metadata, @result_metadata, args)
55
+ return Bound.new(@cql, @params_metadata, @result_metadata, args) if @params_metadata.empty?
56
+
57
+ keyspace, table, _, _ = @params_metadata.first
58
+ return Bound.new(@cql, @params_metadata, @result_metadata, args, keyspace) unless keyspace && table
59
+
60
+ values = ::Hash.new
61
+ @params_metadata.zip(args) do |(keyspace, table, column, type), value|
62
+ values[column] = value
63
+ end
64
+
65
+ partition_key = @schema.create_partition_key(keyspace, table, values)
66
+
67
+ Bound.new(@cql, @params_metadata, @result_metadata, args, keyspace, partition_key)
68
+ end
69
+
70
+ # @return [Cassandra::Execution::Info] execution info for PREPARE request
71
+ def execution_info
72
+ @info ||= Execution::Info.new(@keyspace, @statement, @options, @hosts, @consistency, @retries, @trace_id ? Execution::Trace.new(@trace_id, @client) : nil)
51
73
  end
52
74
 
53
75
  # @return [String] a CLI-friendly prepared statement representation
@@ -164,11 +164,16 @@ module Cassandra
164
164
  # Yield or enumerate each column defined in this table
165
165
  # @overload each_column
166
166
  # @yieldparam column [Cassandra::Column] current column
167
- # @return [Array<Cassandra::Column>] a list of columns
167
+ # @return [Cassandra::Table] self
168
168
  # @overload each_column
169
- # @return [Enumerator<Cassandra::Column>] an enumerator
169
+ # @return [Array<Cassandra::Column>] a list of columns
170
170
  def each_column(&block)
171
- @columns.values.each(&block)
171
+ if block_given?
172
+ @columns.each_value(&block)
173
+ self
174
+ else
175
+ @columns.values
176
+ end
172
177
  end
173
178
  alias :columns :each_column
174
179
 
@@ -177,7 +182,6 @@ module Cassandra
177
182
  cql = "CREATE TABLE #{Util.escape_name(@keyspace)}.#{Util.escape_name(@name)} (\n"
178
183
  first = true
179
184
  @columns.each do |(_, column)|
180
- next if column.name.empty?
181
185
  if first
182
186
  first = false
183
187
  else
@@ -241,6 +245,47 @@ module Cassandra
241
245
  alias :== :eql?
242
246
 
243
247
  # @private
248
+ def create_partition_key(values)
249
+ partition_key = @partition_key
250
+ return nil unless partition_key.size == values.size
251
+
252
+ if partition_key.one?
253
+ column = partition_key.first
254
+ column_name = column.name
255
+ return nil unless values.has_key?(column_name)
256
+
257
+ buffer = Protocol::CqlByteBuffer.new
258
+
259
+ TYPE_CONVERTER.to_bytes(buffer, column.type, values[column_name])
260
+ buffer.discard(4)
261
+ else
262
+ buf = nil
263
+ buffer = nil
264
+
265
+ partition_key.each do |column|
266
+ column_name = column.name
267
+ return nil unless values.has_key?(column_name)
268
+
269
+ buf ||= Protocol::CqlByteBuffer.new
270
+ buffer ||= Protocol::CqlByteBuffer.new
271
+
272
+ TYPE_CONVERTER.to_bytes(buf, column.type, values[column_name])
273
+ buf.discard(4) # discard size
274
+
275
+ size = buf.length
276
+ buffer.append_short(size)
277
+ buffer << buf.read(size) << NULL_BYTE
278
+ end
279
+ end
280
+
281
+ buffer.to_str
282
+ end
283
+
284
+ private
285
+
286
+ NULL_BYTE = "\x00".freeze
287
+ TYPE_CONVERTER = Protocol::TypeConverter.new
288
+
244
289
  attr_reader :partition_key, :clustering_columns, :clustering_order
245
290
  protected :partition_key, :clustering_columns, :clustering_order
246
291
 
@@ -33,6 +33,7 @@ module Cassandra
33
33
  end
34
34
 
35
35
  def <=>(other)
36
+ return nil unless other.kind_of?(Cassandra::Uuid)
36
37
  c = self.value <=> other.value
37
38
  return c if c == 0
38
39
  self.time_bits <=> other.time_bits
@@ -16,8 +16,6 @@
16
16
  # limitations under the License.
17
17
  #++
18
18
 
19
- require 'stringio'
20
-
21
19
  module Cassandra
22
20
  # @private
23
21
  module Util extend self
@@ -17,5 +17,5 @@
17
17
  #++
18
18
 
19
19
  module Cassandra
20
- VERSION = '1.0.0.beta.1'.freeze
20
+ VERSION = '1.0.0.beta.2'.freeze
21
21
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cassandra-driver
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: 6
5
- version: 1.0.0.beta.1
4
+ version: 1.0.0.beta.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Theo Hultberg
@@ -10,68 +9,69 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2014-09-11 00:00:00.000000000 Z
12
+ date: 2014-10-02 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
- name: ione
15
+ prerelease: false
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: 1.2.0.pre4
17
21
  type: :runtime
18
22
  requirement: !ruby/object:Gem::Requirement
19
- none: false
20
23
  requirements:
21
24
  - - ~>
22
25
  - !ruby/object:Gem::Version
23
- version: '1.0'
26
+ version: 1.2.0.pre4
27
+ name: ione
28
+ - !ruby/object:Gem::Dependency
24
29
  prerelease: false
25
30
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
31
  requirements:
28
32
  - - ~>
29
33
  - !ruby/object:Gem::Version
30
- version: '1.0'
31
- - !ruby/object:Gem::Dependency
32
- name: bundler
34
+ version: '1.6'
33
35
  type: :development
34
36
  requirement: !ruby/object:Gem::Requirement
35
- none: false
36
37
  requirements:
37
38
  - - ~>
38
39
  - !ruby/object:Gem::Version
39
40
  version: '1.6'
41
+ name: bundler
42
+ - !ruby/object:Gem::Dependency
40
43
  prerelease: false
41
44
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
45
  requirements:
44
46
  - - ~>
45
47
  - !ruby/object:Gem::Version
46
- version: '1.6'
47
- - !ruby/object:Gem::Dependency
48
- name: rake
48
+ version: '10.0'
49
49
  type: :development
50
50
  requirement: !ruby/object:Gem::Requirement
51
- none: false
52
- requirements:
53
- - - ~>
54
- - !ruby/object:Gem::Version
55
- version: '10.0'
56
- prerelease: false
57
- version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
51
  requirements:
60
52
  - - ~>
61
53
  - !ruby/object:Gem::Version
62
54
  version: '10.0'
55
+ name: rake
63
56
  description: A pure Ruby driver for Apache Cassandra
64
57
  email:
65
58
  - theo@iconara.net
66
59
  - bulat.shakirzyanov@datastax.com
67
60
  executables: []
68
- extensions: []
61
+ extensions:
62
+ - ext/cassandra_murmur3/extconf.rb
69
63
  extra_rdoc_files:
70
64
  - README.md
71
65
  files:
72
- - lib/cassandra/auth/providers/password.rb
73
- - lib/cassandra/auth/providers.rb
66
+ - .yardopts
67
+ - README.md
68
+ - ext/cassandra_murmur3/cassandra_murmur3.c
69
+ - ext/cassandra_murmur3/extconf.rb
70
+ - lib/cassandra.rb
74
71
  - lib/cassandra/auth.rb
72
+ - lib/cassandra/auth/providers.rb
73
+ - lib/cassandra/auth/providers/password.rb
74
+ - lib/cassandra/client.rb
75
75
  - lib/cassandra/client/batch.rb
76
76
  - lib/cassandra/client/client.rb
77
77
  - lib/cassandra/client/column_metadata.rb
@@ -85,19 +85,27 @@ files:
85
85
  - lib/cassandra/client/request_runner.rb
86
86
  - lib/cassandra/client/result_metadata.rb
87
87
  - lib/cassandra/client/void_result.rb
88
- - lib/cassandra/client.rb
88
+ - lib/cassandra/cluster.rb
89
89
  - lib/cassandra/cluster/client.rb
90
90
  - lib/cassandra/cluster/connector.rb
91
91
  - lib/cassandra/cluster/control_connection.rb
92
+ - lib/cassandra/cluster/metadata.rb
92
93
  - lib/cassandra/cluster/options.rb
93
94
  - lib/cassandra/cluster/registry.rb
94
- - lib/cassandra/cluster/schema/type_parser.rb
95
95
  - lib/cassandra/cluster/schema.rb
96
- - lib/cassandra/cluster.rb
96
+ - lib/cassandra/cluster/schema/partitioners.rb
97
+ - lib/cassandra/cluster/schema/partitioners/murmur3.rb
98
+ - lib/cassandra/cluster/schema/partitioners/ordered.rb
99
+ - lib/cassandra/cluster/schema/partitioners/random.rb
100
+ - lib/cassandra/cluster/schema/replication_strategies.rb
101
+ - lib/cassandra/cluster/schema/replication_strategies/network_topology.rb
102
+ - lib/cassandra/cluster/schema/replication_strategies/none.rb
103
+ - lib/cassandra/cluster/schema/replication_strategies/simple.rb
104
+ - lib/cassandra/cluster/schema/type_parser.rb
97
105
  - lib/cassandra/column.rb
106
+ - lib/cassandra/compression.rb
98
107
  - lib/cassandra/compression/compressors/lz4.rb
99
108
  - lib/cassandra/compression/compressors/snappy.rb
100
- - lib/cassandra/compression.rb
101
109
  - lib/cassandra/driver.rb
102
110
  - lib/cassandra/errors.rb
103
111
  - lib/cassandra/execution/info.rb
@@ -107,11 +115,13 @@ files:
107
115
  - lib/cassandra/host.rb
108
116
  - lib/cassandra/keyspace.rb
109
117
  - lib/cassandra/listener.rb
118
+ - lib/cassandra/load_balancing.rb
119
+ - lib/cassandra/load_balancing/policies.rb
110
120
  - lib/cassandra/load_balancing/policies/dc_aware_round_robin.rb
111
121
  - lib/cassandra/load_balancing/policies/round_robin.rb
122
+ - lib/cassandra/load_balancing/policies/token_aware.rb
112
123
  - lib/cassandra/load_balancing/policies/white_list.rb
113
- - lib/cassandra/load_balancing/policies.rb
114
- - lib/cassandra/load_balancing.rb
124
+ - lib/cassandra/protocol.rb
115
125
  - lib/cassandra/protocol/cql_byte_buffer.rb
116
126
  - lib/cassandra/protocol/cql_protocol_handler.rb
117
127
  - lib/cassandra/protocol/frame_decoder.rb
@@ -147,36 +157,33 @@ files:
147
157
  - lib/cassandra/protocol/responses/topology_change_event_response.rb
148
158
  - lib/cassandra/protocol/responses/void_result_response.rb
149
159
  - lib/cassandra/protocol/type_converter.rb
150
- - lib/cassandra/protocol.rb
160
+ - lib/cassandra/reconnection.rb
161
+ - lib/cassandra/reconnection/policies.rb
151
162
  - lib/cassandra/reconnection/policies/constant.rb
152
163
  - lib/cassandra/reconnection/policies/exponential.rb
153
- - lib/cassandra/reconnection/policies.rb
154
- - lib/cassandra/reconnection.rb
155
164
  - lib/cassandra/result.rb
165
+ - lib/cassandra/retry.rb
166
+ - lib/cassandra/retry/policies.rb
156
167
  - lib/cassandra/retry/policies/default.rb
157
168
  - lib/cassandra/retry/policies/downgrading_consistency.rb
158
169
  - lib/cassandra/retry/policies/fallthrough.rb
159
- - lib/cassandra/retry/policies.rb
160
- - lib/cassandra/retry.rb
161
170
  - lib/cassandra/session.rb
162
171
  - lib/cassandra/statement.rb
172
+ - lib/cassandra/statements.rb
163
173
  - lib/cassandra/statements/batch.rb
164
174
  - lib/cassandra/statements/bound.rb
165
175
  - lib/cassandra/statements/prepared.rb
166
176
  - lib/cassandra/statements/simple.rb
167
177
  - lib/cassandra/statements/void.rb
168
- - lib/cassandra/statements.rb
169
178
  - lib/cassandra/table.rb
170
179
  - lib/cassandra/time_uuid.rb
171
180
  - lib/cassandra/util.rb
172
181
  - lib/cassandra/uuid.rb
173
182
  - lib/cassandra/version.rb
174
- - lib/cassandra.rb
175
- - README.md
176
- - .yardopts
177
183
  homepage: http://datastax.github.io/ruby-driver
178
184
  licenses:
179
185
  - Apache License 2.0
186
+ metadata: {}
180
187
  post_install_message:
181
188
  rdoc_options:
182
189
  - --title
@@ -187,22 +194,20 @@ rdoc_options:
187
194
  require_paths:
188
195
  - lib
189
196
  required_ruby_version: !ruby/object:Gem::Requirement
190
- none: false
191
197
  requirements:
192
198
  - - '>='
193
199
  - !ruby/object:Gem::Version
194
200
  version: 1.9.3
195
201
  required_rubygems_version: !ruby/object:Gem::Requirement
196
- none: false
197
202
  requirements:
198
203
  - - '>'
199
204
  - !ruby/object:Gem::Version
200
205
  version: 1.3.1
201
206
  requirements: []
202
207
  rubyforge_project:
203
- rubygems_version: 1.8.23
208
+ rubygems_version: 2.4.1
204
209
  signing_key:
205
- specification_version: 3
210
+ specification_version: 4
206
211
  summary: Datastax Ruby Driver for Apache Cassandra
207
212
  test_files: []
208
213
  has_rdoc: