cassandra-driver 3.0.0.beta.1-java → 3.0.0-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.
Files changed (138) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +106 -39
  3. data/lib/cassandra.rb +396 -148
  4. data/lib/cassandra/address_resolution.rb +1 -1
  5. data/lib/cassandra/address_resolution/policies/ec2_multi_region.rb +1 -1
  6. data/lib/cassandra/address_resolution/policies/none.rb +1 -1
  7. data/lib/cassandra/aggregate.rb +21 -7
  8. data/lib/cassandra/argument.rb +2 -2
  9. data/lib/cassandra/attr_boolean.rb +33 -0
  10. data/lib/cassandra/auth.rb +6 -5
  11. data/lib/cassandra/auth/providers.rb +1 -1
  12. data/lib/cassandra/auth/providers/password.rb +5 -13
  13. data/lib/cassandra/cassandra_logger.rb +80 -0
  14. data/lib/cassandra/cluster.rb +49 -9
  15. data/lib/cassandra/cluster/client.rb +835 -209
  16. data/lib/cassandra/cluster/connection_pool.rb +2 -2
  17. data/lib/cassandra/cluster/connector.rb +86 -27
  18. data/lib/cassandra/cluster/control_connection.rb +222 -95
  19. data/lib/cassandra/cluster/failed_connection.rb +1 -1
  20. data/lib/cassandra/cluster/metadata.rb +14 -8
  21. data/lib/cassandra/cluster/options.rb +68 -22
  22. data/lib/cassandra/cluster/registry.rb +81 -17
  23. data/lib/cassandra/cluster/schema.rb +70 -8
  24. data/lib/cassandra/cluster/schema/cql_type_parser.rb +15 -10
  25. data/lib/cassandra/cluster/schema/fetchers.rb +601 -241
  26. data/lib/cassandra/cluster/schema/fqcn_type_parser.rb +39 -38
  27. data/lib/cassandra/cluster/schema/partitioners.rb +1 -1
  28. data/lib/cassandra/cluster/schema/partitioners/murmur3.rb +6 -8
  29. data/lib/cassandra/cluster/schema/partitioners/ordered.rb +1 -1
  30. data/lib/cassandra/cluster/schema/partitioners/random.rb +1 -1
  31. data/lib/cassandra/cluster/schema/replication_strategies.rb +1 -1
  32. data/lib/cassandra/cluster/schema/replication_strategies/network_topology.rb +19 -18
  33. data/lib/cassandra/cluster/schema/replication_strategies/none.rb +1 -1
  34. data/lib/cassandra/cluster/schema/replication_strategies/simple.rb +1 -1
  35. data/lib/cassandra/column.rb +4 -23
  36. data/lib/cassandra/column_container.rb +322 -0
  37. data/lib/cassandra/compression.rb +1 -1
  38. data/lib/cassandra/compression/compressors/lz4.rb +7 -8
  39. data/lib/cassandra/compression/compressors/snappy.rb +4 -3
  40. data/lib/cassandra/driver.rb +107 -46
  41. data/lib/cassandra/errors.rb +303 -52
  42. data/lib/cassandra/execution/info.rb +16 -5
  43. data/lib/cassandra/execution/options.rb +102 -55
  44. data/lib/cassandra/execution/trace.rb +16 -9
  45. data/lib/cassandra/executors.rb +1 -1
  46. data/lib/cassandra/function.rb +19 -13
  47. data/lib/cassandra/function_collection.rb +85 -0
  48. data/lib/cassandra/future.rb +101 -49
  49. data/lib/cassandra/host.rb +25 -5
  50. data/lib/cassandra/index.rb +118 -0
  51. data/lib/cassandra/keyspace.rb +169 -33
  52. data/lib/cassandra/listener.rb +1 -1
  53. data/lib/cassandra/load_balancing.rb +2 -2
  54. data/lib/cassandra/load_balancing/policies.rb +1 -1
  55. data/lib/cassandra/load_balancing/policies/dc_aware_round_robin.rb +39 -25
  56. data/lib/cassandra/load_balancing/policies/round_robin.rb +8 -1
  57. data/lib/cassandra/load_balancing/policies/token_aware.rb +22 -13
  58. data/lib/cassandra/load_balancing/policies/white_list.rb +18 -5
  59. data/lib/cassandra/materialized_view.rb +90 -0
  60. data/lib/cassandra/null_logger.rb +27 -6
  61. data/lib/cassandra/protocol.rb +1 -1
  62. data/lib/cassandra/protocol/coder.rb +81 -42
  63. data/lib/cassandra/protocol/cql_byte_buffer.rb +58 -44
  64. data/lib/cassandra/protocol/cql_protocol_handler.rb +57 -54
  65. data/lib/cassandra/protocol/request.rb +6 -7
  66. data/lib/cassandra/protocol/requests/auth_response_request.rb +3 -3
  67. data/lib/cassandra/protocol/requests/batch_request.rb +17 -8
  68. data/lib/cassandra/protocol/requests/credentials_request.rb +3 -3
  69. data/lib/cassandra/protocol/requests/execute_request.rb +39 -20
  70. data/lib/cassandra/protocol/requests/options_request.rb +1 -1
  71. data/lib/cassandra/protocol/requests/prepare_request.rb +5 -5
  72. data/lib/cassandra/protocol/requests/query_request.rb +28 -23
  73. data/lib/cassandra/protocol/requests/register_request.rb +2 -2
  74. data/lib/cassandra/protocol/requests/startup_request.rb +8 -8
  75. data/lib/cassandra/protocol/requests/void_query_request.rb +1 -1
  76. data/lib/cassandra/protocol/response.rb +3 -4
  77. data/lib/cassandra/protocol/responses/already_exists_error_response.rb +12 -2
  78. data/lib/cassandra/protocol/responses/auth_challenge_response.rb +4 -5
  79. data/lib/cassandra/protocol/responses/auth_success_response.rb +4 -5
  80. data/lib/cassandra/protocol/responses/authenticate_response.rb +4 -5
  81. data/lib/cassandra/protocol/responses/error_response.rb +104 -17
  82. data/lib/cassandra/protocol/responses/event_response.rb +3 -4
  83. data/lib/cassandra/protocol/responses/function_failure_error_response.rb +13 -2
  84. data/lib/cassandra/protocol/responses/prepared_result_response.rb +14 -9
  85. data/lib/cassandra/protocol/responses/raw_rows_result_response.rb +14 -9
  86. data/lib/cassandra/protocol/responses/read_failure_error_response.rb +26 -4
  87. data/lib/cassandra/protocol/responses/read_timeout_error_response.rb +22 -3
  88. data/lib/cassandra/protocol/responses/ready_response.rb +6 -7
  89. data/lib/cassandra/protocol/responses/result_response.rb +11 -10
  90. data/lib/cassandra/protocol/responses/rows_result_response.rb +8 -7
  91. data/lib/cassandra/protocol/responses/schema_change_event_response.rb +8 -8
  92. data/lib/cassandra/protocol/responses/schema_change_result_response.rb +19 -13
  93. data/lib/cassandra/protocol/responses/set_keyspace_result_response.rb +5 -6
  94. data/lib/cassandra/protocol/responses/status_change_event_response.rb +5 -6
  95. data/lib/cassandra/protocol/responses/supported_response.rb +4 -5
  96. data/lib/cassandra/protocol/responses/topology_change_event_response.rb +4 -5
  97. data/lib/cassandra/protocol/responses/unavailable_error_response.rb +20 -3
  98. data/lib/cassandra/protocol/responses/unprepared_error_response.rb +11 -2
  99. data/lib/cassandra/protocol/responses/void_result_response.rb +4 -5
  100. data/lib/cassandra/protocol/responses/write_failure_error_response.rb +26 -4
  101. data/lib/cassandra/protocol/responses/write_timeout_error_response.rb +22 -3
  102. data/lib/cassandra/protocol/v1.rb +98 -37
  103. data/lib/cassandra/protocol/v3.rb +121 -50
  104. data/lib/cassandra/protocol/v4.rb +172 -68
  105. data/lib/cassandra/reconnection.rb +1 -1
  106. data/lib/cassandra/reconnection/policies.rb +1 -1
  107. data/lib/cassandra/reconnection/policies/constant.rb +2 -4
  108. data/lib/cassandra/reconnection/policies/exponential.rb +6 -6
  109. data/lib/cassandra/result.rb +55 -20
  110. data/lib/cassandra/retry.rb +8 -8
  111. data/lib/cassandra/retry/policies.rb +1 -1
  112. data/lib/cassandra/retry/policies/default.rb +1 -1
  113. data/lib/cassandra/retry/policies/downgrading_consistency.rb +4 -2
  114. data/lib/cassandra/retry/policies/fallthrough.rb +1 -1
  115. data/lib/cassandra/session.rb +24 -16
  116. data/lib/cassandra/statement.rb +1 -1
  117. data/lib/cassandra/statements.rb +1 -1
  118. data/lib/cassandra/statements/batch.rb +16 -10
  119. data/lib/cassandra/statements/bound.rb +10 -3
  120. data/lib/cassandra/statements/prepared.rb +62 -18
  121. data/lib/cassandra/statements/simple.rb +23 -10
  122. data/lib/cassandra/statements/void.rb +1 -1
  123. data/lib/cassandra/table.rb +53 -185
  124. data/lib/cassandra/time.rb +11 -6
  125. data/lib/cassandra/time_uuid.rb +12 -14
  126. data/lib/cassandra/timestamp_generator.rb +37 -0
  127. data/lib/cassandra/timestamp_generator/simple.rb +38 -0
  128. data/lib/cassandra/timestamp_generator/ticking_on_duplicate.rb +58 -0
  129. data/lib/cassandra/tuple.rb +4 -4
  130. data/lib/cassandra/types.rb +109 -71
  131. data/lib/cassandra/udt.rb +66 -50
  132. data/lib/cassandra/util.rb +155 -15
  133. data/lib/cassandra/uuid.rb +20 -21
  134. data/lib/cassandra/uuid/generator.rb +7 -5
  135. data/lib/cassandra/version.rb +2 -2
  136. data/lib/cassandra_murmur3.jar +0 -0
  137. data/lib/datastax/cassandra.rb +1 -1
  138. metadata +27 -16
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  #--
4
- # Copyright 2013-2015 DataStax, Inc.
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 = [@protocol_version, flags, stream_id, request.opcode, body.bytesize]
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
- @handler.complete_request(stream_id, ErrorResponse.new(nil, nil, 0x000A, "Invalid or unsupported protocol version"))
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, size, code)
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(@compressor.decompress(buffer.read(size)))
175
- size = buffer.size
179
+ buffer = CqlByteBuffer.new(
180
+ @compressor.decompress(buffer.read(frame_length)))
181
+ frame_length = buffer.size
176
182
  else
