cassandra-driver 0.1.0.alpha1 → 1.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. data/.yardopts +4 -0
  2. data/README.md +117 -0
  3. data/lib/cassandra.rb +320 -0
  4. data/lib/cassandra/auth.rb +97 -0
  5. data/lib/cassandra/auth/providers.rb +16 -0
  6. data/lib/cassandra/auth/providers/password.rb +73 -0
  7. data/lib/cassandra/client.rb +144 -0
  8. data/lib/cassandra/client/batch.rb +212 -0
  9. data/lib/cassandra/client/client.rb +591 -0
  10. data/lib/cassandra/client/column_metadata.rb +54 -0
  11. data/lib/cassandra/client/connection_manager.rb +72 -0
  12. data/lib/cassandra/client/connector.rb +272 -0
  13. data/lib/cassandra/client/execute_options_decoder.rb +59 -0
  14. data/lib/cassandra/client/null_logger.rb +37 -0
  15. data/lib/cassandra/client/peer_discovery.rb +50 -0
  16. data/lib/cassandra/client/prepared_statement.rb +314 -0
  17. data/lib/cassandra/client/query_result.rb +230 -0
  18. data/lib/cassandra/client/request_runner.rb +71 -0
  19. data/lib/cassandra/client/result_metadata.rb +48 -0
  20. data/lib/cassandra/client/void_result.rb +78 -0
  21. data/lib/cassandra/cluster.rb +191 -0
  22. data/lib/cassandra/cluster/client.rb +767 -0
  23. data/lib/cassandra/cluster/connector.rb +231 -0
  24. data/lib/cassandra/cluster/control_connection.rb +420 -0
  25. data/lib/cassandra/cluster/options.rb +40 -0
  26. data/lib/cassandra/cluster/registry.rb +181 -0
  27. data/lib/cassandra/cluster/schema.rb +321 -0
  28. data/lib/cassandra/cluster/schema/type_parser.rb +138 -0
  29. data/lib/cassandra/column.rb +92 -0
  30. data/lib/cassandra/compression.rb +66 -0
  31. data/lib/cassandra/compression/compressors/lz4.rb +72 -0
  32. data/lib/cassandra/compression/compressors/snappy.rb +66 -0
  33. data/lib/cassandra/driver.rb +86 -0
  34. data/lib/cassandra/errors.rb +79 -0
  35. data/lib/cassandra/execution/info.rb +51 -0
  36. data/lib/cassandra/execution/options.rb +77 -0
  37. data/lib/cassandra/execution/trace.rb +152 -0
  38. data/lib/cassandra/future.rb +675 -0
  39. data/lib/cassandra/host.rb +75 -0
  40. data/lib/cassandra/keyspace.rb +120 -0
  41. data/lib/cassandra/listener.rb +87 -0
  42. data/lib/cassandra/load_balancing.rb +112 -0
  43. data/lib/cassandra/load_balancing/policies.rb +18 -0
  44. data/lib/cassandra/load_balancing/policies/dc_aware_round_robin.rb +149 -0
  45. data/lib/cassandra/load_balancing/policies/round_robin.rb +95 -0
  46. data/lib/cassandra/load_balancing/policies/white_list.rb +90 -0
  47. data/lib/cassandra/protocol.rb +93 -0
  48. data/lib/cassandra/protocol/cql_byte_buffer.rb +307 -0
  49. data/lib/cassandra/protocol/cql_protocol_handler.rb +323 -0
  50. data/lib/cassandra/protocol/frame_decoder.rb +128 -0
  51. data/lib/cassandra/protocol/frame_encoder.rb +48 -0
  52. data/lib/cassandra/protocol/request.rb +38 -0
  53. data/lib/cassandra/protocol/requests/auth_response_request.rb +47 -0
  54. data/lib/cassandra/protocol/requests/batch_request.rb +76 -0
  55. data/lib/cassandra/protocol/requests/credentials_request.rb +47 -0
  56. data/lib/cassandra/protocol/requests/execute_request.rb +103 -0
  57. data/lib/cassandra/protocol/requests/options_request.rb +39 -0
  58. data/lib/cassandra/protocol/requests/prepare_request.rb +50 -0
  59. data/lib/cassandra/protocol/requests/query_request.rb +153 -0
  60. data/lib/cassandra/protocol/requests/register_request.rb +38 -0
  61. data/lib/cassandra/protocol/requests/startup_request.rb +49 -0
  62. data/lib/cassandra/protocol/requests/void_query_request.rb +24 -0
  63. data/lib/cassandra/protocol/response.rb +38 -0
  64. data/lib/cassandra/protocol/responses/auth_challenge_response.rb +41 -0
  65. data/lib/cassandra/protocol/responses/auth_success_response.rb +41 -0
  66. data/lib/cassandra/protocol/responses/authenticate_response.rb +41 -0
  67. data/lib/cassandra/protocol/responses/detailed_error_response.rb +60 -0
  68. data/lib/cassandra/protocol/responses/error_response.rb +50 -0
  69. data/lib/cassandra/protocol/responses/event_response.rb +39 -0
  70. data/lib/cassandra/protocol/responses/prepared_result_response.rb +64 -0
  71. data/lib/cassandra/protocol/responses/raw_rows_result_response.rb +43 -0
  72. data/lib/cassandra/protocol/responses/ready_response.rb +44 -0
  73. data/lib/cassandra/protocol/responses/result_response.rb +48 -0
  74. data/lib/cassandra/protocol/responses/rows_result_response.rb +139 -0
  75. data/lib/cassandra/protocol/responses/schema_change_event_response.rb +60 -0
  76. data/lib/cassandra/protocol/responses/schema_change_result_response.rb +57 -0
  77. data/lib/cassandra/protocol/responses/set_keyspace_result_response.rb +42 -0
  78. data/lib/cassandra/protocol/responses/status_change_event_response.rb +44 -0
  79. data/lib/cassandra/protocol/responses/supported_response.rb +41 -0
  80. data/lib/cassandra/protocol/responses/topology_change_event_response.rb +34 -0
  81. data/lib/cassandra/protocol/responses/void_result_response.rb +39 -0
  82. data/lib/cassandra/protocol/type_converter.rb +384 -0
  83. data/lib/cassandra/reconnection.rb +49 -0
  84. data/lib/cassandra/reconnection/policies.rb +20 -0
  85. data/lib/cassandra/reconnection/policies/constant.rb +48 -0
  86. data/lib/cassandra/reconnection/policies/exponential.rb +79 -0
  87. data/lib/cassandra/result.rb +215 -0
  88. data/lib/cassandra/retry.rb +142 -0
  89. data/lib/cassandra/retry/policies.rb +21 -0
  90. data/lib/cassandra/retry/policies/default.rb +47 -0
  91. data/lib/cassandra/retry/policies/downgrading_consistency.rb +71 -0
  92. data/lib/cassandra/retry/policies/fallthrough.rb +39 -0
  93. data/lib/cassandra/session.rb +195 -0
  94. data/lib/cassandra/statement.rb +22 -0
  95. data/lib/cassandra/statements.rb +23 -0
  96. data/lib/cassandra/statements/batch.rb +95 -0
  97. data/lib/cassandra/statements/bound.rb +46 -0
  98. data/lib/cassandra/statements/prepared.rb +59 -0
  99. data/lib/cassandra/statements/simple.rb +58 -0
  100. data/lib/cassandra/statements/void.rb +33 -0
  101. data/lib/cassandra/table.rb +254 -0
  102. data/lib/cassandra/time_uuid.rb +141 -0
  103. data/lib/cassandra/util.rb +169 -0
  104. data/lib/cassandra/uuid.rb +104 -0
  105. data/lib/cassandra/version.rb +17 -1
  106. metadata +134 -8
