cassandra-driver 3.0.0.rc.1-java → 3.0.0.rc.2-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 +6 -1
- data/lib/cassandra.rb +74 -55
- data/lib/cassandra/attr_boolean.rb +33 -0
- data/lib/cassandra/auth.rb +2 -1
- data/lib/cassandra/auth/providers/password.rb +4 -16
- data/lib/cassandra/cluster/connector.rb +14 -4
- data/lib/cassandra/cluster/control_connection.rb +59 -67
- data/lib/cassandra/cluster/metadata.rb +1 -3
- data/lib/cassandra/cluster/options.rb +9 -10
- data/lib/cassandra/cluster/registry.rb +16 -5
- data/lib/cassandra/cluster/schema.rb +45 -1
- data/lib/cassandra/cluster/schema/fetchers.rb +475 -272
- data/lib/cassandra/cluster/schema/fqcn_type_parser.rb +2 -6
- data/lib/cassandra/cluster/schema/partitioners/murmur3.rb +5 -7
- data/lib/cassandra/column.rb +1 -20
- data/lib/cassandra/column_container.rb +322 -0
- data/lib/cassandra/compression/compressors/lz4.rb +3 -5
- data/lib/cassandra/driver.rb +1 -1
- data/lib/cassandra/errors.rb +38 -22
- data/lib/cassandra/execution/options.rb +4 -2
- data/lib/cassandra/future.rb +3 -9
- data/lib/cassandra/host.rb +16 -2
- data/lib/cassandra/index.rb +104 -0
- data/lib/cassandra/keyspace.rb +88 -9
- data/lib/cassandra/load_balancing/policies/dc_aware_round_robin.rb +6 -10
- data/lib/cassandra/materialized_view.rb +90 -0
- data/lib/cassandra/protocol/coder.rb +3 -3
- data/lib/cassandra/protocol/cql_byte_buffer.rb +12 -11
- data/lib/cassandra/protocol/cql_protocol_handler.rb +12 -8
- data/lib/cassandra/protocol/request.rb +4 -5
- data/lib/cassandra/protocol/requests/execute_request.rb +3 -5
- data/lib/cassandra/protocol/requests/query_request.rb +1 -1
- data/lib/cassandra/protocol/requests/startup_request.rb +6 -8
- data/lib/cassandra/protocol/response.rb +1 -2
- data/lib/cassandra/protocol/responses/auth_challenge_response.rb +3 -4
- data/lib/cassandra/protocol/responses/auth_success_response.rb +3 -4
- data/lib/cassandra/protocol/responses/authenticate_response.rb +3 -4
- data/lib/cassandra/protocol/responses/error_response.rb +3 -4
- data/lib/cassandra/protocol/responses/event_response.rb +2 -3
- data/lib/cassandra/protocol/responses/prepared_result_response.rb +3 -4
- data/lib/cassandra/protocol/responses/ready_response.rb +3 -4
- data/lib/cassandra/protocol/responses/result_response.rb +7 -8
- data/lib/cassandra/protocol/responses/rows_result_response.rb +3 -4
- data/lib/cassandra/protocol/responses/schema_change_event_response.rb +3 -4
- data/lib/cassandra/protocol/responses/schema_change_result_response.rb +3 -4
- data/lib/cassandra/protocol/responses/set_keyspace_result_response.rb +3 -4
- data/lib/cassandra/protocol/responses/status_change_event_response.rb +3 -4
- data/lib/cassandra/protocol/responses/supported_response.rb +3 -4
- data/lib/cassandra/protocol/responses/topology_change_event_response.rb +3 -4
- data/lib/cassandra/protocol/responses/void_result_response.rb +3 -4
- data/lib/cassandra/protocol/v1.rb +1 -5
- data/lib/cassandra/protocol/v3.rb +1 -3
- data/lib/cassandra/result.rb +2 -1
- data/lib/cassandra/retry/policies/downgrading_consistency.rb +1 -3
- data/lib/cassandra/statements/prepared.rb +3 -3
- data/lib/cassandra/table.rb +39 -220
- data/lib/cassandra/time_uuid.rb +5 -7
- data/lib/cassandra/tuple.rb +4 -12
- data/lib/cassandra/types.rb +92 -65
- data/lib/cassandra/udt.rb +34 -14
- data/lib/cassandra/uuid.rb +10 -18
- data/lib/cassandra/version.rb +1 -1
- data/lib/cassandra_murmur3.jar +0 -0
- metadata +8 -2
@@ -26,7 +26,7 @@ module Cassandra
|
|
26
26
|
NO_METADATA_FLAG = 0x04
|
27
27
|
|
28
28
|
def write_values_v4(buffer, values, types, names = EMPTY_LIST)
|
29
|
-
if values && values.
|
29
|
+
if values && !values.empty?
|
30
30
|
buffer.append_short(values.size)
|
31
31
|
values.zip(types, names) do |(value, type, name)|
|
32
32
|
buffer.append_string(name) if name
|
@@ -320,7 +320,7 @@ module Cassandra
|
|
320
320
|
end
|
321
321
|
|
322
322
|
def write_values_v3(buffer, values, types, names = EMPTY_LIST)
|
323
|
-
if values && values.
|
323
|
+
if values && !values.empty?
|
324
324
|
buffer.append_short(values.size)
|
325
325
|
values.zip(types, names) do |(value, type, name)|
|
326
326
|
buffer.append_string(name) if name
|
@@ -571,7 +571,7 @@ module Cassandra
|
|
571
571
|
end
|
572
572
|
|
573
573
|
def write_values_v1(buffer, values, types)
|
574
|
-
if values && values.
|
574
|
+
if values && !values.empty?
|
575
575
|
buffer.append_short(values.size)
|
576
576
|
values.each_with_index do |value, index|
|
577
577
|
write_value_v1(buffer, value, types[index])
|
@@ -19,6 +19,17 @@
|
|
19
19
|
module Cassandra
|
20
20
|
module Protocol
|
21
21
|
class CqlByteBuffer < Ione::ByteBuffer
|
22
|
+
# @private
|
23
|
+
MINUS = '-'.freeze
|
24
|
+
# @private
|
25
|
+
ZERO = '0'.freeze
|
26
|
+
# @private
|
27
|
+
DECIMAL_POINT = '.'.freeze
|
28
|
+
# @private
|
29
|
+
FLOAT_STRING_FORMAT = 'F'.freeze
|
30
|
+
# @private
|
31
|
+
NO_CHAR = ''.freeze
|
32
|
+
|
22
33
|
def inspect
|
23
34
|
"#<#{self.class.name}:0x#{object_id.to_s(16)} #{to_str.inspect}>"
|
24
35
|
end
|
@@ -291,9 +302,7 @@ module Cassandra
|
|
291
302
|
|
292
303
|
def append_consistency(consistency)
|
293
304
|
index = CONSISTENCIES.index(consistency)
|
294
|
-
if index.nil? || CONSISTENCIES[index].nil?
|
295
|
-
raise Errors::EncodingError, %(Unknown consistency "#{consistency}")
|
296
|
-
end
|
305
|
+
raise Errors::EncodingError, %(Unknown consistency "#{consistency}") if index.nil? || CONSISTENCIES[index].nil?
|
297
306
|
append_short(index)
|
298
307
|
end
|
299
308
|
|
@@ -360,14 +369,6 @@ module Cassandra
|
|
360
369
|
other.eql?(to_str)
|
361
370
|
end
|
362
371
|
alias == eql?
|
363
|
-
|
364
|
-
private
|
365
|
-
|
366
|
-
MINUS = '-'.freeze
|
367
|
-
ZERO = '0'.freeze
|
368
|
-
DECIMAL_POINT = '.'.freeze
|
369
|
-
FLOAT_STRING_FORMAT = 'F'.freeze
|
370
|
-
NO_CHAR = ''.freeze
|
371
372
|
end
|
372
373
|
end
|
373
374
|
end
|
@@ -32,7 +32,13 @@ module Cassandra
|
|
32
32
|
# puts "These options are supported: #{response.options}"
|
33
33
|
class CqlProtocolHandler
|
34
34
|
# @return [String] the current keyspace for the underlying connection
|
35
|
-
attr_reader :keyspace
|
35
|
+
attr_reader :keyspace
|
36
|
+
|
37
|
+
# @return [Exception] outstanding error, from a failed connection.
|
38
|
+
attr_reader :error
|
39
|
+
|
40
|
+
# @return [Integer] the version of the protocol to use in communicating with C*.
|
41
|
+
attr_reader :protocol_version
|
36
42
|
|
37
43
|
def initialize(connection,
|
38
44
|
scheduler,
|
@@ -41,6 +47,7 @@ module Cassandra
|
|
41
47
|
heartbeat_interval = 30,
|
42
48
|
idle_timeout = 60,
|
43
49
|
requests_per_connection = 128)
|
50
|
+
@protocol_version = protocol_version
|
44
51
|
@connection = connection
|
45
52
|
@scheduler = scheduler
|
46
53
|
@compressor = compressor
|
@@ -229,9 +236,7 @@ module Cassandra
|
|
229
236
|
ensure
|
230
237
|
@lock.unlock
|
231
238
|
end
|
232
|
-
if response.is_a?(Protocol::SetKeyspaceResultResponse)
|
233
|
-
@keyspace = response.keyspace
|
234
|
-
end
|
239
|
+
@keyspace = response.keyspace if response.is_a?(Protocol::SetKeyspaceResultResponse)
|
235
240
|
if response.is_a?(Protocol::SchemaChangeResultResponse) &&
|
236
241
|
response.change == 'DROPPED' &&
|
237
242
|
response.keyspace == @keyspace &&
|
@@ -246,7 +251,10 @@ module Cassandra
|
|
246
251
|
|
247
252
|
# @private
|
248
253
|
class RequestPromise < Ione::Promise
|
254
|
+
extend AttrBoolean
|
255
|
+
|
249
256
|
attr_reader :request, :timeout
|
257
|
+
attr_boolean :timed_out
|
250
258
|
|
251
259
|
def initialize(request, timeout)
|
252
260
|
@request = request
|
@@ -255,10 +263,6 @@ module Cassandra
|
|
255
263
|
super()
|
256
264
|
end
|
257
265
|
|
258
|
-
def timed_out?
|
259
|
-
@timed_out
|
260
|
-
end
|
261
|
-
|
262
266
|
def time_out!
|
263
267
|
unless future.completed?
|
264
268
|
@timed_out = true
|
@@ -19,17 +19,16 @@
|
|
19
19
|
module Cassandra
|
20
20
|
module Protocol
|
21
21
|
class Request
|
22
|
-
|
22
|
+
extend AttrBoolean
|
23
|
+
|
24
|
+
attr_reader :opcode
|
25
|
+
attr_boolean :trace
|
23
26
|
|
24
27
|
def initialize(opcode, trace = false)
|
25
28
|
@opcode = opcode
|
26
29
|
@trace = trace
|
27
30
|
end
|
28
31
|
|
29
|
-
def trace?
|
30
|
-
@trace
|
31
|
-
end
|
32
|
-
|
33
32
|
def compressable?
|
34
33
|
true
|
35
34
|
end
|
@@ -44,9 +44,7 @@ module Cassandra
|
|
44
44
|
unless serial_consistency.nil? || CONSISTENCIES.include?(serial_consistency)
|
45
45
|
raise ArgumentError, %(No such consistency: #{serial_consistency.inspect})
|
46
46
|
end
|
47
|
-
if paging_state && !page_size
|
48
|
-
raise ArgumentError, %(Paging state given but no page size)
|
49
|
-
end
|
47
|
+
raise ArgumentError, %(Paging state given but no page size) if paging_state && !page_size
|
50
48
|
super(10, trace)
|
51
49
|
@id = id
|
52
50
|
@metadata = metadata
|
@@ -69,14 +67,14 @@ module Cassandra
|
|
69
67
|
if protocol_version > 1
|
70
68
|
buffer.append_consistency(@consistency)
|
71
69
|
flags = 0
|
72
|
-
flags |= 0x01
|
70
|
+
flags |= 0x01 unless @values.empty?
|
73
71
|
flags |= 0x02 unless @request_metadata
|
74
72
|
flags |= 0x04 if @page_size
|
75
73
|
flags |= 0x08 if @paging_state
|
76
74
|
flags |= 0x10 if @serial_consistency
|
77
75
|
flags |= 0x20 if protocol_version > 2 && @timestamp
|
78
76
|
buffer.append(flags.chr)
|
79
|
-
encoder.write_parameters(buffer, @values, @metadata)
|
77
|
+
encoder.write_parameters(buffer, @values, @metadata) unless @values.empty?
|
80
78
|
buffer.append_int(@page_size) if @page_size
|
81
79
|
buffer.append_bytes(@paging_state) if @paging_state
|
82
80
|
buffer.append_consistency(@serial_consistency) if @serial_consistency
|
@@ -60,7 +60,7 @@ module Cassandra
|
|
60
60
|
flags |= 0x08 if @paging_state
|
61
61
|
flags |= 0x10 if @serial_consistency
|
62
62
|
flags |= 0x20 if protocol_version > 2 && @timestamp
|
63
|
-
if @values &&
|
63
|
+
if @values && !@values.empty?
|
64
64
|
flags |= 0x01
|
65
65
|
flags |= 0x40 if protocol_version > 2 && !@names.empty?
|
66
66
|
buffer.append(flags.chr)
|
@@ -19,13 +19,16 @@
|
|
19
19
|
module Cassandra
|
20
20
|
module Protocol
|
21
21
|
class StartupRequest < Request
|
22
|
+
# @private
|
23
|
+
CQL_VERSION = 'CQL_VERSION'.freeze
|
24
|
+
# @private
|
25
|
+
COMPRESSION = 'COMPRESSION'.freeze
|
26
|
+
|
22
27
|
attr_reader :options
|
23
28
|
|
24
29
|
def initialize(cql_version, compression = nil)
|
25
30
|
super(1)
|
26
|
-
unless cql_version
|
27
|
-
raise ArgumentError, "Invalid CQL version: #{cql_version.inspect}"
|
28
|
-
end
|
31
|
+
raise ArgumentError, "Invalid CQL version: #{cql_version.inspect}" unless cql_version
|
29
32
|
@options = {CQL_VERSION => cql_version}
|
30
33
|
@options[COMPRESSION] = compression if compression
|
31
34
|
end
|
@@ -41,11 +44,6 @@ module Cassandra
|
|
41
44
|
def to_s
|
42
45
|
%(STARTUP #{@options})
|
43
46
|
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
CQL_VERSION = 'CQL_VERSION'.freeze
|
48
|
-
COMPRESSION = 'COMPRESSION'.freeze
|
49
47
|
end
|
50
48
|
end
|
51
49
|
end
|
@@ -19,6 +19,9 @@
|
|
19
19
|
module Cassandra
|
20
20
|
module Protocol
|
21
21
|
class AuthChallengeResponse < Response
|
22
|
+
# @private
|
23
|
+
RESPONSE_TYPES[0x0e] = self
|
24
|
+
|
22
25
|
attr_reader :token
|
23
26
|
|
24
27
|
def initialize(token)
|
@@ -28,10 +31,6 @@ module Cassandra
|
|
28
31
|
def to_s
|
29
32
|
%(AUTH_CHALLENGE #{@token.bytesize})
|
30
33
|
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
RESPONSE_TYPES[0x0e] = self
|
35
34
|
end
|
36
35
|
end
|
37
36
|
end
|
@@ -19,6 +19,9 @@
|
|
19
19
|
module Cassandra
|
20
20
|
module Protocol
|
21
21
|
class AuthSuccessResponse < Response
|
22
|
+
# @private
|
23
|
+
RESPONSE_TYPES[0x10] = self
|
24
|
+
|
22
25
|
attr_reader :token
|
23
26
|
|
24
27
|
def initialize(token)
|
@@ -28,10 +31,6 @@ module Cassandra
|
|
28
31
|
def to_s
|
29
32
|
%(AUTH_SUCCESS #{@token && @token.bytesize})
|
30
33
|
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
RESPONSE_TYPES[0x10] = self
|
35
34
|
end
|
36
35
|
end
|
37
36
|
end
|
@@ -19,6 +19,9 @@
|
|
19
19
|
module Cassandra
|
20
20
|
module Protocol
|
21
21
|
class AuthenticateResponse < Response
|
22
|
+
# @private
|
23
|
+
RESPONSE_TYPES[0x03] = self
|
24
|
+
|
22
25
|
attr_reader :authentication_class
|
23
26
|
|
24
27
|
def initialize(authentication_class)
|
@@ -28,10 +31,6 @@ module Cassandra
|
|
28
31
|
def to_s
|
29
32
|
%(AUTHENTICATE #{authentication_class})
|
30
33
|
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
RESPONSE_TYPES[0x03] = self
|
35
34
|
end
|
36
35
|
end
|
37
36
|
end
|
@@ -19,6 +19,9 @@
|
|
19
19
|
module Cassandra
|
20
20
|
module Protocol
|
21
21
|
class ErrorResponse < Response
|
22
|
+
# @private
|
23
|
+
RESPONSE_TYPES[0x00] = self
|
24
|
+
|
22
25
|
attr_reader :code, :message, :custom_payload, :warnings
|
23
26
|
|
24
27
|
def initialize(*args)
|
@@ -134,10 +137,6 @@ module Cassandra
|
|
134
137
|
retries)
|
135
138
|
end
|
136
139
|
end
|
137
|
-
|
138
|
-
private
|
139
|
-
|
140
|
-
RESPONSE_TYPES[0x00] = self
|
141
140
|
end
|
142
141
|
end
|
143
142
|
end
|
@@ -19,6 +19,9 @@
|
|
19
19
|
module Cassandra
|
20
20
|
module Protocol
|
21
21
|
class PreparedResultResponse < ResultResponse
|
22
|
+
# @private
|
23
|
+
RESULT_TYPES[0x04] = self
|
24
|
+
|
22
25
|
attr_reader :id, :metadata, :result_metadata, :pk_idx
|
23
26
|
|
24
27
|
def initialize(custom_payload,
|
@@ -54,10 +57,6 @@ module Cassandra
|
|
54
57
|
hex_id = @id.each_byte.map { |x| x.to_s(16).rjust(2, '0') }.join('')
|
55
58
|
%(RESULT PREPARED #{hex_id} #{@metadata})
|
56
59
|
end
|
57
|
-
|
58
|
-
private
|
59
|
-
|
60
|
-
RESULT_TYPES[0x04] = self
|
61
60
|
end
|
62
61
|
end
|
63
62
|
end
|
@@ -19,6 +19,9 @@
|
|
19
19
|
module Cassandra
|
20
20
|
module Protocol
|
21
21
|
class ReadyResponse < Response
|
22
|
+
# @private
|
23
|
+
RESPONSE_TYPES[0x02] = self
|
24
|
+
|
22
25
|
def eql?(rs)
|
23
26
|
rs.is_a?(self.class)
|
24
27
|
end
|
@@ -35,10 +38,6 @@ module Cassandra
|
|
35
38
|
def to_s
|
36
39
|
'READY'
|
37
40
|
end
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
RESPONSE_TYPES[0x02] = self
|
42
41
|
end
|
43
42
|
end
|
44
43
|
end
|
@@ -19,6 +19,13 @@
|
|
19
19
|
module Cassandra
|
20
20
|
module Protocol
|
21
21
|
class ResultResponse < Response
|
22
|
+
# @private
|
23
|
+
RESPONSE_TYPES[0x08] = self
|
24
|
+
# @private
|
25
|
+
RESULT_TYPES = [
|
26
|
+
# populated by subclasses
|
27
|
+
]
|
28
|
+
|
22
29
|
attr_reader :custom_payload, :warnings, :trace_id
|
23
30
|
|
24
31
|
def initialize(custom_payload, warnings, trace_id)
|
@@ -30,14 +37,6 @@ module Cassandra
|
|
30
37
|
def void?
|
31
38
|
false
|
32
39
|
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
RESPONSE_TYPES[0x08] = self
|
37
|
-
|
38
|
-
RESULT_TYPES = [
|
39
|
-
# populated by subclasses
|
40
|
-
]
|
41
40
|
end
|
42
41
|
end
|
43
42
|
end
|
@@ -19,6 +19,9 @@
|
|
19
19
|
module Cassandra
|
20
20
|
module Protocol
|
21
21
|
class RowsResultResponse < ResultResponse
|
22
|
+
# @private
|
23
|
+
RESULT_TYPES[0x02] = self
|
24
|
+
|
22
25
|
attr_reader :rows, :metadata, :paging_state
|
23
26
|
|
24
27
|
def initialize(custom_payload, warnings, rows, metadata, paging_state, trace_id)
|
@@ -31,10 +34,6 @@ module Cassandra
|
|
31
34
|
def to_s
|
32
35
|
%(RESULT ROWS #{@metadata} #{@rows})
|
33
36
|
end
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
RESULT_TYPES[0x02] = self
|
38
37
|
end
|
39
38
|
end
|
40
39
|
end
|
@@ -21,6 +21,9 @@ module Cassandra
|
|
21
21
|
class SchemaChangeEventResponse < EventResponse
|
22
22
|
TYPE = 'SCHEMA_CHANGE'.freeze
|
23
23
|
|
24
|
+
# @private
|
25
|
+
EVENT_TYPES[TYPE] = self
|
26
|
+
|
24
27
|
attr_reader :change, :keyspace, :name, :target, :arguments
|
25
28
|
|
26
29
|
def initialize(change, keyspace, name, target, arguments)
|
@@ -65,10 +68,6 @@ module Cassandra
|
|
65
68
|
%(EVENT SCHEMA_CHANGE #{@change} #{@target} "#{@keyspace}" "#{@name}")
|
66
69
|
end
|
67
70
|
end
|
68
|
-
|
69
|
-
private
|
70
|
-
|
71
|
-
EVENT_TYPES[TYPE] = self
|
72
71
|
end
|
73
72
|
end
|
74
73
|
end
|
@@ -19,6 +19,9 @@
|
|
19
19
|
module Cassandra
|
20
20
|
module Protocol
|
21
21
|
class SchemaChangeResultResponse < ResultResponse
|
22
|
+
# @private
|
23
|
+
RESULT_TYPES[0x05] = self
|
24
|
+
|
22
25
|
attr_reader :arguments, :change, :keyspace, :name, :target, :type
|
23
26
|
|
24
27
|
def initialize(custom_payload,
|
@@ -62,10 +65,6 @@ module Cassandra
|
|
62
65
|
def to_s
|
63
66
|
%(RESULT SCHEMA_CHANGE #{@change} #{@target} "#{@keyspace}" "#{@name}")
|
64
67
|
end
|
65
|
-
|
66
|
-
private
|
67
|
-
|
68
|
-
RESULT_TYPES[0x05] = self
|
69
68
|
end
|
70
69
|
end
|
71
70
|
end
|