177
- raise Errors::DecodingError, 'Compressed frame received, but no compressor configured'
183
+ raise Errors::DecodingError,
184
+ 'Compressed frame received, but no compressor configured'
178
185
  end
179
186
  end
180
187
 
181
- if tracing
182
- trace_id = buffer.read_uuid
183
- size = buffer.size
184
- else
185
- trace_id = nil
186
- end
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
- if payload
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 warning
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
- extra_length = buffer.length - size
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
- if buffer.length > extra_length
206
- buffer.discard(buffer.length - extra_length)
207
- end
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, protocol_version, buffer, size, trace_id, custom_payload, warnings)
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 = buffer.read_int
230
+ code = buffer.read_int
220
231
  message = buffer.read_string
221
232
 
222
233
  case code
223
- when 0x1000 then UnavailableErrorResponse.new(custom_payload, warnings, code, message, buffer.read_consistency, buffer.read_int, buffer.read_int)
224
- when 0x1100 then WriteTimeoutErrorResponse.new(custom_payload, warnings, code, message, buffer.read_consistency, buffer.read_int, buffer.read_int, buffer.read_string)
225
- when 0x1200 then ReadTimeoutErrorResponse.new(custom_payload, warnings, code, message, buffer.read_consistency, buffer.read_int, buffer.read_int, (buffer.read_byte != 0))
226
- when 0x1300 then ReadFailureErrorResponse.new(custom_payload, warnings, code, message, buffer.read_consistency, buffer.read_int, buffer.read_int, buffer.read_int, (buffer.read_byte != 0))
227
- when 0x1400 then FunctionFailureErrorResponse.new(custom_payload, warnings, code, message, buffer.read_string, buffer.read_string, buffer.read_string_list)
228
- when 0x1500 then WriteFailureErrorResponse.new(custom_payload, warnings, code, message, buffer.read_consistency, buffer.read_int, buffer.read_int, buffer.read_int, buffer.read_string)
229
- when 0x2400 then AlreadyExistsErrorResponse.new(custom_payload, warnings, code, message, buffer.read_string, buffer.read_string)
230
- when 0x2500 then UnpreparedErrorResponse.new(custom_payload, warnings, code, message, buffer.read_short_bytes)
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 = original_buffer_length - buffer.length
251
- remaining_bytes = CqlByteBuffer.new(buffer.read(size - consumed_bytes - 4))
252
- RawRowsResultResponse.new(custom_payload, warnings, protocol_version, remaining_bytes, paging_state, trace_id)
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, warnings, Coder.read_values_v4(buffer, column_specs), column_specs, paging_state, trace_id)
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, warnings, buffer.read_string, trace_id)
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, warnings, id, params_metadata, result_metadata, pk_idx, trace_id)
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 = buffer.read_string
266
- target = buffer.read_string
267
- keyspace = nil
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
- Protocol::Constants::SCHEMA_CHANGE_TARGET_UDT
364
+ Protocol::Constants::SCHEMA_CHANGE_TARGET_UDT
276
365
  keyspace = buffer.read_string
