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.
|
@@ -20,7 +20,7 @@ module Cassandra
|
|
20
20
|
module Protocol
|
21
21
|
class CqlByteBuffer < Ione::ByteBuffer
|
22
22
|
def inspect
|
23
|
-
"#<#{self.class.name}:0x#{
|
23
|
+
"#<#{self.class.name}:0x#{object_id.to_s(16)} #{to_str.inspect}>"
|
24
24
|
end
|
25
25
|
|
26
26
|
def read_unsigned_byte
|
@@ -28,22 +28,20 @@ module Cassandra
|
|
28
28
|
rescue RangeError => e
|
29
29
|
raise Errors::DecodingError, e.message, e.backtrace
|
30
30
|
end
|
31
|
-
|
32
|
-
def read_varint(len=bytesize, signed=true)
|
31
|
+
|
32
|
+
def read_varint(len = bytesize, signed = true)
|
33
33
|
bytes = read(len)
|
34
34
|
n = 0
|
35
35
|
bytes.each_byte do |b|
|
36
36
|
n = (n << 8) | b
|
37
37
|
end
|
38
|
-
if signed && bytes.getbyte(0) & 0x80 == 0x80
|
39
|
-
n -= 2**(bytes.length * 8)
|
40
|
-
end
|
38
|
+
n -= 2**(bytes.length * 8) if signed && bytes.getbyte(0) & 0x80 == 0x80
|
41
39
|
n
|
42
40
|
rescue RangeError => e
|
43
41
|
raise Errors::DecodingError, e.message, e.backtrace
|
44
42
|
end
|
45
43
|
|
46
|
-
def read_decimal(len=bytesize)
|
44
|
+
def read_decimal(len = bytesize)
|
47
45
|
size = read_signed_int
|
48
46
|
number_string = read_varint(len - 4).to_s
|
49
47
|
if number_string.length <= size
|
@@ -58,7 +56,8 @@ module Cassandra
|
|
58
56
|
else
|
59
57
|
fraction_string = number_string[0, number_string.length - size]
|
60
58
|
fraction_string << DECIMAL_POINT
|
61
|
-
fraction_string <<
|
59
|
+
fraction_string <<
|
60
|
+
number_string[number_string.length - size, number_string.length]
|
62
61
|
end
|
63
62
|
BigDecimal.new(fraction_string)
|
64
63
|
rescue Errors::DecodingError => e
|
@@ -78,13 +77,15 @@ module Cassandra
|
|
78
77
|
def read_double
|
79
78
|
read(8).unpack(Formats::DOUBLE_FORMAT).first
|
80
79
|
rescue RangeError => e
|
81
|
-
raise Errors::DecodingError,
|
80
|
+
raise Errors::DecodingError,
|
81
|
+
"Not enough bytes available to decode a double: #{e.message}", e.backtrace
|
82
82
|
end
|
83
83
|
|
84
84
|
def read_float
|
85
85
|
read(4).unpack(Formats::FLOAT_FORMAT).first
|
86
86
|
rescue RangeError => e
|
87
|
-
raise Errors::DecodingError,
|
87
|
+
raise Errors::DecodingError,
|
88
|
+
"Not enough bytes available to decode a float: #{e.message}", e.backtrace
|
88
89
|
end
|
89
90
|
|
90
91
|
def read_signed_int
|
@@ -92,13 +93,15 @@ module Cassandra
|
|
92
93
|
return n if n <= 0x7fffffff
|
93
94
|
n - 0xffffffff - 1
|
94
95
|
rescue RangeError => e
|
95
|
-
raise Errors::DecodingError,
|
96
|
+
raise Errors::DecodingError,
|
97
|
+
"Not enough bytes available to decode an int: #{e.message}", e.backtrace
|
96
98
|
end
|
97
|
-
|
99
|
+
|
98
100
|
def read_unsigned_short
|
99
101
|
read_short
|
100
102
|
rescue RangeError => e
|
101
|
-
raise Errors::DecodingError,
|
103
|
+
raise Errors::DecodingError,
|
104
|
+
"Not enough bytes available to decode a short: #{e.message}", e.backtrace
|
102
105
|
end
|
103
106
|
|
104
107
|
def read_string
|
@@ -107,7 +110,8 @@ module Cassandra
|
|
107
110
|
string.force_encoding(::Encoding::UTF_8)
|
108
111
|
string
|
109
112
|
rescue RangeError => e
|
110
|
-
raise Errors::DecodingError,
|
113
|
+
raise Errors::DecodingError,
|
114
|
+
"Not enough bytes available to decode a string: #{e.message}", e.backtrace
|
111
115
|
end
|
112
116
|
|
113
117
|
def read_long_string
|
@@ -116,13 +120,16 @@ module Cassandra
|
|
116
120
|
string.force_encoding(::Encoding::UTF_8)
|
117
121
|
string
|
118
122
|
rescue RangeError => e
|
119
|
-
raise Errors::DecodingError,
|
123
|
+
raise Errors::DecodingError,
|
124
|
+
"Not enough bytes available to decode a long string: #{e.message}",
|
125
|
+
e.backtrace
|
120
126
|
end
|
121
127
|
|
122
|
-
def read_uuid(impl=Uuid)
|
128
|
+
def read_uuid(impl = Uuid)
|
123
129
|
impl.new(read_varint(16, false))
|
124
130
|
rescue Errors::DecodingError => e
|
125
|
-
raise Errors::DecodingError,
|
131
|
+
raise Errors::DecodingError,
|
132
|
+
"Not enough bytes available to decode a UUID: #{e.message}", e.backtrace
|
126
133
|
end
|
127
134
|
|
128
135
|
def read_string_list
|
@@ -135,21 +142,22 @@ module Cassandra
|
|
135
142
|
return nil if size & 0x80000000 == 0x80000000
|
136
143
|
read(size)
|
137
144
|
rescue RangeError => e
|
138
|
-
raise Errors::DecodingError,
|
145
|
+
raise Errors::DecodingError,
|
146
|
+
"Not enough bytes available to decode a bytes: #{e.message}", e.backtrace
|
139
147
|
end
|
140
148
|
|
141
149
|
def read_short_bytes
|
142
150
|
read(read_unsigned_short)
|
143
151
|
rescue RangeError => e
|
144
|
-
raise Errors::DecodingError,
|
152
|
+
raise Errors::DecodingError,
|
153
|
+
"Not enough bytes available to decode a short bytes: #{e.message}",
|
154
|
+
e.backtrace
|
145
155
|
end
|
146
156
|
|
147
157
|
def read_option
|
148
158
|
id = read_unsigned_short
|
149
159
|
value = nil
|
150
|
-
if block_given?
|
151
|
-
value = yield id, self
|
152
|
-
end
|
160
|
+
value = yield id, self if block_given?
|
153
161
|
[id, value]
|
154
162
|
end
|
155
163
|
|
@@ -159,12 +167,16 @@ module Cassandra
|
|
159
167
|
port = read_int
|
160
168
|
[ip_addr, port]
|
161
169
|
rescue RangeError => e
|
162
|
-
raise Errors::DecodingError,
|
170
|
+
raise Errors::DecodingError,
|
171
|
+
"Not enough bytes available to decode an INET: #{e.message}",
|
172
|
+
e.backtrace
|
163
173
|
end
|
164
174
|
|
165
175
|
def read_consistency
|
166
176
|
index = read_unsigned_short
|
167
|
-
|
177
|
+
if index >= CONSISTENCIES.size || CONSISTENCIES[index].nil?
|
178
|
+
raise Errors::DecodingError, "Unknown consistency index #{index}"
|
179
|
+
end
|
168
180
|
CONSISTENCIES[index]
|
169
181
|
end
|
170
182
|
|
@@ -203,7 +215,8 @@ module Cassandra
|
|
203
215
|
return n if n <= 0x7fff
|
204
216
|
n - 0xffff - 1
|
205
217
|
rescue RangeError => e
|
206
|
-
raise Errors::DecodingError,
|
218
|
+
raise Errors::DecodingError,
|
219
|
+
"Not enough bytes available to decode a smallint: #{e.message}", e.backtrace
|
207
220
|
end
|
208
221
|
|
209
222
|
def read_tinyint
|
@@ -211,7 +224,8 @@ module Cassandra
|
|
211
224
|
return n if n <= 0x7f
|
212
225
|
n - 0xff - 1
|
213
226
|
rescue RangeError => e
|
214
|
-
raise Errors::DecodingError,
|
227
|
+
raise Errors::DecodingError,
|
228
|
+
"Not enough bytes available to decode a tinyint: #{e.message}", e.backtrace
|
215
229
|
end
|
216
230
|
|
217
231
|
def append_tinyint(n)
|
@@ -246,7 +260,7 @@ module Cassandra
|
|
246
260
|
append_int((v >> 96) & 0xffffffff)
|
247
261
|
append_int((v >> 64) & 0xffffffff)
|
248
262
|
append_int((v >> 32) & 0xffffffff)
|
249
|
-
append_int((v >>
|
263
|
+
append_int((v >> 0) & 0xffffffff)
|
250
264
|
end
|
251
265
|
|
252
266
|
def append_string_list(strs)
|
@@ -277,7 +291,9 @@ module Cassandra
|
|
277
291
|
|
278
292
|
def append_consistency(consistency)
|
279
293
|
index = CONSISTENCIES.index(consistency)
|
280
|
-
|
294
|
+
if index.nil? || CONSISTENCIES[index].nil?
|
295
|
+
raise Errors::EncodingError, %(Unknown consistency "#{consistency}")
|
296
|
+
end
|
281
297
|
append_short(index)
|
282
298
|
end
|
283
299
|
|
@@ -313,10 +329,11 @@ module Cassandra
|
|
313
329
|
def append_varint(n)
|
314
330
|
num = n
|
315
331
|
bytes = []
|
316
|
-
|
332
|
+
loop do
|
317
333
|
bytes << (num & 0xff)
|
318
334
|
num >>= 8
|
319
|
-
|
335
|
+
break if (num == 0 || num == -1) && (bytes.last[7] == num[7])
|
336
|
+
end
|
320
337
|
append(bytes.reverse.pack(Formats::BYTES_FORMAT))
|
321
338
|
end
|
322
339
|
|
@@ -342,7 +359,7 @@ module Cassandra
|
|
342
359
|
def eql?(other)
|
343
360
|
other.eql?(to_str)
|
344
361
|
end
|
345
|
-
|
362
|
+
alias == eql?
|
346
363
|
|
347
364
|
private
|
348
365
|
|
@@ -353,4 +370,4 @@ module Cassandra
|
|
353
370
|
NO_CHAR = ''.freeze
|
354
371
|
end
|
355
372
|
end
|
356
|
-
end
|
373
|
+
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.
|
@@ -34,20 +34,22 @@ module Cassandra
|
|
34
34
|
# @return [String] the current keyspace for the underlying connection
|
35
35
|
attr_reader :keyspace, :error
|
36
36
|
|
37
|
-
def initialize(connection,
|
37
|
+
def initialize(connection,
|
38
|
+
scheduler,
|
39
|
+
protocol_version,
|
40
|
+
compressor = nil,
|
41
|
+
heartbeat_interval = 30,
|
42
|
+
idle_timeout = 60,
|
43
|
+
requests_per_connection = 128)
|
38
44
|
@connection = connection
|
39
45
|
@scheduler = scheduler
|
40
46
|
@compressor = compressor
|
41
47
|
@connection.on_data(&method(:receive_data))
|
42
48
|
@connection.on_closed(&method(:socket_closed))
|
43
49
|
|
44
|
-
|
45
|
-
@streams = Array.new(1024) {|i| i}
|
46
|
-
else
|
47
|
-
@streams = Array.new(128) {|i| i}
|
48
|
-
end
|
50
|
+
@streams = Array.new(requests_per_connection) {|i| i}
|
49
51
|
|
50
|
-
@promises =
|
52
|
+
@promises = {}
|
51
53
|
|
52
54
|
if protocol_version > 3
|
53
55
|
@frame_encoder = V4::Encoder.new(@compressor, protocol_version)
|
@@ -147,20 +149,20 @@ module Cassandra
|
|
147
149
|
# closes the futures of all active requests will be failed with the error
|
148
150
|
# that caused the connection to close, or nil.
|
149
151
|
#
|
150
|
-
# When `timeout` is specified the future will fail with
|
151
|
-
# after that many seconds have passed. If a
|
152
|
-
# time it will be lost. If a response never arrives
|
153
|
-
# channel occupied by the request will _not_ be reused.
|
152
|
+
# When `timeout` is specified the future will fail with
|
153
|
+
# {Cassandra::Errors::TimeoutError} after that many seconds have passed. If a
|
154
|
+
# response arrives after that time it will be lost. If a response never arrives
|
155
|
+
# for the request the channel occupied by the request will _not_ be reused.
|
154
156
|
#
|
155
157
|
# @param [Cassandra::Protocol::Request] request
|
156
158
|
# @param [Float] timeout an optional number of seconds to wait until
|
157
159
|
# failing the request
|
158
160
|
# @return [Ione::Future<Cassandra::Protocol::Response>] a future that resolves to
|
159
161
|
# the response
|
160
|
-
def send_request(request, timeout=nil, with_heartbeat = true)
|
162
|
+
def send_request(request, timeout = nil, with_heartbeat = true)
|
161
163
|
return Ione::Future.failed(Errors::IOError.new('Connection closed')) if closed?
|
162
164
|
schedule_heartbeat if with_heartbeat
|
163
|
-
promise = RequestPromise.new(request)
|
165
|
+
promise = RequestPromise.new(request, timeout)
|
164
166
|
id = nil
|
165
167
|
@lock.lock
|
166
168
|
begin
|
@@ -171,9 +173,7 @@ module Cassandra
|
|
171
173
|
@lock.unlock
|
172
174
|
end
|
173
175
|
if id
|
174
|
-
|
175
|
-
@frame_encoder.encode(buffer, request, id)
|
176
|
-
end
|
176
|
+
write_request(id, promise)
|
177
177
|
else
|
178
178
|
@lock.lock
|
179
179
|
begin
|
@@ -182,11 +182,6 @@ module Cassandra
|
|
182
182
|
@lock.unlock
|
183
183
|
end
|
184
184
|
end
|
185
|
-
if timeout
|
186
|
-
@scheduler.schedule_timer(timeout).on_value do
|
187
|
-
promise.time_out!
|
188
|
-
end
|
189
|
-
end
|
190
185
|
promise.future
|
191
186
|
end
|
192
187
|
|
@@ -237,23 +232,25 @@ module Cassandra
|
|
237
232
|
if response.is_a?(Protocol::SetKeyspaceResultResponse)
|
238
233
|
@keyspace = response.keyspace
|
239
234
|
end
|
240
|
-
if response.is_a?(Protocol::SchemaChangeResultResponse) &&
|
235
|
+
if response.is_a?(Protocol::SchemaChangeResultResponse) &&
|
236
|
+
response.change == 'DROPPED' &&
|
237
|
+
response.keyspace == @keyspace &&
|
238
|
+
response.target == Protocol::Constants::SCHEMA_CHANGE_TARGET_KEYSPACE
|
241
239
|
@keyspace = nil
|
242
240
|
end
|
243
241
|
flush_request_queue
|
244
|
-
unless promise.timed_out?
|
245
|
-
promise.fulfill(response)
|
246
|
-
end
|
242
|
+
promise.fulfill(response) unless promise.timed_out?
|
247
243
|
end
|
248
244
|
|
249
245
|
private
|
250
246
|
|
251
247
|
# @private
|
252
248
|
class RequestPromise < Ione::Promise
|
253
|
-
attr_reader :request
|
249
|
+
attr_reader :request, :timeout
|
254
250
|
|
255
|
-
def initialize(request)
|
251
|
+
def initialize(request, timeout)
|
256
252
|
@request = request
|
253
|
+
@timeout = timeout
|
257
254
|
@timed_out = false
|
258
255
|
super()
|
259
256
|
end
|
@@ -265,7 +262,9 @@ module Cassandra
|
|
265
262
|
def time_out!
|
266
263
|
unless future.completed?
|
267
264
|
@timed_out = true
|
265
|
+
# rubocop:disable Style/SignalException
|
268
266
|
fail(Errors::TimeoutError.new('Timed out'))
|
267
|
+
# rubocop:enable Style/SignalException
|
269
268
|
end
|
270
269
|
end
|
271
270
|
end
|
@@ -285,28 +284,32 @@ module Cassandra
|
|
285
284
|
ensure
|
286
285
|
@lock.unlock
|
287
286
|
end
|
288
|
-
|
287
|
+
loop do
|
289
288
|
id = nil
|
290
289
|
promise = nil
|
291
290
|
@lock.lock
|
292
291
|
begin
|
293
292
|
if @request_queue_out.any? && (id = next_stream_id)
|
294
293
|
promise = @request_queue_out.shift
|
295
|
-
if promise.timed_out?
|
296
|
-
|
297
|
-
else
|
298
|
-
@promises[id] = promise
|
299
|
-
end
|
294
|
+
next if promise.timed_out?
|
295
|
+
@promises[id] = promise
|
300
296
|
end
|
301
297
|
ensure
|
302
298
|
@lock.unlock
|
303
299
|
end
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
300
|
+
|
301
|
+
break unless id
|
302
|
+
write_request(id, promise)
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
def write_request(id, request_promise)
|
307
|
+
@connection.write do |buffer|
|
308
|
+
@frame_encoder.encode(buffer, request_promise.request, id)
|
309
|
+
end
|
310
|
+
if request_promise.timeout
|
311
|
+
@scheduler.schedule_timer(request_promise.timeout).on_value do
|
312
|
+
request_promise.time_out!
|
310
313
|
end
|
311
314
|
end
|
312
315
|
end
|
@@ -382,11 +385,7 @@ module Cassandra
|
|
382
385
|
end
|
383
386
|
|
384
387
|
def next_stream_id
|
385
|
-
|
386
|
-
stream_id
|
387
|
-
else
|
388
|
-
nil
|
389
|
-
end
|
388
|
+
@streams.shift
|
390
389
|
end
|
391
390
|
|
392
391
|
HEARTBEAT = OptionsRequest.new
|
@@ -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.
|
@@ -21,7 +21,7 @@ module Cassandra
|
|
21
21
|
class Request
|
22
22
|
attr_reader :opcode, :trace
|
23
23
|
|
24
|
-
def initialize(opcode, trace=false)
|
24
|
+
def initialize(opcode, trace = false)
|
25
25
|
@opcode = opcode
|
26
26
|
@trace = trace
|
27
27
|
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.
|
@@ -35,9 +35,9 @@ module Cassandra
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def eql?(other)
|
38
|
-
|
38
|
+
token == other.token
|
39
39
|
end
|
40
|
-
|
40
|
+
alias == eql?
|
41
41
|
|
42
42
|
def hash
|
43
43
|
@h ||= begin
|