cassandra-driver 1.0.0.beta.3-java → 1.0.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +51 -14
- data/lib/cassandra.rb +164 -78
- data/lib/cassandra/address_resolution.rb +36 -0
- data/lib/cassandra/address_resolution/policies.rb +2 -0
- data/lib/cassandra/address_resolution/policies/ec2_multi_region.rb +56 -0
- data/lib/cassandra/address_resolution/policies/none.rb +35 -0
- data/lib/cassandra/auth.rb +1 -1
- data/lib/cassandra/auth/providers/password.rb +1 -1
- data/lib/cassandra/cluster.rb +18 -5
- data/lib/cassandra/cluster/client.rb +175 -101
- data/lib/cassandra/{client/connection_manager.rb → cluster/connection_pool.rb} +5 -5
- data/lib/cassandra/cluster/connector.rb +142 -56
- data/lib/cassandra/cluster/control_connection.rb +385 -134
- data/lib/cassandra/{client/null_logger.rb → cluster/failed_connection.rb} +12 -14
- data/lib/cassandra/cluster/options.rb +13 -2
- data/lib/cassandra/cluster/registry.rb +19 -9
- data/lib/cassandra/column.rb +5 -0
- data/lib/cassandra/compression.rb +1 -1
- data/lib/cassandra/compression/compressors/lz4.rb +1 -1
- data/lib/cassandra/compression/compressors/snappy.rb +1 -1
- data/lib/cassandra/driver.rb +29 -21
- data/lib/cassandra/errors.rb +325 -35
- data/lib/cassandra/execution/options.rb +13 -6
- data/lib/cassandra/execution/trace.rb +4 -4
- data/lib/cassandra/future.rb +7 -3
- data/lib/cassandra/keyspace.rb +5 -0
- data/lib/cassandra/load_balancing/policies/dc_aware_round_robin.rb +13 -4
- data/lib/cassandra/load_balancing/policies/token_aware.rb +2 -4
- data/lib/cassandra/load_balancing/policies/white_list.rb +3 -6
- data/lib/cassandra/null_logger.rb +35 -0
- data/lib/cassandra/protocol.rb +0 -16
- data/lib/cassandra/protocol/cql_byte_buffer.rb +18 -18
- data/lib/cassandra/protocol/cql_protocol_handler.rb +78 -8
- data/lib/cassandra/protocol/frame_decoder.rb +2 -2
- data/lib/cassandra/protocol/frame_encoder.rb +1 -1
- data/lib/cassandra/protocol/requests/query_request.rb +1 -11
- data/lib/cassandra/protocol/response.rb +1 -1
- data/lib/cassandra/protocol/responses/detailed_error_response.rb +16 -1
- data/lib/cassandra/protocol/responses/error_response.rb +17 -0
- data/lib/cassandra/protocol/responses/event_response.rb +1 -1
- data/lib/cassandra/protocol/responses/raw_rows_result_response.rb +1 -1
- data/lib/cassandra/protocol/responses/result_response.rb +1 -1
- data/lib/cassandra/protocol/responses/rows_result_response.rb +1 -1
- data/lib/cassandra/protocol/type_converter.rb +4 -3
- data/lib/cassandra/reconnection.rb +1 -1
- data/lib/cassandra/result.rb +4 -6
- data/lib/cassandra/retry.rb +3 -5
- data/lib/cassandra/session.rb +14 -5
- data/lib/cassandra/statements/prepared.rb +5 -1
- data/lib/cassandra/table.rb +6 -1
- data/lib/cassandra/time_uuid.rb +21 -83
- data/lib/cassandra/util.rb +131 -1
- data/lib/cassandra/uuid.rb +6 -4
- data/lib/cassandra/uuid/generator.rb +207 -0
- data/lib/cassandra/version.rb +1 -1
- data/lib/cassandra_murmur3.jar +0 -0
- metadata +43 -49
- data/lib/cassandra/client.rb +0 -144
- data/lib/cassandra/client/batch.rb +0 -212
- data/lib/cassandra/client/client.rb +0 -591
- data/lib/cassandra/client/column_metadata.rb +0 -54
- data/lib/cassandra/client/connector.rb +0 -277
- data/lib/cassandra/client/execute_options_decoder.rb +0 -59
- data/lib/cassandra/client/peer_discovery.rb +0 -50
- data/lib/cassandra/client/prepared_statement.rb +0 -314
- data/lib/cassandra/client/query_result.rb +0 -230
- data/lib/cassandra/client/request_runner.rb +0 -71
- data/lib/cassandra/client/result_metadata.rb +0 -48
- data/lib/cassandra/client/void_result.rb +0 -78
@@ -1,230 +0,0 @@
|
|
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 Client
|
21
|
-
# Query results encapsulate the rows returned by a query.
|
22
|
-
#
|
23
|
-
# In addition to containing the rows it contains metadata about the data
|
24
|
-
# types of the columns of the rows, and it knows the ID of the trace,
|
25
|
-
# if tracing was requested for the query.
|
26
|
-
#
|
27
|
-
# When paging over a big result you can use {#last_page?} to find out if the
|
28
|
-
# page is the last, or {#next_page} to retrieve the next page.
|
29
|
-
#
|
30
|
-
# `QueryResult` is an `Enumerable` so it can be mapped, filtered, reduced, etc.
|
31
|
-
class QueryResult
|
32
|
-
include Enumerable
|
33
|
-
|
34
|
-
# @return [ResultMetadata]
|
35
|
-
attr_reader :metadata
|
36
|
-
|
37
|
-
# The ID of the query trace associated with the query, if any.
|
38
|
-
#
|
39
|
-
# @return [Cassandra::Uuid]
|
40
|
-
attr_reader :trace_id
|
41
|
-
|
42
|
-
# @private
|
43
|
-
attr_reader :paging_state
|
44
|
-
|
45
|
-
# @private
|
46
|
-
def initialize(metadata, rows, trace_id, paging_state)
|
47
|
-
@metadata = ResultMetadata.new(metadata)
|
48
|
-
@rows = rows
|
49
|
-
@trace_id = trace_id
|
50
|
-
@paging_state = paging_state
|
51
|
-
end
|
52
|
-
|
53
|
-
# Returns whether or not there are any rows in this result set
|
54
|
-
def empty?
|
55
|
-
@rows.empty?
|
56
|
-
end
|
57
|
-
|
58
|
-
# Returns count of underlying rows
|
59
|
-
def size
|
60
|
-
@rows.size
|
61
|
-
end
|
62
|
-
alias :length :size
|
63
|
-
|
64
|
-
# Iterates over each row in the result set.
|
65
|
-
#
|
66
|
-
# @yieldparam [Hash] row each row in the result set as a hash
|
67
|
-
# @return [Enumerable<Hash>]
|
68
|
-
def each(&block)
|
69
|
-
@rows.each(&block)
|
70
|
-
end
|
71
|
-
alias_method :each_row, :each
|
72
|
-
|
73
|
-
# Returns true when there are no more pages to load.
|
74
|
-
#
|
75
|
-
# This is only relevant when you have requested paging of the results with
|
76
|
-
# the `:page_size` option to {Cassandra::Client::Client#execute} or
|
77
|
-
# {Cassandra::Client::PreparedStatement#execute}.
|
78
|
-
#
|
79
|
-
# @see Cassandra::Client::Client#execute
|
80
|
-
def last_page?
|
81
|
-
true
|
82
|
-
end
|
83
|
-
|
84
|
-
# Returns the next page or nil when there is no next page.
|
85
|
-
#
|
86
|
-
# This is only relevant when you have requested paging of the results with
|
87
|
-
# the `:page_size` option to {Cassandra::Client::Client#execute} or
|
88
|
-
# {Cassandra::Client::PreparedStatement#execute}.
|
89
|
-
#
|
90
|
-
# @see Cassandra::Client::Client#execute
|
91
|
-
def next_page
|
92
|
-
nil
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
# @private
|
97
|
-
class PagedQueryResult < QueryResult
|
98
|
-
def metadata
|
99
|
-
@result.metadata
|
100
|
-
end
|
101
|
-
|
102
|
-
def trace_id
|
103
|
-
@result.trace_id
|
104
|
-
end
|
105
|
-
|
106
|
-
def paging_state
|
107
|
-
@result.paging_state
|
108
|
-
end
|
109
|
-
|
110
|
-
def empty?
|
111
|
-
@result.empty?
|
112
|
-
end
|
113
|
-
|
114
|
-
def each(&block)
|
115
|
-
@result.each(&block)
|
116
|
-
end
|
117
|
-
alias_method :each_row, :each
|
118
|
-
|
119
|
-
def last_page?
|
120
|
-
@last_page
|
121
|
-
end
|
122
|
-
|
123
|
-
def next_page
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
# @private
|
128
|
-
class AsynchronousPagedQueryResult < PagedQueryResult
|
129
|
-
def initialize(request, result, options)
|
130
|
-
@request = request
|
131
|
-
@result = result
|
132
|
-
@result = result
|
133
|
-
@options = options.merge(paging_state: result.paging_state)
|
134
|
-
@last_page = !result.paging_state
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
# @private
|
139
|
-
class AsynchronousQueryPagedQueryResult < AsynchronousPagedQueryResult
|
140
|
-
def initialize(client, request, result, options)
|
141
|
-
super(request, result, options)
|
142
|
-
@client = client
|
143
|
-
end
|
144
|
-
|
145
|
-
def next_page
|
146
|
-
return Ione::Future.resolved(nil) if last_page?
|
147
|
-
@client.execute(@request.cql, *@request.values, @options)
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
# @private
|
152
|
-
class AsynchronousPreparedPagedQueryResult < AsynchronousPagedQueryResult
|
153
|
-
def initialize(prepared_statement, request, result, options)
|
154
|
-
super(request, result, options)
|
155
|
-
@prepared_statement = prepared_statement
|
156
|
-
end
|
157
|
-
|
158
|
-
def next_page
|
159
|
-
return Ione::Future.resolved(nil) if last_page?
|
160
|
-
@prepared_statement.execute(*@request.values, @options)
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
# @private
|
165
|
-
class SynchronousPagedQueryResult < PagedQueryResult
|
166
|
-
include SynchronousBacktrace
|
167
|
-
|
168
|
-
def initialize(asynchronous_result)
|
169
|
-
@result = asynchronous_result
|
170
|
-
end
|
171
|
-
|
172
|
-
def async
|
173
|
-
@result
|
174
|
-
end
|
175
|
-
|
176
|
-
def last_page?
|
177
|
-
@result.last_page?
|
178
|
-
end
|
179
|
-
|
180
|
-
def next_page
|
181
|
-
synchronous_backtrace do
|
182
|
-
asynchronous_result = @result.next_page.value
|
183
|
-
asynchronous_result && self.class.new(asynchronous_result)
|
184
|
-
end
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
# @private
|
189
|
-
class LazyQueryResult < QueryResult
|
190
|
-
def initialize(metadata, lazy_rows, trace_id, paging_state)
|
191
|
-
super(metadata, nil, trace_id, paging_state)
|
192
|
-
@raw_metadata = metadata
|
193
|
-
@lazy_rows = lazy_rows
|
194
|
-
@lock = Mutex.new
|
195
|
-
end
|
196
|
-
|
197
|
-
def empty?
|
198
|
-
ensure_materialized
|
199
|
-
super
|
200
|
-
end
|
201
|
-
|
202
|
-
def size
|
203
|
-
ensure_materialized
|
204
|
-
super
|
205
|
-
end
|
206
|
-
alias :length :size
|
207
|
-
|
208
|
-
def each(&block)
|
209
|
-
ensure_materialized
|
210
|
-
super
|
211
|
-
end
|
212
|
-
alias_method :each_row, :each
|
213
|
-
|
214
|
-
private
|
215
|
-
|
216
|
-
def ensure_materialized
|
217
|
-
unless @rows
|
218
|
-
@lock.lock
|
219
|
-
begin
|
220
|
-
unless @rows
|
221
|
-
@rows = @lazy_rows.materialize(@raw_metadata)
|
222
|
-
end
|
223
|
-
ensure
|
224
|
-
@lock.unlock
|
225
|
-
end
|
226
|
-
end
|
227
|
-
end
|
228
|
-
end
|
229
|
-
end
|
230
|
-
end
|
@@ -1,71 +0,0 @@
|
|
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 Client
|
21
|
-
# @private
|
22
|
-
class RequestRunner
|
23
|
-
def execute(connection, request, timeout=nil, raw_metadata=nil)
|
24
|
-
connection.send_request(request, timeout).map do |response|
|
25
|
-
case response
|
26
|
-
when Protocol::RawRowsResultResponse
|
27
|
-
LazyQueryResult.new(raw_metadata, response, response.trace_id, response.paging_state)
|
28
|
-
when Protocol::RowsResultResponse
|
29
|
-
QueryResult.new(response.metadata, response.rows, response.trace_id, response.paging_state)
|
30
|
-
when Protocol::VoidResultResponse
|
31
|
-
response.trace_id ? VoidResult.new(response.trace_id) : VoidResult::INSTANCE
|
32
|
-
when Protocol::ErrorResponse
|
33
|
-
cql = request.is_a?(Protocol::QueryRequest) ? request.cql : nil
|
34
|
-
details = response.respond_to?(:details) ? response.details : nil
|
35
|
-
raise Errors::QueryError.new(response.code, response.message, cql, details)
|
36
|
-
when Protocol::SetKeyspaceResultResponse
|
37
|
-
KeyspaceChanged.new(response.keyspace)
|
38
|
-
when Protocol::AuthenticateResponse
|
39
|
-
AuthenticationRequired.new(response.authentication_class)
|
40
|
-
when Protocol::SupportedResponse
|
41
|
-
response.options
|
42
|
-
else
|
43
|
-
if block_given?
|
44
|
-
yield response
|
45
|
-
else
|
46
|
-
nil
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
# @private
|
54
|
-
class AuthenticationRequired
|
55
|
-
attr_reader :authentication_class
|
56
|
-
|
57
|
-
def initialize(authentication_class)
|
58
|
-
@authentication_class = authentication_class
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
# @private
|
63
|
-
class KeyspaceChanged
|
64
|
-
attr_reader :keyspace
|
65
|
-
|
66
|
-
def initialize(keyspace)
|
67
|
-
@keyspace = keyspace
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
@@ -1,48 +0,0 @@
|
|
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 Client
|
21
|
-
# A collection of metadata (keyspace, table, name and type) of a result set.
|
22
|
-
#
|
23
|
-
# @see Cassandra::Client::ColumnMetadata
|
24
|
-
class ResultMetadata
|
25
|
-
include Enumerable
|
26
|
-
|
27
|
-
# @private
|
28
|
-
def initialize(metadata)
|
29
|
-
@metadata = metadata.each_with_object({}) { |m, h| h[m[2]] = ColumnMetadata.new(*m) }
|
30
|
-
end
|
31
|
-
|
32
|
-
# Returns the column metadata
|
33
|
-
#
|
34
|
-
# @return [ColumnMetadata] column_metadata the metadata for the column
|
35
|
-
def [](column_name)
|
36
|
-
@metadata[column_name]
|
37
|
-
end
|
38
|
-
|
39
|
-
# Iterates over the metadata for each column
|
40
|
-
#
|
41
|
-
# @yieldparam [ColumnMetadata] metadata the metadata for each column
|
42
|
-
# @return [Enumerable<ColumnMetadata>]
|
43
|
-
def each(&block)
|
44
|
-
@metadata.each_value(&block)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,78 +0,0 @@
|
|
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 Client
|
21
|
-
# Many CQL queries do not return any rows, but they can still return
|
22
|
-
# data about the query, for example the trace ID. This class exist to make
|
23
|
-
# that data available.
|
24
|
-
#
|
25
|
-
# It has the exact same API as {Cassandra::Client::QueryResult} so that you don't
|
26
|
-
# need to check the return value of for example {Cassandra::Client::Client#execute}.
|
27
|
-
#
|
28
|
-
# @see Cassandra::Client::QueryResult
|
29
|
-
# @see Cassandra::Client::Client#execute
|
30
|
-
# @see Cassandra::Client::PreparedStatement#execute
|
31
|
-
class VoidResult
|
32
|
-
include Enumerable
|
33
|
-
|
34
|
-
INSTANCE = self.new
|
35
|
-
|
36
|
-
# @return [ResultMetadata]
|
37
|
-
attr_reader :metadata
|
38
|
-
|
39
|
-
# The ID of the query trace associated with the query, if any.
|
40
|
-
#
|
41
|
-
# @return [Cassandra::Uuid]
|
42
|
-
attr_reader :trace_id
|
43
|
-
|
44
|
-
# @private
|
45
|
-
def initialize(trace_id=nil)
|
46
|
-
@trace_id = trace_id
|
47
|
-
@metadata = EMPTY_METADATA
|
48
|
-
end
|
49
|
-
|
50
|
-
# Always returns true
|
51
|
-
def empty?
|
52
|
-
true
|
53
|
-
end
|
54
|
-
|
55
|
-
# Always returns true
|
56
|
-
def last_page?
|
57
|
-
true
|
58
|
-
end
|
59
|
-
|
60
|
-
# Always returns nil
|
61
|
-
def next_page
|
62
|
-
nil
|
63
|
-
end
|
64
|
-
|
65
|
-
# No-op for API compatibility with {QueryResult}.
|
66
|
-
#
|
67
|
-
# @return [Enumerable]
|
68
|
-
def each(&block)
|
69
|
-
self
|
70
|
-
end
|
71
|
-
alias_method :each_row, :each
|
72
|
-
|
73
|
-
private
|
74
|
-
|
75
|
-
EMPTY_METADATA = ResultMetadata.new([])
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|