277
- name = buffer.read_string
366
+ name = buffer.read_string
278
367
  when Protocol::Constants::SCHEMA_CHANGE_TARGET_FUNCTION,
279
- Protocol::Constants::SCHEMA_CHANGE_TARGET_AGGREGATE
280
- keyspace = buffer.read_string
281
- name = buffer.read_string
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, warnings, change, keyspace, name, target, arguments, trace_id)
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, "Unsupported result type: #{result_type.inspect}"
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 = buffer.read_string
294
- target = buffer.read_string
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 = nil
400
+ name = nil
302
401
  when Protocol::Constants::SCHEMA_CHANGE_TARGET_TABLE,
303
- Protocol::Constants::SCHEMA_CHANGE_TARGET_UDT,
304
- Protocol::Constants::SCHEMA_CHANGE_TARGET_FUNCTION,
305
- Protocol::Constants::SCHEMA_CHANGE_TARGET_AGGREGATE
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 = buffer.read_string
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
- || target == Protocol::Constants::SCHEMA_CHANGE_TARGET_AGGREGATE
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, "Unsupported event type: #{event_type.inspect}"
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, "Unsupported response opcode: #{opcode.inspect}"
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-2015 DataStax, Inc.
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.
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  #--
4
- # Copyright 2013-2015 DataStax, Inc.
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.
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  #--
4
- # Copyright 2013-2015 DataStax, Inc.
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
- def schedule
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-2015 DataStax, Inc.
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
- @interval = @max
44
- else
45
- @interval = new_interval
46
- end
42
+ @interval = if new_interval >= @max
43
+ @max
44
+ else
45
+ new_interval
46
+ end
47
47
  end
