cassandra-driver 3.0.0.beta.1 → 3.0.0.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +90 -38
- data/ext/cassandra_murmur3/cassandra_murmur3.c +1 -1
- data/lib/cassandra.rb +327 -130
- data/lib/cassandra/address_resolution.rb +1 -1
- data/lib/cassandra/address_resolution/policies/ec2_multi_region.rb +1 -1
- data/lib/cassandra/address_resolution/policies/none.rb +1 -1
- data/lib/cassandra/aggregate.rb +21 -7
- data/lib/cassandra/argument.rb +2 -2
- data/lib/cassandra/auth.rb +4 -4
- data/lib/cassandra/auth/providers.rb +1 -1
- data/lib/cassandra/auth/providers/password.rb +9 -5
- data/lib/cassandra/cassandra_logger.rb +80 -0
- data/lib/cassandra/cluster.rb +38 -9
- data/lib/cassandra/cluster/client.rb +801 -205
- data/lib/cassandra/cluster/connection_pool.rb +2 -2
- data/lib/cassandra/cluster/connector.rb +74 -25
- data/lib/cassandra/cluster/control_connection.rb +217 -82
- data/lib/cassandra/cluster/failed_connection.rb +1 -1
- data/lib/cassandra/cluster/metadata.rb +12 -4
- data/lib/cassandra/cluster/options.rb +60 -11
- data/lib/cassandra/cluster/registry.rb +69 -16
- data/lib/cassandra/cluster/schema.rb +25 -7
- data/lib/cassandra/cluster/schema/cql_type_parser.rb +15 -10
- data/lib/cassandra/cluster/schema/fetchers.rb +263 -106
- data/lib/cassandra/cluster/schema/fqcn_type_parser.rb +41 -36
- data/lib/cassandra/cluster/schema/partitioners.rb +1 -1
- data/lib/cassandra/cluster/schema/partitioners/murmur3.rb +3 -3
- data/lib/cassandra/cluster/schema/partitioners/ordered.rb +1 -1
- data/lib/cassandra/cluster/schema/partitioners/random.rb +1 -1
- data/lib/cassandra/cluster/schema/replication_strategies.rb +1 -1
- data/lib/cassandra/cluster/schema/replication_strategies/network_topology.rb +19 -18
- data/lib/cassandra/cluster/schema/replication_strategies/none.rb +1 -1
- data/lib/cassandra/cluster/schema/replication_strategies/simple.rb +1 -1
- data/lib/cassandra/column.rb +3 -3
- data/lib/cassandra/compression.rb +1 -1
- data/lib/cassandra/compression/compressors/lz4.rb +4 -3
- data/lib/cassandra/compression/compressors/snappy.rb +4 -3
- data/lib/cassandra/driver.rb +103 -41
- data/lib/cassandra/errors.rb +265 -30
- data/lib/cassandra/execution/info.rb +16 -5
- data/lib/cassandra/execution/options.rb +99 -54
- data/lib/cassandra/execution/trace.rb +16 -9
- data/lib/cassandra/executors.rb +1 -1
- data/lib/cassandra/function.rb +19 -13
- data/lib/cassandra/function_collection.rb +85 -0
- data/lib/cassandra/future.rb +106 -48
- data/lib/cassandra/host.rb +10 -4
- data/lib/cassandra/keyspace.rb +90 -33
- data/lib/cassandra/listener.rb +1 -1
- data/lib/cassandra/load_balancing.rb +2 -2
- data/lib/cassandra/load_balancing/policies.rb +1 -1
- data/lib/cassandra/load_balancing/policies/dc_aware_round_robin.rb +18 -18
- data/lib/cassandra/load_balancing/policies/round_robin.rb +1 -1
- data/lib/cassandra/load_balancing/policies/token_aware.rb +15 -13
- data/lib/cassandra/load_balancing/policies/white_list.rb +11 -5
- data/lib/cassandra/null_logger.rb +27 -6
- data/lib/cassandra/protocol.rb +1 -1
- data/lib/cassandra/protocol/coder.rb +78 -39
- data/lib/cassandra/protocol/cql_byte_buffer.rb +50 -33
- data/lib/cassandra/protocol/cql_protocol_handler.rb +44 -45
- data/lib/cassandra/protocol/request.rb +2 -2
- data/lib/cassandra/protocol/requests/auth_response_request.rb +3 -3
- data/lib/cassandra/protocol/requests/batch_request.rb +16 -7
- data/lib/cassandra/protocol/requests/credentials_request.rb +3 -3
- data/lib/cassandra/protocol/requests/execute_request.rb +41 -20
- data/lib/cassandra/protocol/requests/options_request.rb +1 -1
- data/lib/cassandra/protocol/requests/prepare_request.rb +5 -5
- data/lib/cassandra/protocol/requests/query_request.rb +27 -22
- data/lib/cassandra/protocol/requests/register_request.rb +2 -2
- data/lib/cassandra/protocol/requests/startup_request.rb +6 -4
- data/lib/cassandra/protocol/requests/void_query_request.rb +1 -1
- data/lib/cassandra/protocol/response.rb +2 -2
- data/lib/cassandra/protocol/responses/already_exists_error_response.rb +12 -2
- data/lib/cassandra/protocol/responses/auth_challenge_response.rb +1 -1
- data/lib/cassandra/protocol/responses/auth_success_response.rb +1 -1
- data/lib/cassandra/protocol/responses/authenticate_response.rb +1 -1
- data/lib/cassandra/protocol/responses/error_response.rb +101 -13
- data/lib/cassandra/protocol/responses/event_response.rb +1 -1
- data/lib/cassandra/protocol/responses/function_failure_error_response.rb +13 -2
- data/lib/cassandra/protocol/responses/prepared_result_response.rb +11 -5
- data/lib/cassandra/protocol/responses/raw_rows_result_response.rb +14 -9
- data/lib/cassandra/protocol/responses/read_failure_error_response.rb +26 -4
- data/lib/cassandra/protocol/responses/read_timeout_error_response.rb +22 -3
- data/lib/cassandra/protocol/responses/ready_response.rb +3 -3
- data/lib/cassandra/protocol/responses/result_response.rb +4 -2
- data/lib/cassandra/protocol/responses/rows_result_response.rb +5 -3
- data/lib/cassandra/protocol/responses/schema_change_event_response.rb +5 -4
- data/lib/cassandra/protocol/responses/schema_change_result_response.rb +16 -9
- data/lib/cassandra/protocol/responses/set_keyspace_result_response.rb +2 -2
- data/lib/cassandra/protocol/responses/status_change_event_response.rb +2 -2
- data/lib/cassandra/protocol/responses/supported_response.rb +1 -1
- data/lib/cassandra/protocol/responses/topology_change_event_response.rb +1 -1
- data/lib/cassandra/protocol/responses/unavailable_error_response.rb +20 -3
- data/lib/cassandra/protocol/responses/unprepared_error_response.rb +11 -2
- data/lib/cassandra/protocol/responses/void_result_response.rb +1 -1
- data/lib/cassandra/protocol/responses/write_failure_error_response.rb +26 -4
- data/lib/cassandra/protocol/responses/write_timeout_error_response.rb +22 -3
- data/lib/cassandra/protocol/v1.rb +101 -36
- data/lib/cassandra/protocol/v3.rb +124 -51
- data/lib/cassandra/protocol/v4.rb +172 -68
- data/lib/cassandra/reconnection.rb +1 -1
- data/lib/cassandra/reconnection/policies.rb +1 -1
- data/lib/cassandra/reconnection/policies/constant.rb +2 -4
- data/lib/cassandra/reconnection/policies/exponential.rb +6 -6
- data/lib/cassandra/result.rb +53 -19
- data/lib/cassandra/retry.rb +8 -8
- data/lib/cassandra/retry/policies.rb +1 -1
- data/lib/cassandra/retry/policies/default.rb +1 -1
- data/lib/cassandra/retry/policies/downgrading_consistency.rb +7 -3
- data/lib/cassandra/retry/policies/fallthrough.rb +1 -1
- data/lib/cassandra/session.rb +22 -16
- data/lib/cassandra/statement.rb +1 -1
- data/lib/cassandra/statements.rb +1 -1
- data/lib/cassandra/statements/batch.rb +16 -10
- data/lib/cassandra/statements/bound.rb +10 -3
- data/lib/cassandra/statements/prepared.rb +59 -15
- data/lib/cassandra/statements/simple.rb +23 -10
- data/lib/cassandra/statements/void.rb +1 -1
- data/lib/cassandra/table.rb +79 -30
- data/lib/cassandra/time.rb +11 -6
- data/lib/cassandra/time_uuid.rb +7 -7
- data/lib/cassandra/tuple.rb +16 -8
- data/lib/cassandra/types.rb +20 -9
- data/lib/cassandra/udt.rb +32 -36
- data/lib/cassandra/util.rb +20 -13
- data/lib/cassandra/uuid.rb +22 -15
- data/lib/cassandra/uuid/generator.rb +7 -5
- data/lib/cassandra/version.rb +2 -2
- data/lib/datastax/cassandra.rb +1 -1
- metadata +5 -3
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
#--
|
4
|
-
# Copyright 2013-
|
4
|
+
# Copyright 2013-2016 DataStax, Inc.
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
# you may not use this file except in compliance with the License.
|
@@ -46,7 +46,7 @@ module Cassandra
|
|
46
46
|
body = @compressor.compress(body)
|
47
47
|
end
|
48
48
|
|
49
|
-
header
|
49
|
+
header = [@protocol_version, flags, stream_id, request.opcode, body.bytesize]
|
50
50
|
buffer << header.pack(HEADER_FORMAT)
|
51
51
|
buffer << body
|
52
52
|
|
@@ -90,7 +90,9 @@ module Cassandra
|
|
90
90
|
stream_id = (frame_header >> 8) & 0xff
|
91
91
|
stream_id = (stream_id & 0x7f) - (stream_id & 0x80)
|
92
92
|
|
93
|
-
|
93
|
+
error_response = ErrorResponse.new(nil, nil, 0x000A,
|
94
|
+
'Invalid or unsupported protocol version')
|
95
|
+
@handler.complete_request(stream_id, error_response)
|
94
96
|
|
95
97
|
return
|
96
98
|
end
|
@@ -159,7 +161,7 @@ module Cassandra
|
|
159
161
|
nil
|
160
162
|
end
|
161
163
|
|
162
|
-
def actual_decode(buffer, fields,
|
164
|
+
def actual_decode(buffer, fields, frame_length, code)
|
163
165
|
protocol_version = (fields >> 24) & 0x7f
|
164
166
|
compression = ((fields >> 16) & 0x01) == 0x01
|
165
167
|
tracing = ((fields >> 16) & 0x02) == 0x02
|
@@ -169,42 +171,45 @@ module Cassandra
|
|
169
171
|
stream_id = (stream_id & 0x7fff) - (stream_id & 0x8000)
|
170
172
|
opcode = code & 0xff
|
171
173
|
|
174
|
+
# If we're dealing with a compressed body, read the whole body, decompress,
|
175
|
+
# and treat the uncompressed body as if that's what we got in the first place.
|
176
|
+
# This means, reset frame_length to that uncompressed size.
|
172
177
|
if compression
|
173
178
|
if @compressor
|
174
|
-
buffer = CqlByteBuffer.new(
|
175
|
-
|
179
|
+
buffer = CqlByteBuffer.new(
|
180
|
+
@compressor.decompress(buffer.read(frame_length)))
|
181
|
+
frame_length = buffer.size
|
176
182
|
else
|
177
|
-
raise Errors::DecodingError,
|
183
|
+
raise Errors::DecodingError,
|
184
|
+
'Compressed frame received, but no compressor configured'
|
178
185
|
end
|
179
186
|
end
|
180
187
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
188
|
+
# We want to read one full frame; but after we read/parse chunks of the body
|
189
|
+
# there may be more cruft left in the frame that we don't care about. So,
|
190
|
+
# we save off the current size of the buffer, do all our reads for the
|
191
|
+
# frame, get the final remaining size, and based on that discard possible
|
192
|
+
# remaining bytes in the frame. In particular, we account for the possibility
|
193
|
+
# that the buffer contains some/all of a subsequent frame as well, and we
|
194
|
+
# don't want to mess with that.
|
187
195
|
|
188
|
-
|
189
|
-
custom_payload = buffer.read_bytes_map.freeze
|
190
|
-
size = buffer.size
|
191
|
-
else
|
192
|
-
custom_payload = nil
|
193
|
-
end
|
196
|
+
buffer_starting_length = buffer.length
|
194
197
|
|
195
|
-
if
|
196
|
-
warnings = buffer.read_string_list
|
197
|
-
size = buffer.size
|
198
|
-
else
|
199
|
-
warnings = nil
|
200
|
-
end
|
198
|
+
trace_id = (buffer.read_uuid if tracing)
|
201
199
|
|
202
|
-
|
203
|
-
response = decode_response(opcode, protocol_version, buffer, size, trace_id, custom_payload, warnings)
|
200
|
+
warnings = (buffer.read_string_list if warning)
|
204
201
|
|
205
|
-
|
206
|
-
|
207
|
-
|
202
|
+
custom_payload = (buffer.read_bytes_map.freeze if payload)
|
203
|
+
|
204
|
+
remaining_frame_length = frame_length -
|
205
|
+
(buffer_starting_length - buffer.length)
|
206
|
+
response = decode_response(opcode, protocol_version, buffer,
|
207
|
+
remaining_frame_length, trace_id, custom_payload,
|
208
|
+
warnings)
|
209
|
+
|
210
|
+
# Calculate and discard remaining cruft in the frame.
|
211
|
+
extra_length = frame_length - (buffer_starting_length - buffer.length)
|
212
|
+
buffer.discard(extra_length) if extra_length > 0
|
208
213
|
|
209
214
|
if stream_id == -1
|
210
215
|
@handler.notify_event_listeners(response)
|
@@ -213,21 +218,86 @@ module Cassandra
|
|
213
218
|
end
|
214
219
|
end
|
215
220
|
|
216
|
-
def decode_response(opcode,
|
221
|
+
def decode_response(opcode,
|
222
|
+
protocol_version,
|
223
|
+
buffer,
|
224
|
+
size,
|
225
|
+
trace_id,
|
226
|
+
custom_payload,
|
227
|
+
warnings)
|
217
228
|
case opcode
|
218
229
|
when 0x00 # ERROR
|
219
|
-
code
|
230
|
+
code = buffer.read_int
|
220
231
|
message = buffer.read_string
|
221
232
|
|
222
233
|
case code
|
223
|
-
when 0x1000
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
234
|
+
when 0x1000
|
235
|
+
UnavailableErrorResponse.new(custom_payload,
|
236
|
+
warnings,
|
237
|
+
code,
|
238
|
+
message,
|
239
|
+
buffer.read_consistency,
|
240
|
+
buffer.read_int,
|
241
|
+
buffer.read_int)
|
242
|
+
when 0x1100
|
243
|
+
WriteTimeoutErrorResponse.new(custom_payload,
|
244
|
+
warnings,
|
245
|
+
code,
|
246
|
+
message,
|
247
|
+
buffer.read_consistency,
|
248
|
+
buffer.read_int,
|
249
|
+
buffer.read_int,
|
250
|
+
buffer.read_string)
|
251
|
+
when 0x1200
|
252
|
+
ReadTimeoutErrorResponse.new(custom_payload,
|
253
|
+
warnings,
|
254
|
+
code,
|
255
|
+
message,
|
256
|
+
buffer.read_consistency,
|
257
|
+
buffer.read_int,
|
258
|
+
buffer.read_int,
|
259
|
+
(buffer.read_byte != 0))
|
260
|
+
when 0x1300
|
261
|
+
ReadFailureErrorResponse.new(custom_payload,
|
262
|
+
warnings,
|
263
|
+
code,
|
264
|
+
message,
|
265
|
+
buffer.read_consistency,
|
266
|
+
buffer.read_int,
|
267
|
+
buffer.read_int,
|
268
|
+
buffer.read_int,
|
269
|
+
(buffer.read_byte != 0))
|
270
|
+
when 0x1400
|
271
|
+
FunctionFailureErrorResponse.new(custom_payload,
|
272
|
+
warnings,
|
273
|
+
code,
|
274
|
+
message,
|
275
|
+
buffer.read_string,
|
276
|
+
buffer.read_string,
|
277
|
+
buffer.read_string_list)
|
278
|
+
when 0x1500
|
279
|
+
WriteFailureErrorResponse.new(custom_payload,
|
280
|
+
warnings,
|
281
|
+
code,
|
282
|
+
message,
|
283
|
+
buffer.read_consistency,
|
284
|
+
buffer.read_int,
|
285
|
+
buffer.read_int,
|
286
|
+
buffer.read_int,
|
287
|
+
buffer.read_string)
|
288
|
+
when 0x2400
|
289
|
+
AlreadyExistsErrorResponse.new(custom_payload,
|
290
|
+
warnings,
|
291
|
+
code,
|
292
|
+
message,
|
293
|
+
buffer.read_string,
|
294
|
+
buffer.read_string)
|
295
|
+
when 0x2500
|
296
|
+
UnpreparedErrorResponse.new(custom_payload,
|
297
|
+
warnings,
|
298
|
+
code,
|
299
|
+
message,
|
300
|
+
buffer.read_short_bytes)
|
231
301
|
else
|
232
302
|
ErrorResponse.new(custom_payload, warnings, code, message)
|
233
303
|
end
|
@@ -247,68 +317,100 @@ module Cassandra
|
|
247
317
|
column_specs, paging_state = Coder.read_metadata_v4(buffer)
|
248
318
|
|
249
319
|
if column_specs.nil?
|
250
|
-
consumed_bytes
|
251
|
-
remaining_bytes =
|
252
|
-
|
320
|
+
consumed_bytes = original_buffer_length - buffer.length
|
321
|
+
remaining_bytes =
|
322
|
+
CqlByteBuffer.new(buffer.read(size - consumed_bytes - 4))
|
323
|
+
RawRowsResultResponse.new(custom_payload,
|
324
|
+
warnings,
|
325
|
+
protocol_version,
|
326
|
+
remaining_bytes,
|
327
|
+
paging_state,
|
328
|
+
trace_id)
|
253
329
|
else
|
254
|
-
RowsResultResponse.new(custom_payload,
|
330
|
+
RowsResultResponse.new(custom_payload,
|
331
|
+
warnings,
|
332
|
+
Coder.read_values_v4(buffer, column_specs),
|
333
|
+
column_specs,
|
334
|
+
paging_state,
|
335
|
+
trace_id)
|
255
336
|
end
|
256
337
|
when 0x0003 # SetKeyspace
|
257
|
-
SetKeyspaceResultResponse.new(custom_payload,
|
338
|
+
SetKeyspaceResultResponse.new(custom_payload,
|
339
|
+
warnings,
|
340
|
+
buffer.read_string,
|
341
|
+
trace_id)
|
258
342
|
when 0x0004 # Prepared
|
259
343
|
id = buffer.read_short_bytes
|
260
344
|
pk_idx, params_metadata = Coder.read_prepared_metadata_v4(buffer)
|
261
345
|
result_metadata = Coder.read_metadata_v4(buffer).first
|
262
346
|
|
263
|
-
PreparedResultResponse.new(custom_payload,
|
347
|
+
PreparedResultResponse.new(custom_payload,
|
348
|
+
warnings,
|
349
|
+
id,
|
350
|
+
params_metadata,
|
351
|
+
result_metadata,
|
352
|
+
pk_idx,
|
353
|
+
trace_id)
|
264
354
|
when 0x0005 # SchemaChange
|
265
|
-
change
|
266
|
-
target
|
267
|
-
|
268
|
-
name = nil
|
355
|
+
change = buffer.read_string
|
356
|
+
target = buffer.read_string
|
357
|
+
name = nil
|
269
358
|
arguments = EMPTY_LIST
|
270
359
|
|
271
360
|
case target
|
272
361
|
when Protocol::Constants::SCHEMA_CHANGE_TARGET_KEYSPACE
|
273
362
|
keyspace = buffer.read_string
|
274
363
|
when Protocol::Constants::SCHEMA_CHANGE_TARGET_TABLE,
|
275
|
-
|
364
|
+
Protocol::Constants::SCHEMA_CHANGE_TARGET_UDT
|
276
365
|
keyspace = buffer.read_string
|
277
|
-
name
|
366
|
+
name = buffer.read_string
|
278
367
|
when Protocol::Constants::SCHEMA_CHANGE_TARGET_FUNCTION,
|
279
|
-
|
280
|
-
keyspace
|
281
|
-
name
|
368
|
+
Protocol::Constants::SCHEMA_CHANGE_TARGET_AGGREGATE
|
369
|
+
keyspace = buffer.read_string
|
370
|
+
name = buffer.read_string
|
282
371
|
arguments = buffer.read_string_list
|
372
|
+
else
|
373
|
+
raise Errors::DecodingError,
|
374
|
+
"Unsupported event target: #{target.inspect}"
|
283
375
|
end
|
284
376
|
|
285
|
-
SchemaChangeResultResponse.new(custom_payload,
|
377
|
+
SchemaChangeResultResponse.new(custom_payload,
|
378
|
+
warnings,
|
379
|
+
change,
|
380
|
+
keyspace,
|
381
|
+
name,
|
382
|
+
target,
|
383
|
+
arguments,
|
384
|
+
trace_id)
|
286
385
|
else
|
287
|
-
raise Errors::DecodingError,
|
386
|
+
raise Errors::DecodingError,
|
387
|
+
"Unsupported result type: #{result_type.inspect}"
|
288
388
|
end
|
289
389
|
when 0x0C # EVENT
|
290
390
|
event_type = buffer.read_string
|
291
391
|
case event_type
|
292
392
|
when 'SCHEMA_CHANGE'
|
293
|
-
change
|
294
|
-
target
|
295
|
-
keyspace = nil
|
393
|
+
change = buffer.read_string
|
394
|
+
target = buffer.read_string
|
296
395
|
arguments = EMPTY_LIST
|
297
396
|
|
298
397
|
case target
|
299
398
|
when Protocol::Constants::SCHEMA_CHANGE_TARGET_KEYSPACE
|
300
399
|
keyspace = buffer.read_string
|
301
|
-
name
|
400
|
+
name = nil
|
302
401
|
when Protocol::Constants::SCHEMA_CHANGE_TARGET_TABLE,
|
303
|
-
|
304
|
-
|
305
|
-
|
402
|
+
Protocol::Constants::SCHEMA_CHANGE_TARGET_UDT,
|
403
|
+
Protocol::Constants::SCHEMA_CHANGE_TARGET_FUNCTION,
|
404
|
+
Protocol::Constants::SCHEMA_CHANGE_TARGET_AGGREGATE
|
306
405
|
keyspace = buffer.read_string
|
307
|
-
name
|
406
|
+
name = buffer.read_string
|
407
|
+
else
|
408
|
+
raise Errors::DecodingError,
|
409
|
+
"Unsupported event target: #{target.inspect}"
|
308
410
|
end
|
309
411
|
|
310
412
|
if target == Protocol::Constants::SCHEMA_CHANGE_TARGET_FUNCTION \
|
311
|
-
|
413
|
+
|| target == Protocol::Constants::SCHEMA_CHANGE_TARGET_AGGREGATE
|
312
414
|
arguments = buffer.read_string_list
|
313
415
|
end
|
314
416
|
|
@@ -318,14 +420,16 @@ module Cassandra
|
|
318
420
|
when 'TOPOLOGY_CHANGE'
|
319
421
|
TopologyChangeEventResponse.new(buffer.read_string, *buffer.read_inet)
|
320
422
|
else
|
321
|
-
raise Errors::DecodingError,
|
423
|
+
raise Errors::DecodingError,
|
424
|
+
"Unsupported event type: #{event_type.inspect}"
|
322
425
|
end
|
323
426
|
when 0x0E # AUTH_CHALLENGE
|
324
427
|
AuthChallengeResponse.new(buffer.read_bytes)
|
325
428
|
when 0x10 # AUTH_SUCCESS
|
326
429
|
AuthSuccessResponse.new(buffer.read_bytes)
|
327
430
|
else
|
328
|
-
raise Errors::DecodingError,
|
431
|
+
raise Errors::DecodingError,
|
432
|
+
"Unsupported response opcode: #{opcode.inspect}"
|
329
433
|
end
|
330
434
|
end
|
331
435
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
#--
|
4
|
-
# Copyright 2013-
|
4
|
+
# Copyright 2013-2016 DataStax, Inc.
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
# you may not use this file except in compliance with the License.
|
@@ -39,9 +39,7 @@ module Cassandra
|
|
39
39
|
|
40
40
|
# @return [Cassandra::Reconnection::Schedule] reconnection schedule
|
41
41
|
# with constant interval
|
42
|
-
|
43
|
-
@schedule
|
44
|
-
end
|
42
|
+
attr_reader :schedule
|
45
43
|
end
|
46
44
|
end
|
47
45
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
#--
|
4
|
-
# Copyright 2013-
|
4
|
+
# Copyright 2013-2016 DataStax, Inc.
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
# you may not use this file except in compliance with the License.
|
@@ -39,11 +39,11 @@ module Cassandra
|
|
39
39
|
def backoff
|
40
40
|
new_interval = @interval * @exponent
|
41
41
|
|
42
|
-
if new_interval >= @max
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
@interval = if new_interval >= @max
|
43
|
+
@max
|
44
|
+
else
|
45
|
+
new_interval
|
46
|
+
end
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
data/lib/cassandra/result.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
#--
|
4
|
-
# Copyright 2013-
|
4
|
+
# Copyright 2013-2016 DataStax, Inc.
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
# you may not use this file except in compliance with the License.
|
@@ -23,7 +23,17 @@ module Cassandra
|
|
23
23
|
# Query execution information, such as number of retries and all tried hosts, etc.
|
24
24
|
# @return [Cassandra::Execution::Info]
|
25
25
|
def execution_info
|
26
|
-
@info ||= Execution::Info.new(@payload,
|
26
|
+
@info ||= Execution::Info.new(@payload,
|
27
|
+
@warnings,
|
28
|
+
@keyspace,
|
29
|
+
@statement,
|
30
|
+
@options,
|
31
|
+
@hosts,
|
32
|
+
@consistency,
|
33
|
+
@retries,
|
34
|
+
@trace_id ?
|
35
|
+
Execution::Trace.new(@trace_id, @client) :
|
36
|
+
nil)
|
27
37
|
end
|
28
38
|
|
29
39
|
# @return [Boolean] whether it has any rows
|
@@ -33,14 +43,14 @@ module Cassandra
|
|
33
43
|
# @return [Integer] rows count
|
34
44
|
def size
|
35
45
|
end
|
36
|
-
alias
|
46
|
+
alias length size
|
37
47
|
|
38
48
|
# @yieldparam row [Hash] current row
|
39
49
|
# @return [Enumerator, self] returns Enumerator if no block given
|
40
50
|
def each
|
41
51
|
end
|
42
|
-
alias
|
43
|
-
alias
|
52
|
+
alias rows each
|
53
|
+
alias each_row each
|
44
54
|
|
45
55
|
# @return [Boolean] whether no more pages are available
|
46
56
|
def last_page?
|
@@ -78,10 +88,10 @@ module Cassandra
|
|
78
88
|
# @return [String, nil] current paging state as a `String` or `nil`.
|
79
89
|
#
|
80
90
|
# @note Although this feature exists to allow web applications to store
|
81
|
-
# paging state in an [HTTP cookie](http://en.wikipedia.org/wiki/HTTP_cookie),
|
82
|
-
# expose without encrypting or otherwise securing it**.
|
83
|
-
# contains information internal to the Apache Cassandra cluster,
|
84
|
-
# partition key and data. Additionally, if a paging state is sent with CQL
|
91
|
+
# paging state in an [HTTP cookie](http://en.wikipedia.org/wiki/HTTP_cookie),
|
92
|
+
# **it is not safe to expose without encrypting or otherwise securing it**.
|
93
|
+
# Paging state contains information internal to the Apache Cassandra cluster,
|
94
|
+
# such as partition key and data. Additionally, if a paging state is sent with CQL
|
85
95
|
# statement, different from the original, the behavior of Cassandra is
|
86
96
|
# undefined and will likely cause a server process of the coordinator of
|
87
97
|
# such request to abort.
|
@@ -96,7 +106,19 @@ module Cassandra
|
|
96
106
|
class Paged < Result
|
97
107
|
attr_reader :paging_state
|
98
108
|
|
99
|
-
def initialize(payload,
|
109
|
+
def initialize(payload,
|
110
|
+
warnings,
|
111
|
+
rows,
|
112
|
+
paging_state,
|
113
|
+
trace_id,
|
114
|
+
keyspace,
|
115
|
+
statement,
|
116
|
+
options,
|
117
|
+
hosts,
|
118
|
+
consistency,
|
119
|
+
retries,
|
120
|
+
client,
|
121
|
+
futures_factory)
|
100
122
|
@payload = payload
|
101
123
|
@warnings = warnings
|
102
124
|
@rows = rows
|
@@ -121,7 +143,7 @@ module Cassandra
|
|
121
143
|
def size
|
122
144
|
@rows.size
|
123
145
|
end
|
124
|
-
alias
|
146
|
+
alias length size
|
125
147
|
|
126
148
|
def each(&block)
|
127
149
|
if block_given?
|
@@ -131,8 +153,8 @@ module Cassandra
|
|
131
153
|
@rows.each
|
132
154
|
end
|
133
155
|
end
|
134
|
-
alias
|
135
|
-
alias
|
156
|
+
alias rows each
|
157
|
+
alias each_row each
|
136
158
|
|
137
159
|
# Returns true when there are no more pages to load.
|
138
160
|
def last_page?
|
@@ -160,12 +182,24 @@ module Cassandra
|
|
160
182
|
|
161
183
|
# @private
|
162
184
|
def inspect
|
163
|
-
"#<Cassandra::Result:0x#{
|
185
|
+
"#<Cassandra::Result:0x#{object_id.to_s(16)} " \
|
186
|
+
"@rows=#{@rows.inspect} " \
|
187
|
+
"@last_page=#{@paging_state.nil?}>"
|
164
188
|
end
|
165
189
|
end
|
166
190
|
|
167
191
|
class Void < Result
|
168
|
-
def initialize(payload,
|
192
|
+
def initialize(payload,
|
193
|
+
warnings,
|
194
|
+
trace_id,
|
195
|
+
keyspace,
|
196
|
+
statement,
|
197
|
+
options,
|
198
|
+
hosts,
|
199
|
+
consistency,
|
200
|
+
retries,
|
201
|
+
client,
|
202
|
+
futures_factory)
|
169
203
|
@payload = payload
|
170
204
|
@warnings = warnings
|
171
205
|
@trace_id = trace_id
|
@@ -188,7 +222,7 @@ module Cassandra
|
|
188
222
|
def size
|
189
223
|
0
|
190
224
|
end
|
191
|
-
alias
|
225
|
+
alias length size
|
192
226
|
|
193
227
|
# Iterates over each row in the result set.
|
194
228
|
#
|
@@ -202,8 +236,8 @@ module Cassandra
|
|
202
236
|
EMPTY_LIST.each
|
203
237
|
end
|
204
238
|
end
|
205
|
-
alias
|
206
|
-
alias
|
239
|
+
alias rows each
|
240
|
+
alias each_row each
|
207
241
|
|
208
242
|
# Returns true when there are no more pages to load.
|
209
243
|
#
|
@@ -234,7 +268,7 @@ module Cassandra
|
|
234
268
|
end
|
235
269
|
|
236
270
|
def inspect
|
237
|
-
"#<Cassandra::Result:0x#{
|
271
|
+
"#<Cassandra::Result:0x#{object_id.to_s(16)} @rows=[] @last_page=true>"
|
238
272
|
end
|
239
273
|
end
|
240
274
|
end
|