cassandra-driver 1.0.0.rc.1 → 1.0.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.
- checksums.yaml +8 -8
- data/README.md +45 -10
- data/lib/cassandra.rb +82 -82
- data/lib/cassandra/cluster.rb +3 -0
- data/lib/cassandra/cluster/client.rb +17 -5
- data/lib/cassandra/{client/connection_manager.rb → cluster/connection_pool.rb} +3 -3
- data/lib/cassandra/cluster/connector.rb +101 -30
- data/lib/cassandra/cluster/control_connection.rb +6 -7
- data/lib/cassandra/{client/null_logger.rb → cluster/failed_connection.rb} +12 -14
- data/lib/cassandra/cluster/options.rb +8 -0
- data/lib/cassandra/column.rb +5 -0
- data/lib/cassandra/driver.rb +3 -3
- data/lib/cassandra/errors.rb +5 -5
- data/lib/cassandra/execution/options.rb +13 -6
- data/lib/cassandra/execution/trace.rb +4 -4
- data/lib/cassandra/future.rb +4 -0
- data/lib/cassandra/keyspace.rb +5 -0
- data/lib/cassandra/load_balancing/policies/dc_aware_round_robin.rb +7 -2
- data/lib/cassandra/load_balancing/policies/token_aware.rb +1 -3
- data/lib/cassandra/load_balancing/policies/white_list.rb +3 -6
- data/lib/cassandra/null_logger.rb +35 -0
- data/lib/cassandra/protocol/cql_protocol_handler.rb +4 -0
- data/lib/cassandra/protocol/requests/query_request.rb +1 -11
- data/lib/cassandra/result.rb +4 -6
- data/lib/cassandra/session.rb +3 -0
- data/lib/cassandra/statements/prepared.rb +5 -1
- data/lib/cassandra/table.rb +5 -0
- data/lib/cassandra/util.rb +130 -0
- data/lib/cassandra/version.rb +1 -1
- metadata +9 -20
- 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 -273
- 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 -70
- 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,70 +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
|
-
raise response.to_error(cql)
|
35
|
-
when Protocol::SetKeyspaceResultResponse
|
36
|
-
KeyspaceChanged.new(response.keyspace)
|
37
|
-
when Protocol::AuthenticateResponse
|
38
|
-
AuthenticationRequired.new(response.authentication_class)
|
39
|
-
when Protocol::SupportedResponse
|
40
|
-
response.options
|
41
|
-
else
|
42
|
-
if block_given?
|
43
|
-
yield response
|
44
|
-
else
|
45
|
-
nil
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
# @private
|
53
|
-
class AuthenticationRequired
|
54
|
-
attr_reader :authentication_class
|
55
|
-
|
56
|
-
def initialize(authentication_class)
|
57
|
-
@authentication_class = authentication_class
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
# @private
|
62
|
-
class KeyspaceChanged
|
63
|
-
attr_reader :keyspace
|
64
|
-
|
65
|
-
def initialize(keyspace)
|
66
|
-
@keyspace = keyspace
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
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
|