48
48
  end
49
49
 
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  #--
4
- # Copyright 2013-2015 DataStax, Inc.
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, @warnings, @keyspace, @statement, @options, @hosts, @consistency, @retries, @trace_id ? Execution::Trace.new(@trace_id, @client) : nil)
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 :length :size
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 :rows :each
43
- alias :each_row :each
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,15 +88,16 @@ 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), **it is not safe to
82
- # expose without encrypting or otherwise securing it**. Paging state
83
- # contains information internal to the Apache Cassandra cluster, such as
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.
88
98
  #
89
- # @see https://github.com/apache/cassandra/blob/cassandra-2.0.16/doc/native_protocol_v2.spec#L482-L487 Paging State description in Cassandra Native Protocol v2 specification
99
+ # @see https://github.com/apache/cassandra/blob/cassandra-2.0.16/doc/native_protocol_v2.spec#L482-L487 Paging State
100
+ # description in Cassandra Native Protocol v2 specification
90
101
  def paging_state
91
102
  end
92
103
  end
@@ -96,7 +107,19 @@ module Cassandra
96
107
  class Paged < Result
97
108
  attr_reader :paging_state
98
109
 
99
- def initialize(payload, warnings, rows, paging_state, trace_id, keyspace, statement, options, hosts, consistency, retries, client, futures_factory)
110
+ def initialize(payload,
111
+ warnings,
112
+ rows,
113
+ paging_state,
114
+ trace_id,
115
+ keyspace,
116
+ statement,
117
+ options,
118
+ hosts,
119
+ consistency,
120
+ retries,
121
+ client,
122
+ futures_factory)
100
123
  @payload = payload
