cassandra-driver 3.2.0-java → 3.2.5.rc1-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +30 -30
- data/lib/cassandra.rb +3 -2
- 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 +1 -1
- data/lib/cassandra/argument.rb +1 -1
- data/lib/cassandra/attr_boolean.rb +1 -1
- data/lib/cassandra/auth.rb +1 -1
- data/lib/cassandra/auth/providers.rb +1 -1
- data/lib/cassandra/auth/providers/password.rb +1 -1
- data/lib/cassandra/cassandra_logger.rb +1 -1
- data/lib/cassandra/cluster.rb +1 -1
- data/lib/cassandra/cluster/client.rb +1 -1
- data/lib/cassandra/cluster/connection_pool.rb +1 -1
- data/lib/cassandra/cluster/connector.rb +1 -1
- data/lib/cassandra/cluster/control_connection.rb +1 -1
- data/lib/cassandra/cluster/failed_connection.rb +1 -1
- data/lib/cassandra/cluster/metadata.rb +1 -1
- data/lib/cassandra/cluster/options.rb +1 -1
- data/lib/cassandra/cluster/registry.rb +5 -5
- data/lib/cassandra/cluster/schema.rb +1 -1
- data/lib/cassandra/cluster/schema/cql_type_parser.rb +4 -3
- data/lib/cassandra/cluster/schema/fetchers.rb +2 -2
- data/lib/cassandra/cluster/schema/fqcn_type_parser.rb +4 -5
- data/lib/cassandra/cluster/schema/partitioners.rb +1 -1
- data/lib/cassandra/cluster/schema/partitioners/murmur3.rb +1 -1
- 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 +1 -1
- 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 +1 -1
- data/lib/cassandra/column_container.rb +2 -2
- data/lib/cassandra/compression.rb +1 -1
- data/lib/cassandra/compression/compressors/lz4.rb +1 -1
- data/lib/cassandra/compression/compressors/snappy.rb +1 -1
- data/lib/cassandra/custom_data.rb +1 -1
- data/lib/cassandra/driver.rb +1 -1
- data/lib/cassandra/duration.rb +100 -0
- data/lib/cassandra/errors.rb +1 -1
- data/lib/cassandra/execution/info.rb +1 -1
- data/lib/cassandra/execution/options.rb +1 -1
- data/lib/cassandra/execution/profile.rb +5 -2
- data/lib/cassandra/execution/profile_manager.rb +1 -1
- data/lib/cassandra/execution/trace.rb +1 -1
- data/lib/cassandra/executors.rb +1 -1
- data/lib/cassandra/function.rb +1 -1
- data/lib/cassandra/function_collection.rb +1 -1
- data/lib/cassandra/future.rb +9 -3
- data/lib/cassandra/host.rb +1 -1
- data/lib/cassandra/index.rb +1 -1
- data/lib/cassandra/keyspace.rb +1 -1
- data/lib/cassandra/listener.rb +1 -1
- data/lib/cassandra/load_balancing.rb +1 -1
- data/lib/cassandra/load_balancing/policies.rb +1 -1
- data/lib/cassandra/load_balancing/policies/dc_aware_round_robin.rb +1 -1
- data/lib/cassandra/load_balancing/policies/round_robin.rb +1 -1
- data/lib/cassandra/load_balancing/policies/token_aware.rb +1 -1
- data/lib/cassandra/load_balancing/policies/white_list.rb +1 -1
- data/lib/cassandra/materialized_view.rb +1 -1
- data/lib/cassandra/null_logger.rb +1 -1
- data/lib/cassandra/protocol.rb +1 -1
- data/lib/cassandra/protocol/coder.rb +1 -1
- data/lib/cassandra/protocol/cql_byte_buffer.rb +63 -15
- data/lib/cassandra/protocol/cql_protocol_handler.rb +58 -10
- data/lib/cassandra/protocol/request.rb +1 -1
- data/lib/cassandra/protocol/requests/auth_response_request.rb +1 -1
- data/lib/cassandra/protocol/requests/batch_request.rb +1 -1
- data/lib/cassandra/protocol/requests/credentials_request.rb +1 -1
- data/lib/cassandra/protocol/requests/execute_request.rb +1 -1
- data/lib/cassandra/protocol/requests/options_request.rb +1 -1
- data/lib/cassandra/protocol/requests/prepare_request.rb +1 -1
- data/lib/cassandra/protocol/requests/query_request.rb +1 -1
- data/lib/cassandra/protocol/requests/register_request.rb +1 -1
- data/lib/cassandra/protocol/requests/startup_request.rb +1 -1
- data/lib/cassandra/protocol/requests/void_query_request.rb +1 -1
- data/lib/cassandra/protocol/response.rb +1 -1
- data/lib/cassandra/protocol/responses/already_exists_error_response.rb +1 -1
- 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 +1 -1
- data/lib/cassandra/protocol/responses/event_response.rb +1 -1
- data/lib/cassandra/protocol/responses/function_failure_error_response.rb +1 -1
- data/lib/cassandra/protocol/responses/prepared_result_response.rb +1 -1
- data/lib/cassandra/protocol/responses/raw_rows_result_response.rb +1 -1
- data/lib/cassandra/protocol/responses/read_failure_error_response.rb +1 -1
- data/lib/cassandra/protocol/responses/read_timeout_error_response.rb +1 -1
- data/lib/cassandra/protocol/responses/ready_response.rb +1 -1
- data/lib/cassandra/protocol/responses/result_response.rb +1 -1
- data/lib/cassandra/protocol/responses/rows_result_response.rb +1 -1
- data/lib/cassandra/protocol/responses/schema_change_event_response.rb +1 -1
- data/lib/cassandra/protocol/responses/schema_change_result_response.rb +1 -1
- data/lib/cassandra/protocol/responses/set_keyspace_result_response.rb +1 -1
- data/lib/cassandra/protocol/responses/status_change_event_response.rb +1 -1
- 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 +1 -1
- data/lib/cassandra/protocol/responses/unprepared_error_response.rb +1 -1
- data/lib/cassandra/protocol/responses/void_result_response.rb +1 -1
- data/lib/cassandra/protocol/responses/write_failure_error_response.rb +1 -1
- data/lib/cassandra/protocol/responses/write_timeout_error_response.rb +1 -1
- data/lib/cassandra/protocol/v1.rb +1 -1
- data/lib/cassandra/protocol/v3.rb +1 -1
- data/lib/cassandra/protocol/v4.rb +4 -1
- data/lib/cassandra/reconnection.rb +1 -1
- data/lib/cassandra/reconnection/policies.rb +1 -1
- data/lib/cassandra/reconnection/policies/constant.rb +1 -1
- data/lib/cassandra/reconnection/policies/exponential.rb +1 -1
- data/lib/cassandra/result.rb +1 -1
- data/lib/cassandra/retry.rb +1 -1
- 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 +1 -1
- data/lib/cassandra/retry/policies/fallthrough.rb +1 -1
- data/lib/cassandra/session.rb +8 -4
- data/lib/cassandra/statement.rb +1 -1
- data/lib/cassandra/statements.rb +1 -1
- data/lib/cassandra/statements/batch.rb +1 -1
- data/lib/cassandra/statements/bound.rb +1 -1
- data/lib/cassandra/statements/prepared.rb +1 -1
- data/lib/cassandra/statements/simple.rb +1 -1
- data/lib/cassandra/statements/void.rb +1 -1
- data/lib/cassandra/table.rb +2 -2
- data/lib/cassandra/time.rb +1 -1
- data/lib/cassandra/time_uuid.rb +1 -1
- data/lib/cassandra/timestamp_generator.rb +1 -1
- data/lib/cassandra/timestamp_generator/simple.rb +1 -1
- data/lib/cassandra/timestamp_generator/ticking_on_duplicate.rb +1 -1
- data/lib/cassandra/trigger.rb +1 -1
- data/lib/cassandra/tuple.rb +1 -1
- data/lib/cassandra/types.rb +73 -2
- data/lib/cassandra/udt.rb +1 -1
- data/lib/cassandra/util.rb +21 -1
- data/lib/cassandra/uuid.rb +1 -1
- data/lib/cassandra/uuid/generator.rb +1 -1
- data/lib/cassandra/version.rb +2 -2
- data/lib/cassandra_murmur3.jar +0 -0
- data/lib/datastax/cassandra.rb +1 -1
- metadata +8 -8
data/lib/cassandra/keyspace.rb
CHANGED
data/lib/cassandra/listener.rb
CHANGED
data/lib/cassandra/protocol.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
#--
|
4
|
-
# Copyright
|
4
|
+
# Copyright 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.
|
@@ -53,24 +53,30 @@ module Cassandra
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def read_decimal(len = bytesize)
|
56
|
-
|
56
|
+
scale = read_signed_int
|
57
57
|
number_string = read_varint(len - 4).to_s
|
58
|
-
if
|
59
|
-
|
60
|
-
|
61
|
-
|
58
|
+
if scale <= 0
|
59
|
+
# Special case where the actual scale is positive; scale in the protocol is actually negative of
|
60
|
+
# reality.
|
61
|
+
BigDecimal(number_string + '0' * -scale)
|
62
|
+
else
|
63
|
+
if number_string.length <= scale
|
64
|
+
if number_string.start_with?(MINUS)
|
65
|
+
number_string = number_string[1, number_string.length - 1]
|
66
|
+
fraction_string = MINUS + ZERO << DECIMAL_POINT
|
67
|
+
else
|
68
|
+
fraction_string = ZERO + DECIMAL_POINT
|
69
|
+
end
|
70
|
+
(scale - number_string.length).times { fraction_string << ZERO }
|
71
|
+
fraction_string << number_string
|
62
72
|
else
|
63
|
-
fraction_string =
|
73
|
+
fraction_string = number_string[0, number_string.length - scale]
|
74
|
+
fraction_string << DECIMAL_POINT
|
75
|
+
fraction_string <<
|
76
|
+
number_string[number_string.length - scale, number_string.length]
|
64
77
|
end
|
65
|
-
(
|
66
|
-
fraction_string << number_string
|
67
|
-
else
|
68
|
-
fraction_string = number_string[0, number_string.length - size]
|
69
|
-
fraction_string << DECIMAL_POINT
|
70
|
-
fraction_string <<
|
71
|
-
number_string[number_string.length - size, number_string.length]
|
78
|
+
BigDecimal(fraction_string)
|
72
79
|
end
|
73
|
-
BigDecimal.new(fraction_string)
|
74
80
|
rescue Errors::DecodingError => e
|
75
81
|
raise Errors::DecodingError, e.message, e.backtrace
|
76
82
|
end
|
@@ -281,6 +287,29 @@ module Cassandra
|
|
281
287
|
"Not enough bytes available to decode a tinyint: #{e.message}", e.backtrace
|
282
288
|
end
|
283
289
|
|
290
|
+
def read_vint
|
291
|
+
n = read_byte
|
292
|
+
|
293
|
+
# Bits are indexed in Integer in little-endian order
|
294
|
+
bytes_to_read = 7.downto(0).take_while {|i| n[i] == 1}.size
|
295
|
+
return n unless bytes_to_read > 0
|
296
|
+
|
297
|
+
rv = n & (0xff >> bytes_to_read)
|
298
|
+
1.upto(bytes_to_read) do |idx|
|
299
|
+
new_byte = read_byte
|
300
|
+
rv <<= 8
|
301
|
+
rv |= (new_byte & 0xff)
|
302
|
+
end
|
303
|
+
|
304
|
+
rv
|
305
|
+
rescue RangeError => e
|
306
|
+
raise Errors::DecodingError, e.message, e.backtrace
|
307
|
+
end
|
308
|
+
|
309
|
+
def read_signed_vint
|
310
|
+
Util.decode_zigzag(read_vint)
|
311
|
+
end
|
312
|
+
|
284
313
|
def append_tinyint(n)
|
285
314
|
append([n].pack(Formats::CHAR_FORMAT))
|
286
315
|
end
|
@@ -403,6 +432,25 @@ module Cassandra
|
|
403
432
|
append([n].pack(Formats::FLOAT_FORMAT))
|
404
433
|
end
|
405
434
|
|
435
|
+
def append_vint(n)
|
436
|
+
send_bytes = Util.to_min_byte_array(n)
|
437
|
+
send_cnt = send_bytes.length
|
438
|
+
|
439
|
+
raise Errors::EncodingError, "Too many bytes (#{bytes_to_send.length}) to send!" if send_cnt > 8
|
440
|
+
|
441
|
+
send_cnt_byte = (0xff << (8 - send_cnt)) & 0xff
|
442
|
+
append([send_cnt_byte].pack(Formats::BYTES_FORMAT))
|
443
|
+
append(send_bytes.pack(Formats::BYTES_FORMAT))
|
444
|
+
end
|
445
|
+
|
446
|
+
def append_signed_vint32(n)
|
447
|
+
append_vint(Util.encode_zigzag32(n))
|
448
|
+
end
|
449
|
+
|
450
|
+
def append_signed_vint64(n)
|
451
|
+
append_vint(Util.encode_zigzag64(n))
|
452
|
+
end
|
453
|
+
|
406
454
|
def eql?(other)
|
407
455
|
other.eql?(to_str)
|
408
456
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
#--
|
4
|
-
# Copyright
|
4
|
+
# Copyright 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.
|
@@ -170,7 +170,7 @@ module Cassandra
|
|
170
170
|
def send_request(request, timeout = nil, with_heartbeat = true)
|
171
171
|
return Ione::Future.failed(Errors::IOError.new('Connection closed')) if closed?
|
172
172
|
schedule_heartbeat if with_heartbeat
|
173
|
-
promise = RequestPromise.new(request, timeout)
|
173
|
+
promise = RequestPromise.new(request, timeout, @scheduler)
|
174
174
|
id = nil
|
175
175
|
@lock.lock
|
176
176
|
begin
|
@@ -256,22 +256,74 @@ module Cassandra
|
|
256
256
|
|
257
257
|
attr_reader :request, :timeout
|
258
258
|
attr_boolean :timed_out
|
259
|
+
attr_accessor :timer
|
259
260
|
|
260
|
-
def initialize(request, timeout)
|
261
|
+
def initialize(request, timeout, scheduler)
|
261
262
|
@request = request
|
262
263
|
@timeout = timeout
|
263
264
|
@timed_out = false
|
265
|
+
@scheduler = scheduler
|
266
|
+
@lock = Mutex.new
|
267
|
+
@timer = nil
|
264
268
|
super()
|
265
269
|
end
|
266
270
|
|
267
271
|
def time_out!
|
268
272
|
unless future.completed?
|
269
273
|
@timed_out = true
|
270
|
-
# rubocop:disable Style/SignalException
|
271
274
|
fail(Errors::TimeoutError.new('Timed out'))
|
272
|
-
# rubocop:enable Style/SignalException
|
273
275
|
end
|
274
276
|
end
|
277
|
+
|
278
|
+
def maybe_start_timer
|
279
|
+
# This is more complicated than one would expect. First, we want to start a timer
|
280
|
+
# if a timeout is set. But there is a race condition where send_request creates
|
281
|
+
# a fresh promise and adds it to @promises, but another thread handles a socket
|
282
|
+
# closure event and fails all known promises. When a promise fails, we want to cancel
|
283
|
+
# the timer, if set. So, we synchronize access to @timer to be sure we don't set up
|
284
|
+
# and cancel the timer at the same time. However, if promise.fail runs first, there
|
285
|
+
# will be no timer to cancel, and then when maybe_start_timer gets called in the other
|
286
|
+
# thread, it'll create a timer on a promise that no one is going to action on going forward.
|
287
|
+
# So, that leads to leaking the timer until it times out. To avoid this, we want to
|
288
|
+
# check that the future of the promise isn't completed before starting the timer.
|
289
|
+
|
290
|
+
return if @timeout.nil?
|
291
|
+
return if @future.completed?
|
292
|
+
|
293
|
+
if @timer.nil?
|
294
|
+
@lock.synchronize do
|
295
|
+
if @timer.nil?
|
296
|
+
return if @future.completed?
|
297
|
+
@timer = @scheduler.schedule_timer(@timeout)
|
298
|
+
@timer.on_value { time_out! }
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
def fulfill(response)
|
305
|
+
super
|
306
|
+
maybe_cancel_timer
|
307
|
+
end
|
308
|
+
|
309
|
+
def fail(cause)
|
310
|
+
super
|
311
|
+
maybe_cancel_timer
|
312
|
+
end
|
313
|
+
|
314
|
+
def maybe_cancel_timer
|
315
|
+
return if @timeout.nil?
|
316
|
+
timer = nil
|
317
|
+
if @timer
|
318
|
+
@lock.synchronize do
|
319
|
+
if @timer
|
320
|
+
timer = @timer
|
321
|
+
@timer = nil
|
322
|
+
end
|
323
|
+
end
|
324
|
+
end
|
325
|
+
@scheduler.cancel_timer(timer) if timer
|
326
|
+
end
|
275
327
|
end
|
276
328
|
|
277
329
|
def receive_data(data)
|
@@ -312,11 +364,7 @@ module Cassandra
|
|
312
364
|
@connection.write do |buffer|
|
313
365
|
@frame_encoder.encode(buffer, request_promise.request, id)
|
314
366
|
end
|
315
|
-
|
316
|
-
@scheduler.schedule_timer(request_promise.timeout).on_value do
|
317
|
-
request_promise.time_out!
|
318
|
-
end
|
319
|
-
end
|
367
|
+
request_promise.maybe_start_timer
|
320
368
|
end
|
321
369
|
|
322
370
|
def socket_closed(cause)
|