@@ -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
+ # @note 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
+ # @note 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
+ # @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
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,20 @@
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/reconnection/policies/constant'
20
+ require 'cassandra/reconnection/policies/exponential'
@@ -0,0 +1,48 @@
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
+ module Policies
22
+ # A reconnection policy that returns a constant reconnection interval
23
+ class Constant < Policy
24
+ # @private
25
+ class Schedule
26
+ def initialize(interval)
27
+ @interval = interval
28
+ end
29
+
30
+ def next
31
+ @interval
32
+ end
33
+ end
34
+
35
+ # @param interval [Numeric] reconnection interval (in seconds)
36
+ def initialize(interval)
37
+ @schedule = Schedule.new(Float(interval))
38
+ end
39
+
40
+ # @return [Cassandra::Reconnection::Schedule] reconnection schedule
41
+ # with constant interval
42
+ def schedule
43
+ @schedule
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,79 @@
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
+ module Policies
22
+ # A reconnection policy that returns a constant exponentially growing
23
+ # reconnection interval up to a given maximum
24
+ class Exponential < Policy
25
+ # @private
26
+ class Schedule
27
+ def initialize(start, max, exponent)
28
+ @interval = start
29
+ @max = max
30
+ @exponent = exponent
31
+ end
32
+
33
+ def next
34
+ @interval.tap { backoff if @interval < @max }
35
+ end
36
+
37
+ private
38
+
39
+ def backoff
40
+ new_interval = @interval * @exponent
41
+
42
+ if new_interval >= @max
43
+ @interval = @max
44
+ else
45
+ @interval = new_interval
46
+ end
47
+ end
48
+ end
49
+
50
+ # @param start [Numeric] beginning interval
51
+ # @param max [Numeric] maximum reconnection interval
52
+ # @param exponent [Numeric] (2) interval exponent to use
53
+ #
54
+ # @example Using this policy
55
+ # policy = Cassandra::Reconnection::Policies::Exponential.new(0.5, 10, 2)
56
+ # schedule = policy.schedule
57
+ # schedule.next # 0.5
58
+ # schedule.next # 1.0
59
+ # schedule.next # 2.0
60
+ # schedule.next # 4.0
61
+ # schedule.next # 8.0
62
+ # schedule.next # 10.0
63
+ # schedule.next # 10.0
64
+ # schedule.next # 10.0
65
+ def initialize(start, max, exponent = 2)
66
+ @start = start
67
+ @max = max
68
+ @exponent = exponent
69
+ end
70
+
71
+ # @return [Cassandra::Reconnection::Schedule] an exponential
72
+ # reconnection schedule
73
+ def schedule
74
+ Schedule.new(@start, @max, @exponent)
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -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,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
+ module Policy
22
+ # Decides wether to retry a read and at what consistency level.
23
+ #
24
+ # @note this method may be called even if required_responses >= received
25
+ # responses if data_present is false.
26
+ #
27
+ # @param statement [Cassandra::Statement] the original statement that timed out
28
+ # @param consistency [Symbol] the original consistency level for the
29
+ # request, one of {Cassandra::CONSISTENCIES}
30
+ # @param required [Integer] the number of responses required to achieve
31
+ # requested consistency level
32
+ # @param received [Integer] the number of responses received by the time
33
+ # the query timed out
34
+ # @param retrieved [Boolean] whether actual data (as opposed to data
35
+ # checksum) was present in the received responses.
36
+ # @param retries [Integer] the number of retries already performed
37
+ #
38
+ # @abstract implementation should be provided by an actual policy
39
+ # @return [Cassandra::Policies::Retry::Decision] a retry decision
40
+ #
41
+ # @see Cassandra::Retry::Policy#try_again
42
+ # @see Cassandra::Retry::Policy#reraise
43
+ # @see Cassandra::Retry::Policy#ignore
44
+ def read_timeout(statement, consistency, required, received, retrieved, retries)
45
+ end
46
+
47
+ # Decides wether to retry a write and at what consistency level.
48
+ #
49
+ # @param statement [Cassandra::Statement] the original statement that timed out
50
+ # @param consistency [Symbol] the original consistency level for the
51
+ # request, one of {Cassandra::CONSISTENCIES}
52
+ # @param type [Symbol] One of `:simple`, `:batch`, `:unlogged_batch`,
53
+ # `:counter` or `:batch_log`
54
+ # @param required [Integer] the number of acks required to achieve
55
+ # requested consistency level
56
+ # @param received [Integer] the number of acks received by the time the
57
+ # query timed out
58
+ # @param retries [Integer] the number of retries already performed
59
+ #
60
+ # @abstract implementation should be provided by an actual policy
61
+ # @return [Cassandra::Policies::Retry::Decision] a retry decision
62
+ #
63
+ # @see Cassandra::Retry::Policy#try_again
64
+ # @see Cassandra::Retry::Policy#reraise
65
+ # @see Cassandra::Retry::Policy#ignore
66
+ def write_timeout(statement, consistency, type, required, received, retries)
67
+ end
68
+
69
+ # Decides wether to retry and at what consistency level on an Unavailable
70
+ # exception.
71
+ #
72
+ # @param statement [Cassandra::Statement] the original Statement that timed out
73
+ # @param consistency [Symbol] the original consistency level for the
74
+ # request, one of {Cassandra::CONSISTENCIES}
75
+ # @param required [Integer] the number of replicas required to achieve
76
+ # requested consistency level
77
+ # @param alive [Integer] the number of replicas received by the time the
78
+ # query timed out
79
+ # @param retries [Integer] the number of retries already performed
80
+ #
81
+ # @abstract implementation should be provided by an actual policy
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'