101
124
  @warnings = warnings
102
125
  @rows = rows
@@ -121,7 +144,7 @@ module Cassandra
121
144
  def size
122
145
  @rows.size
123
146
  end
124
- alias :length :size
147
+ alias length size
125
148
 
126
149
  def each(&block)
127
150
  if block_given?
@@ -131,8 +154,8 @@ module Cassandra
131
154
  @rows.each
132
155
  end
133
156
  end
134
- alias :rows :each
135
- alias :each_row :each
157
+ alias rows each
158
+ alias each_row each
136
159
 
137
160
  # Returns true when there are no more pages to load.
138
161
  def last_page?
@@ -160,12 +183,24 @@ module Cassandra
160
183
 
161
184
  # @private
162
185
  def inspect
163
- "#<Cassandra::Result:0x#{self.object_id.to_s(16)} @rows=#{@rows.inspect} @last_page=#{@paging_state.nil?}>"
186
+ "#<Cassandra::Result:0x#{object_id.to_s(16)} " \
187
+ "@rows=#{@rows.inspect} " \
188
+ "@last_page=#{@paging_state.nil?}>"
164
189
  end
165
190
  end
166
191
 
167
192
  class Void < Result
168
- def initialize(payload, warnings, trace_id, keyspace, statement, options, hosts, consistency, retries, client, futures_factory)
193
+ def initialize(payload,
194
+ warnings,
195
+ trace_id,
196
+ keyspace,
197
+ statement,
198
+ options,
199
+ hosts,
200
+ consistency,
201
+ retries,
202
+ client,
203
+ futures_factory)
169
204
  @payload = payload
170
205
  @warnings = warnings
171
206
  @trace_id = trace_id
@@ -188,7 +223,7 @@ module Cassandra
188
223
  def size
189
224
  0
190
225
  end
191
- alias :length :size
226
+ alias length size
192
227
 
193
228
  # Iterates over each row in the result set.
194
229
  #
@@ -202,8 +237,8 @@ module Cassandra
202
237
  EMPTY_LIST.each
203
238
  end
204
239
  end
205
- alias :rows :each
206
- alias :each_row :each
240
+ alias rows each
241
+ alias each_row each
207
242
 
208
243
  # Returns true when there are no more pages to load.
209
244
  #
@@ -234,7 +269,7 @@ module Cassandra
234
269
  end
235
270
 
236
271
  def inspect
237
- "#<Cassandra::Result:0x#{self.object_id.to_s(16)} @rows=[] @last_page=true>"
272
+ "#<Cassandra::Result:0x#{object_id.to_s(16)} @rows=[] @last_page=true>"
238
273
  end
239
274
  end
240
275
  end