cassandra-driver 1.0.0.beta.2-java
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 +7 -0
- data/.yardopts +4 -0
- data/README.md +125 -0
- data/lib/cassandra/auth/providers/password.rb +73 -0
- data/lib/cassandra/auth/providers.rb +16 -0
- data/lib/cassandra/auth.rb +97 -0
- data/lib/cassandra/client/batch.rb +212 -0
- data/lib/cassandra/client/client.rb +591 -0
- data/lib/cassandra/client/column_metadata.rb +54 -0
- data/lib/cassandra/client/connection_manager.rb +72 -0
- data/lib/cassandra/client/connector.rb +277 -0
- data/lib/cassandra/client/execute_options_decoder.rb +59 -0
- data/lib/cassandra/client/null_logger.rb +37 -0
- data/lib/cassandra/client/peer_discovery.rb +50 -0
- data/lib/cassandra/client/prepared_statement.rb +314 -0
- data/lib/cassandra/client/query_result.rb +230 -0
- data/lib/cassandra/client/request_runner.rb +71 -0
- data/lib/cassandra/client/result_metadata.rb +48 -0
- data/lib/cassandra/client/void_result.rb +78 -0
- data/lib/cassandra/client.rb +144 -0
- data/lib/cassandra/cluster/client.rb +768 -0
- data/lib/cassandra/cluster/connector.rb +244 -0
- data/lib/cassandra/cluster/control_connection.rb +425 -0
- data/lib/cassandra/cluster/metadata.rb +124 -0
- data/lib/cassandra/cluster/options.rb +42 -0
- data/lib/cassandra/cluster/registry.rb +198 -0
- data/lib/cassandra/cluster/schema/partitioners/murmur3.rb +47 -0
- data/lib/cassandra/cluster/schema/partitioners/ordered.rb +37 -0
- data/lib/cassandra/cluster/schema/partitioners/random.rb +37 -0
- data/lib/cassandra/cluster/schema/partitioners.rb +21 -0
- data/lib/cassandra/cluster/schema/replication_strategies/network_topology.rb +92 -0
- data/lib/cassandra/cluster/schema/replication_strategies/none.rb +39 -0
- data/lib/cassandra/cluster/schema/replication_strategies/simple.rb +44 -0
- data/lib/cassandra/cluster/schema/replication_strategies.rb +21 -0
- data/lib/cassandra/cluster/schema/type_parser.rb +138 -0
- data/lib/cassandra/cluster/schema.rb +340 -0
- data/lib/cassandra/cluster.rb +215 -0
- data/lib/cassandra/column.rb +92 -0
- data/lib/cassandra/compression/compressors/lz4.rb +72 -0
- data/lib/cassandra/compression/compressors/snappy.rb +66 -0
- data/lib/cassandra/compression.rb +66 -0
- data/lib/cassandra/driver.rb +111 -0
- data/lib/cassandra/errors.rb +79 -0
- data/lib/cassandra/execution/info.rb +51 -0
- data/lib/cassandra/execution/options.rb +80 -0
- data/lib/cassandra/execution/trace.rb +152 -0
- data/lib/cassandra/future.rb +675 -0
- data/lib/cassandra/host.rb +79 -0
- data/lib/cassandra/keyspace.rb +133 -0
- data/lib/cassandra/listener.rb +87 -0
- data/lib/cassandra/load_balancing/policies/dc_aware_round_robin.rb +149 -0
- data/lib/cassandra/load_balancing/policies/round_robin.rb +132 -0
- data/lib/cassandra/load_balancing/policies/token_aware.rb +119 -0
- data/lib/cassandra/load_balancing/policies/white_list.rb +90 -0
- data/lib/cassandra/load_balancing/policies.rb +19 -0
- data/lib/cassandra/load_balancing.rb +113 -0
- data/lib/cassandra/protocol/cql_byte_buffer.rb +307 -0
- data/lib/cassandra/protocol/cql_protocol_handler.rb +323 -0
- data/lib/cassandra/protocol/frame_decoder.rb +128 -0
- data/lib/cassandra/protocol/frame_encoder.rb +48 -0
- data/lib/cassandra/protocol/request.rb +38 -0
- data/lib/cassandra/protocol/requests/auth_response_request.rb +47 -0
- data/lib/cassandra/protocol/requests/batch_request.rb +76 -0
- data/lib/cassandra/protocol/requests/credentials_request.rb +47 -0
- data/lib/cassandra/protocol/requests/execute_request.rb +103 -0
- data/lib/cassandra/protocol/requests/options_request.rb +39 -0
- data/lib/cassandra/protocol/requests/prepare_request.rb +50 -0
- data/lib/cassandra/protocol/requests/query_request.rb +153 -0
- data/lib/cassandra/protocol/requests/register_request.rb +38 -0
- data/lib/cassandra/protocol/requests/startup_request.rb +49 -0
- data/lib/cassandra/protocol/requests/void_query_request.rb +24 -0
- data/lib/cassandra/protocol/response.rb +38 -0
- data/lib/cassandra/protocol/responses/auth_challenge_response.rb +41 -0
- data/lib/cassandra/protocol/responses/auth_success_response.rb +41 -0
- data/lib/cassandra/protocol/responses/authenticate_response.rb +41 -0
- data/lib/cassandra/protocol/responses/detailed_error_response.rb +60 -0
- data/lib/cassandra/protocol/responses/error_response.rb +50 -0
- data/lib/cassandra/protocol/responses/event_response.rb +39 -0
- data/lib/cassandra/protocol/responses/prepared_result_response.rb +64 -0
- data/lib/cassandra/protocol/responses/raw_rows_result_response.rb +43 -0
- data/lib/cassandra/protocol/responses/ready_response.rb +44 -0
- data/lib/cassandra/protocol/responses/result_response.rb +48 -0
- data/lib/cassandra/protocol/responses/rows_result_response.rb +139 -0
- data/lib/cassandra/protocol/responses/schema_change_event_response.rb +60 -0
- data/lib/cassandra/protocol/responses/schema_change_result_response.rb +57 -0
- data/lib/cassandra/protocol/responses/set_keyspace_result_response.rb +42 -0
- data/lib/cassandra/protocol/responses/status_change_event_response.rb +44 -0
- data/lib/cassandra/protocol/responses/supported_response.rb +41 -0
- data/lib/cassandra/protocol/responses/topology_change_event_response.rb +34 -0
- data/lib/cassandra/protocol/responses/void_result_response.rb +39 -0
- data/lib/cassandra/protocol/type_converter.rb +384 -0
- data/lib/cassandra/protocol.rb +93 -0
- data/lib/cassandra/reconnection/policies/constant.rb +48 -0
- data/lib/cassandra/reconnection/policies/exponential.rb +79 -0
- data/lib/cassandra/reconnection/policies.rb +20 -0
- data/lib/cassandra/reconnection.rb +49 -0
- data/lib/cassandra/result.rb +215 -0
- data/lib/cassandra/retry/policies/default.rb +47 -0
- data/lib/cassandra/retry/policies/downgrading_consistency.rb +71 -0
- data/lib/cassandra/retry/policies/fallthrough.rb +39 -0
- data/lib/cassandra/retry/policies.rb +21 -0
- data/lib/cassandra/retry.rb +142 -0
- data/lib/cassandra/session.rb +202 -0
- data/lib/cassandra/statement.rb +22 -0
- data/lib/cassandra/statements/batch.rb +95 -0
- data/lib/cassandra/statements/bound.rb +48 -0
- data/lib/cassandra/statements/prepared.rb +81 -0
- data/lib/cassandra/statements/simple.rb +58 -0
- data/lib/cassandra/statements/void.rb +33 -0
- data/lib/cassandra/statements.rb +23 -0
- data/lib/cassandra/table.rb +299 -0
- data/lib/cassandra/time_uuid.rb +142 -0
- data/lib/cassandra/util.rb +167 -0
- data/lib/cassandra/uuid.rb +104 -0
- data/lib/cassandra/version.rb +21 -0
- data/lib/cassandra.rb +428 -0
- data/lib/cassandra_murmur3.jar +0 -0
- metadata +211 -0
|
@@ -0,0 +1,49 @@
|
|
|
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 Reconnection
|
|
21
|
+
# Reconnection schedule
|
|
22
|
+
# @abstract Actual reconnection schedules returned from
|
|
23
|
+
# {Cassandra::Reconnection::Policy} implementation don't need to inherit
|
|
24
|
+
# this class. This class exists for documentation purposes only.
|
|
25
|
+
class Schedule
|
|
26
|
+
# @return [Numeric] the next reconnection interval in seconds
|
|
27
|
+
def next
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# A reconnection policy
|
|
32
|
+
# @abstract Actual reconnection policies supplied as `:reconnection_policy`
|
|
33
|
+
# option to {Cassandra.connect} don't need to inherit this class, only
|
|
34
|
+
# implement its methods. This class exists for documentation purposes
|
|
35
|
+
# only.
|
|
36
|
+
class Policy
|
|
37
|
+
# Returns a reconnection schedule
|
|
38
|
+
#
|
|
39
|
+
# @note Reconnection schedule returned from this method doesn't need to
|
|
40
|
+
# extend {Cassandra::Reconnection::Schedule}, only conform to its
|
|
41
|
+
# interface.
|
|
42
|
+
# @return [Cassandra::Reconnection::Schedule] reconnection schedule
|
|
43
|
+
def schedule
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
require 'cassandra/reconnection/policies'
|
|
@@ -0,0 +1,215 @@
|
|
|
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
|
+
class Result
|
|
21
|
+
include Enumerable
|
|
22
|
+
|
|
23
|
+
# Query execution information, such as number of retries and all tried hosts, etc.
|
|
24
|
+
# @return [Cassandra::Execution::Info]
|
|
25
|
+
def execution_info
|
|
26
|
+
@info ||= Execution::Info.new(@keyspace, @statement, @options, @hosts, @consistency, @retries, @trace_id ? Execution::Trace.new(@trace_id, @client) : nil)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# @return [Boolean] whether it has any rows
|
|
30
|
+
def empty?
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# @return [Integer] rows count
|
|
34
|
+
def size
|
|
35
|
+
end
|
|
36
|
+
alias :length :size
|
|
37
|
+
|
|
38
|
+
# @yieldparam row [Hash] current row
|
|
39
|
+
# @return [Enumerator, self] returns Enumerator if no block given
|
|
40
|
+
def each
|
|
41
|
+
end
|
|
42
|
+
alias :rows :each
|
|
43
|
+
alias :each_row :each
|
|
44
|
+
|
|
45
|
+
# @return [Boolean] whether no more pages are available
|
|
46
|
+
def last_page?
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Loads next page synchronously
|
|
50
|
+
#
|
|
51
|
+
# @param options [Hash] additional options, just like the ones for
|
|
52
|
+
# {Cassandra::Session#execute}
|
|
53
|
+
#
|
|
54
|
+
# @return [Cassandra::Result, nil] returns `nil` if last page
|
|
55
|
+
#
|
|
56
|
+
# @see Cassandra::Session#execute
|
|
57
|
+
def next_page(options = nil)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Loads next page asynchronously
|
|
61
|
+
#
|
|
62
|
+
# @param options [Hash] additional options, just like the ones for
|
|
63
|
+
# {Cassandra::Session#execute_async}
|
|
64
|
+
#
|
|
65
|
+
# @return [Cassandra::Future<Cassandra::Result, nil>] `nil` if last
|
|
66
|
+
# page
|
|
67
|
+
#
|
|
68
|
+
# @see Cassandra::Session#execute
|
|
69
|
+
def next_page_async(options = nil)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# @private
|
|
74
|
+
module Results
|
|
75
|
+
class Paged < Result
|
|
76
|
+
def initialize(rows, paging_state, trace_id, keyspace, statement, options, hosts, consistency, retries, client, futures_factory)
|
|
77
|
+
@rows = rows
|
|
78
|
+
@paging_state = paging_state
|
|
79
|
+
@trace_id = trace_id
|
|
80
|
+
@keyspace = keyspace
|
|
81
|
+
@statement = statement
|
|
82
|
+
@options = options
|
|
83
|
+
@hosts = hosts
|
|
84
|
+
@consistency = consistency
|
|
85
|
+
@retries = retries
|
|
86
|
+
@client = client
|
|
87
|
+
@futures = futures_factory
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# Returns whether or not there are any rows in this result set
|
|
91
|
+
def empty?
|
|
92
|
+
@rows.empty?
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# Returns count of underlying rows
|
|
96
|
+
def size
|
|
97
|
+
@rows.size
|
|
98
|
+
end
|
|
99
|
+
alias :length :size
|
|
100
|
+
|
|
101
|
+
def each(&block)
|
|
102
|
+
if block_given?
|
|
103
|
+
@rows.each(&block)
|
|
104
|
+
self
|
|
105
|
+
else
|
|
106
|
+
@rows.each
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
alias :rows :each
|
|
110
|
+
alias :each_row :each
|
|
111
|
+
|
|
112
|
+
# Returns true when there are no more pages to load.
|
|
113
|
+
def last_page?
|
|
114
|
+
@paging_state.nil?
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Returns the next page or nil when there is no next page.
|
|
118
|
+
#
|
|
119
|
+
# @return [Cassandra::Result]
|
|
120
|
+
def next_page(options = nil)
|
|
121
|
+
next_page_async(options).get
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def next_page_async(options = nil)
|
|
125
|
+
return @futures.value(nil) if @paging_state.nil?
|
|
126
|
+
|
|
127
|
+
options = options ? @options.override(options) : @options
|
|
128
|
+
|
|
129
|
+
if @statement.is_a?(Statements::Simple)
|
|
130
|
+
@client.query(@statement, options, @paging_state)
|
|
131
|
+
else
|
|
132
|
+
@client.execute(@statement, options, @paging_state)
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def inspect
|
|
137
|
+
"#<Cassandra::Result:0x#{self.object_id.to_s(16)} @rows=#{@rows.inspect} @last_page=#{@paging_state.nil?}>"
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
class Void < Result
|
|
142
|
+
def initialize(trace_id, keyspace, statement, options, hosts, consistency, retries, client, futures_factory)
|
|
143
|
+
@trace_id = trace_id
|
|
144
|
+
@keyspace = keyspace
|
|
145
|
+
@statement = statement
|
|
146
|
+
@options = options
|
|
147
|
+
@hosts = hosts
|
|
148
|
+
@consistency = consistency
|
|
149
|
+
@retries = retries
|
|
150
|
+
@client = client
|
|
151
|
+
@futures = futures_factory
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
# Returns whether or not there are any rows in this result set
|
|
155
|
+
def empty?
|
|
156
|
+
true
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
# Returns count of underlying rows
|
|
160
|
+
def size
|
|
161
|
+
0
|
|
162
|
+
end
|
|
163
|
+
alias :length :size
|
|
164
|
+
|
|
165
|
+
# Iterates over each row in the result set.
|
|
166
|
+
#
|
|
167
|
+
# @yieldparam row [Hash] each row in the result set as a hash
|
|
168
|
+
# @return [Cassandra::Result]
|
|
169
|
+
def each(&block)
|
|
170
|
+
if block_given?
|
|
171
|
+
NO_ROWS.each(&block)
|
|
172
|
+
self
|
|
173
|
+
else
|
|
174
|
+
NO_ROWS.each
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
alias :rows :each
|
|
178
|
+
alias :each_row :each
|
|
179
|
+
|
|
180
|
+
# Returns true when there are no more pages to load.
|
|
181
|
+
#
|
|
182
|
+
# This is only relevant when you have requested paging of the results with
|
|
183
|
+
# the `:page_size` option to {Cassandra::Client::Client#execute} or
|
|
184
|
+
# {Cassandra::Client::PreparedStatement#execute}.
|
|
185
|
+
#
|
|
186
|
+
# @see Cassandra::Client::Client#execute
|
|
187
|
+
def last_page?
|
|
188
|
+
true
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
# Returns the next page or nil when there is no next page.
|
|
192
|
+
#
|
|
193
|
+
# This is only relevant when you have requested paging of the results with
|
|
194
|
+
# the `:page_size` option to {Cassandra::Client::Client#execute} or
|
|
195
|
+
# {Cassandra::Client::PreparedStatement#execute}.
|
|
196
|
+
#
|
|
197
|
+
# @see Cassandra::Client::Client#execute
|
|
198
|
+
def next_page_async(options = nil)
|
|
199
|
+
@futures.value(nil)
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
def next_page(options = nil)
|
|
203
|
+
nil
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
def inspect
|
|
207
|
+
"#<Cassandra::Result:0x#{self.object_id.to_s(16)} @rows=[] @last_page=true>"
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
private
|
|
211
|
+
|
|
212
|
+
NO_ROWS = [].freeze
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
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 Retry
|
|
21
|
+
module Policies
|
|
22
|
+
class Default
|
|
23
|
+
include Policy
|
|
24
|
+
|
|
25
|
+
def read_timeout(statement, consistency, required, received, retrieved, retries)
|
|
26
|
+
return reraise if retries > 0
|
|
27
|
+
|
|
28
|
+
if received >= required && !retrieved
|
|
29
|
+
try_again(consistency)
|
|
30
|
+
else
|
|
31
|
+
reraise
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def write_timeout(statement, consistency, type, required, received, retries)
|
|
36
|
+
return reraise if retries > 0
|
|
37
|
+
|
|
38
|
+
type == :batch_log ? try_again(consistency) : reraise
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def unavailable(statement, consistency, required, alive, retries)
|
|
42
|
+
reraise
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
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 Retry
|
|
21
|
+
module Policies
|
|
22
|
+
class DowngradingConsistency
|
|
23
|
+
include Policy
|
|
24
|
+
|
|
25
|
+
def read_timeout(statement, consistency, required, received, retrieved, retries)
|
|
26
|
+
return reraise if retries > 0 || SERIAL_CONSISTENCIES.include?(consistency)
|
|
27
|
+
return max_likely_to_work(consistency, required, received) if received < required
|
|
28
|
+
|
|
29
|
+
retrieved ? reraise : try_again(consistency)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def write_timeout(statement, consistency, type, required, received, retries)
|
|
33
|
+
return reraise if retries > 0
|
|
34
|
+
|
|
35
|
+
case type
|
|
36
|
+
when :simple, :batch
|
|
37
|
+
ignore
|
|
38
|
+
when :unlogged_batch
|
|
39
|
+
max_likely_to_work(consistency, required, received)
|
|
40
|
+
when :batch_log
|
|
41
|
+
try_again(consistency)
|
|
42
|
+
else
|
|
43
|
+
reraise
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def unavailable(statement, consistency, required, alive, retries)
|
|
48
|
+
return reraise if retries > 0
|
|
49
|
+
|
|
50
|
+
max_likely_to_work(consistency, required, alive)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
private
|
|
54
|
+
|
|
55
|
+
def max_likely_to_work(consistency, required, received)
|
|
56
|
+
if consistency == :all && required > 1 && received >= (required.to_f / 2).floor + 1
|
|
57
|
+
try_again(:quorum)
|
|
58
|
+
elsif received >= 3
|
|
59
|
+
try_again(:three)
|
|
60
|
+
elsif received >= 2
|
|
61
|
+
try_again(:two)
|
|
62
|
+
elsif received >= 1
|
|
63
|
+
try_again(:one)
|
|
64
|
+
else
|
|
65
|
+
reraise
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
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 Retry
|
|
21
|
+
module Policies
|
|
22
|
+
class Fallthrough
|
|
23
|
+
include Policy
|
|
24
|
+
|
|
25
|
+
def read_timeout(statement, consistency, required, received, retrieved, retries)
|
|
26
|
+
reraise
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def write_timeout(statement, consistency, type, required, received, retries)
|
|
30
|
+
reraise
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def unavailable(statement, consistency, required, alive, retries)
|
|
34
|
+
reraise
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
require 'cassandra/retry/policies/default'
|
|
20
|
+
require 'cassandra/retry/policies/downgrading_consistency'
|
|
21
|
+
require 'cassandra/retry/policies/fallthrough'
|
|
@@ -0,0 +1,142 @@
|
|
|
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 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.
|
|
24
|
+
module Policy
|
|
25
|
+
# Decides wether to retry a read and at what consistency level.
|
|
26
|
+
#
|
|
27
|
+
# @note this method may be called even if required_responses >= received
|
|
28
|
+
# responses if data_present is false.
|
|
29
|
+
#
|
|
30
|
+
# @param statement [Cassandra::Statement] the original statement that timed out
|
|
31
|
+
# @param consistency [Symbol] the original consistency level for the
|
|
32
|
+
# request, one of {Cassandra::CONSISTENCIES}
|
|
33
|
+
# @param required [Integer] the number of responses required to achieve
|
|
34
|
+
# requested consistency level
|
|
35
|
+
# @param received [Integer] the number of responses received by the time
|
|
36
|
+
# the query timed out
|
|
37
|
+
# @param retrieved [Boolean] whether actual data (as opposed to data
|
|
38
|
+
# checksum) was present in the received responses.
|
|
39
|
+
# @param retries [Integer] the number of retries already performed
|
|
40
|
+
#
|
|
41
|
+
# @return [Cassandra::Policies::Retry::Decision] a retry decision
|
|
42
|
+
#
|
|
43
|
+
# @see Cassandra::Retry::Policy#try_again
|
|
44
|
+
# @see Cassandra::Retry::Policy#reraise
|
|
45
|
+
# @see Cassandra::Retry::Policy#ignore
|
|
46
|
+
def read_timeout(statement, consistency, required, received, retrieved, retries)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Decides wether to retry a write and at what consistency level.
|
|
50
|
+
#
|
|
51
|
+
# @param statement [Cassandra::Statement] the original statement that timed out
|
|
52
|
+
# @param consistency [Symbol] the original consistency level for the
|
|
53
|
+
# request, one of {Cassandra::CONSISTENCIES}
|
|
54
|
+
# @param type [Symbol] One of `:simple`, `:batch`, `:unlogged_batch`,
|
|
55
|
+
# `:counter` or `:batch_log`
|
|
56
|
+
# @param required [Integer] the number of acks required to achieve
|
|
57
|
+
# requested consistency level
|
|
58
|
+
# @param received [Integer] the number of acks received by the time the
|
|
59
|
+
# query timed out
|
|
60
|
+
# @param retries [Integer] the number of retries already performed
|
|
61
|
+
#
|
|
62
|
+
# @return [Cassandra::Policies::Retry::Decision] a retry decision
|
|
63
|
+
#
|
|
64
|
+
# @see Cassandra::Retry::Policy#try_again
|
|
65
|
+
# @see Cassandra::Retry::Policy#reraise
|
|
66
|
+
# @see Cassandra::Retry::Policy#ignore
|
|
67
|
+
def write_timeout(statement, consistency, type, required, received, retries)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Decides wether to retry and at what consistency level on an Unavailable
|
|
71
|
+
# exception.
|
|
72
|
+
#
|
|
73
|
+
# @param statement [Cassandra::Statement] the original Statement that timed out
|
|
74
|
+
# @param consistency [Symbol] the original consistency level for the
|
|
75
|
+
# request, one of {Cassandra::CONSISTENCIES}
|
|
76
|
+
# @param required [Integer] the number of replicas required to achieve
|
|
77
|
+
# requested consistency level
|
|
78
|
+
# @param alive [Integer] the number of replicas received by the time the
|
|
79
|
+
# query timed out
|
|
80
|
+
# @param retries [Integer] the number of retries already performed
|
|
81
|
+
#
|
|
82
|
+
# @return [Cassandra::Policies::Retry::Decision] a retry decision
|
|
83
|
+
#
|
|
84
|
+
# @see Cassandra::Retry::Policy#try_again
|
|
85
|
+
# @see Cassandra::Retry::Policy#reraise
|
|
86
|
+
# @see Cassandra::Retry::Policy#ignore
|
|
87
|
+
def unavailable(statement, consistency, required, alive, retries)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
private
|
|
91
|
+
|
|
92
|
+
# Returns a decision that signals retry at a given consistency
|
|
93
|
+
#
|
|
94
|
+
# @param consistency [Symbol] consistency level for the retry, one of
|
|
95
|
+
# {Cassandra::CONSISTENCIES}
|
|
96
|
+
# @return [Cassandra::Policies::Retry::Decision] tell driver to retry
|
|
97
|
+
def try_again(consistency)
|
|
98
|
+
Decisions::Retry.new(consistency)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# Returns a decision that signals to driver to reraise original error to
|
|
102
|
+
# the application
|
|
103
|
+
#
|
|
104
|
+
# @return [Cassandra::Policies::Retry::Decision] tell driver to reraise
|
|
105
|
+
def reraise
|
|
106
|
+
DECISION_RERAISE
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Returns a decision that signals to driver to ignore the error
|
|
110
|
+
#
|
|
111
|
+
# @return [Cassandra::Policies::Retry::Decision] tell driver to ignore the error
|
|
112
|
+
# and return an empty result to the application
|
|
113
|
+
def ignore
|
|
114
|
+
DECISION_IGNORE
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# @private
|
|
119
|
+
module Decisions
|
|
120
|
+
class Retry
|
|
121
|
+
attr_reader :consistency
|
|
122
|
+
|
|
123
|
+
def initialize(consistency)
|
|
124
|
+
@consistency = consistency
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
class Reraise
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
class Ignore
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# @private
|
|
136
|
+
DECISION_RERAISE = Decisions::Reraise.new
|
|
137
|
+
# @private
|
|
138
|
+
DECISION_IGNORE = Decisions::Ignore.new
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
require 'cassandra/retry/policies'
|