cassandra-driver 2.0.1-java → 2.1.0-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 +18 -9
- data/lib/cassandra.rb +5 -1
- 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/auth.rb +1 -1
- data/lib/cassandra/auth/providers.rb +1 -1
- data/lib/cassandra/auth/providers/password.rb +1 -1
- data/lib/cassandra/cluster.rb +1 -1
- data/lib/cassandra/cluster/client.rb +33 -13
- data/lib/cassandra/cluster/connection_pool.rb +1 -1
- data/lib/cassandra/cluster/connector.rb +1 -36
- data/lib/cassandra/cluster/control_connection.rb +85 -9
- data/lib/cassandra/cluster/failed_connection.rb +1 -1
- data/lib/cassandra/cluster/metadata.rb +1 -1
- data/lib/cassandra/cluster/options.rb +15 -4
- data/lib/cassandra/cluster/registry.rb +1 -1
- data/lib/cassandra/cluster/schema.rb +76 -16
- 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/cluster/schema/type_parser.rb +35 -8
- data/lib/cassandra/column.rb +10 -14
- 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/driver.rb +2 -2
- data/lib/cassandra/errors.rb +1 -1
- data/lib/cassandra/execution/info.rb +1 -1
- data/lib/cassandra/execution/options.rb +3 -2
- data/lib/cassandra/execution/trace.rb +1 -1
- data/lib/cassandra/executors.rb +1 -1
- data/lib/cassandra/future.rb +1 -1
- data/lib/cassandra/host.rb +1 -1
- data/lib/cassandra/keyspace.rb +55 -5
- 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/null_logger.rb +1 -1
- data/lib/cassandra/protocol.rb +6 -1
- data/lib/cassandra/protocol/coder.rb +319 -84
- data/lib/cassandra/protocol/cql_byte_buffer.rb +1 -1
- data/lib/cassandra/protocol/cql_protocol_handler.rb +24 -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 +5 -3
- 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/prepared_result_response.rb +1 -1
- data/lib/cassandra/protocol/responses/raw_rows_result_response.rb +9 -2
- 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 +21 -6
- data/lib/cassandra/protocol/responses/schema_change_result_response.rb +18 -8
- 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_timeout_error_response.rb +1 -1
- data/lib/cassandra/protocol/v1.rb +4 -2
- data/lib/cassandra/protocol/v3.rb +280 -0
- 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 +14 -80
- data/lib/cassandra/statement.rb +1 -1
- data/lib/cassandra/statements.rb +1 -1
- data/lib/cassandra/statements/batch.rb +10 -25
- data/lib/cassandra/statements/bound.rb +1 -1
- data/lib/cassandra/statements/prepared.rb +24 -31
- data/lib/cassandra/statements/simple.rb +22 -66
- data/lib/cassandra/statements/void.rb +1 -1
- data/lib/cassandra/table.rb +36 -5
- data/lib/cassandra/time_uuid.rb +1 -1
- data/lib/cassandra/tuple.rb +124 -0
- data/lib/cassandra/types.rb +1406 -0
- data/lib/cassandra/udt.rb +420 -0
- data/lib/cassandra/util.rb +42 -64
- data/lib/cassandra/uuid.rb +1 -1
- data/lib/cassandra/uuid/generator.rb +1 -1
- data/lib/cassandra/version.rb +2 -2
- metadata +38 -34
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
#--
|
4
|
-
# Copyright 2013-
|
4
|
+
# Copyright 2013-2015 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.
|
@@ -43,7 +43,7 @@ module Cassandra
|
|
43
43
|
buffer
|
44
44
|
end
|
45
45
|
|
46
|
-
def write_parameters(buffer, params, types)
|
46
|
+
def write_parameters(buffer, params, types, names = EMPTY_LIST)
|
47
47
|
Coder.write_values_v1(buffer, params, types)
|
48
48
|
end
|
49
49
|
end
|
@@ -156,6 +156,8 @@ module Cassandra
|
|
156
156
|
end
|
157
157
|
end
|
158
158
|
|
159
|
+
private
|
160
|
+
|
159
161
|
CODE_ERROR = 0x00
|
160
162
|
CODE_READY = 0x02
|
161
163
|
CODE_AUTHENTICATE = 0x03
|
@@ -0,0 +1,280 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#--
|
4
|
+
# Copyright 2013-2015 DataStax, Inc.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#++
|
18
|
+
|
19
|
+
module Cassandra
|
20
|
+
module Protocol
|
21
|
+
module V3
|
22
|
+
class Encoder
|
23
|
+
HEADER_FORMAT = 'c2ncN'.freeze
|
24
|
+
|
25
|
+
def initialize(compressor = nil, protocol_version = 3)
|
26
|
+
@compressor = compressor
|
27
|
+
@protocol_version = protocol_version
|
28
|
+
end
|
29
|
+
|
30
|
+
def encode(buffer, request, stream_id)
|
31
|
+
flags = request.trace? ? 2 : 0
|
32
|
+
body = request.write(CqlByteBuffer.new, @protocol_version, self)
|
33
|
+
|
34
|
+
if @compressor && request.compressable? && @compressor.compress?(body)
|
35
|
+
flags |= 1
|
36
|
+
body = @compressor.compress(body)
|
37
|
+
end
|
38
|
+
|
39
|
+
header = [@protocol_version, flags, stream_id, request.opcode, body.bytesize]
|
40
|
+
buffer << header.pack(HEADER_FORMAT)
|
41
|
+
buffer << body
|
42
|
+
|
43
|
+
buffer
|
44
|
+
end
|
45
|
+
|
46
|
+
def write_parameters(buffer, params, types, names = EMPTY_LIST)
|
47
|
+
Coder.write_values_v3(buffer, params, types, names)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class Decoder
|
52
|
+
def initialize(handler, compressor = nil)
|
53
|
+
@handler = handler
|
54
|
+
@compressor = compressor
|
55
|
+
@state = :initial
|
56
|
+
@header = nil
|
57
|
+
@version = nil
|
58
|
+
@code = nil
|
59
|
+
@length = nil
|
60
|
+
@buffer = CqlByteBuffer.new
|
61
|
+
end
|
62
|
+
|
63
|
+
def <<(data)
|
64
|
+
@buffer << data
|
65
|
+
|
66
|
+
__send__(:"decode_#{@state}", @buffer)
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
READY = ReadyResponse.new
|
72
|
+
|
73
|
+
def decode_initial(buffer)
|
74
|
+
return if buffer.length < 9
|
75
|
+
|
76
|
+
frame_header = buffer.read_int
|
77
|
+
protocol_version = (frame_header >> 24) & 0x7f
|
78
|
+
|
79
|
+
if protocol_version < 3
|
80
|
+
stream_id = (frame_header >> 8) & 0xff
|
81
|
+
stream_id = (stream_id & 0x7f) - (stream_id & 0x80)
|
82
|
+
|
83
|
+
@handler.complete_request(stream_id, ErrorResponse.new(0x000A, "Invalid or unsupported protocol version"))
|
84
|
+
|
85
|
+
return
|
86
|
+
end
|
87
|
+
|
88
|
+
@header = frame_header
|
89
|
+
@code = buffer.read_byte
|
90
|
+
@length = buffer.read_int
|
91
|
+
@state = :body
|
92
|
+
|
93
|
+
decode_body(buffer)
|
94
|
+
end
|
95
|
+
|
96
|
+
def decode_header(buffer)
|
97
|
+
buffer_length = buffer.length
|
98
|
+
|
99
|
+
while buffer_length >= 9
|
100
|
+
frame_header = buffer.read_int
|
101
|
+
frame_code = buffer.read_byte
|
102
|
+
frame_length = buffer.read_int
|
103
|
+
|
104
|
+
if (buffer_length - 9) < frame_length
|
105
|
+
@header = frame_header
|
106
|
+
@code = frame_code
|
107
|
+
@length = frame_length
|
108
|
+
@state = :body
|
109
|
+
|
110
|
+
return
|
111
|
+
end
|
112
|
+
|
113
|
+
actual_decode(buffer, frame_header, frame_length, frame_code)
|
114
|
+
buffer_length = buffer.length
|
115
|
+
end
|
116
|
+
|
117
|
+
nil
|
118
|
+
end
|
119
|
+
|
120
|
+
def decode_body(buffer)
|
121
|
+
frame_header = @header
|
122
|
+
frame_code = @code
|
123
|
+
frame_length = @length
|
124
|
+
buffer_length = buffer.length
|
125
|
+
|
126
|
+
until buffer_length < frame_length
|
127
|
+
actual_decode(buffer, frame_header, frame_length, frame_code)
|
128
|
+
buffer_length = buffer.length
|
129
|
+
|
130
|
+
if buffer_length < 9
|
131
|
+
@header = nil
|
132
|
+
@code = nil
|
133
|
+
@length = nil
|
134
|
+
@state = :header
|
135
|
+
|
136
|
+
return
|
137
|
+
end
|
138
|
+
|
139
|
+
frame_header = buffer.read_int
|
140
|
+
frame_code = buffer.read_byte
|
141
|
+
frame_length = buffer.read_int
|
142
|
+
buffer_length -= 8
|
143
|
+
end
|
144
|
+
|
145
|
+
@header = frame_header
|
146
|
+
@code = frame_code
|
147
|
+
@length = frame_length
|
148
|
+
|
149
|
+
nil
|
150
|
+
end
|
151
|
+
|
152
|
+
def actual_decode(buffer, fields, size, code)
|
153
|
+
protocol_version = (fields >> 24) & 0x7f
|
154
|
+
compression = (fields >> 16) & 0x01
|
155
|
+
tracing = (fields >> 16) & 0x02
|
156
|
+
stream_id = fields & 0xffff
|
157
|
+
stream_id = (stream_id & 0x7fff) - (stream_id & 0x8000)
|
158
|
+
opcode = code & 0xff
|
159
|
+
|
160
|
+
if compression == 1
|
161
|
+
if @compressor
|
162
|
+
buffer = CqlByteBuffer.new(@compressor.decompress(buffer.read(size)))
|
163
|
+
size = buffer.size
|
164
|
+
else
|
165
|
+
raise Errors::DecodingError, 'Compressed frame received, but no compressor configured'
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
if tracing == 2
|
170
|
+
trace_id = buffer.read_uuid
|
171
|
+
size -= 16
|
172
|
+
else
|
173
|
+
trace_id = nil
|
174
|
+
end
|
175
|
+
|
176
|
+
extra_length = buffer.length - size
|
177
|
+
response = decode_response(opcode, protocol_version, buffer, size, trace_id)
|
178
|
+
|
179
|
+
if buffer.length > extra_length
|
180
|
+
buffer.discard(buffer.length - extra_length)
|
181
|
+
end
|
182
|
+
|
183
|
+
if stream_id == -1
|
184
|
+
@handler.notify_event_listeners(response)
|
185
|
+
else
|
186
|
+
@handler.complete_request(stream_id, response)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
def decode_response(opcode, protocol_version, buffer, size, trace_id)
|
191
|
+
case opcode
|
192
|
+
when 0x00 # ERROR
|
193
|
+
code = buffer.read_int
|
194
|
+
message = buffer.read_string
|
195
|
+
|
196
|
+
case code
|
197
|
+
when 0x1000 then UnavailableErrorResponse.new(code, message, buffer.read_consistency, buffer.read_int, buffer.read_int)
|
198
|
+
when 0x1100 then WriteTimeoutErrorResponse.new(code, message, buffer.read_consistency, buffer.read_int, buffer.read_int, buffer.read_string)
|
199
|
+
when 0x1200 then ReadTimeoutErrorResponse.new(code, message, buffer.read_consistency, buffer.read_int, buffer.read_int, (buffer.read_byte != 0))
|
200
|
+
when 0x2400 then AlreadyExistsErrorResponse.new(code, message, buffer.read_string, buffer.read_string)
|
201
|
+
when 0x2500 then UnpreparedErrorResponse.new(code, message, buffer.read_short_bytes)
|
202
|
+
else
|
203
|
+
ErrorResponse.new(code, message)
|
204
|
+
end
|
205
|
+
when 0x02 # READY
|
206
|
+
READY
|
207
|
+
when 0x03 # AUTHENTICATE
|
208
|
+
AuthenticateResponse.new(buffer.read_string)
|
209
|
+
when 0x06 # SUPPORTED
|
210
|
+
SupportedResponse.new(buffer.read_string_multimap)
|
211
|
+
when 0x08 # RESULT
|
212
|
+
result_type = buffer.read_int
|
213
|
+
case result_type
|
214
|
+
when 0x0001 # Void
|
215
|
+
VoidResultResponse.new(trace_id)
|
216
|
+
when 0x0002 # Rows
|
217
|
+
original_buffer_length = buffer.length
|
218
|
+
column_specs, paging_state = Coder.read_metadata_v3(buffer)
|
219
|
+
|
220
|
+
if column_specs.nil?
|
221
|
+
consumed_bytes = original_buffer_length - buffer.length
|
222
|
+
remaining_bytes = CqlByteBuffer.new(buffer.read(size - consumed_bytes - 4))
|
223
|
+
RawRowsResultResponse.new(protocol_version, remaining_bytes, paging_state, trace_id)
|
224
|
+
else
|
225
|
+
RowsResultResponse.new(Coder.read_values_v3(buffer, column_specs), column_specs, paging_state, trace_id)
|
226
|
+
end
|
227
|
+
when 0x0003 # SetKeyspace
|
228
|
+
SetKeyspaceResultResponse.new(buffer.read_string, trace_id)
|
229
|
+
when 0x0004 # Prepared
|
230
|
+
id = buffer.read_short_bytes
|
231
|
+
params_metadata = Coder.read_metadata_v3(buffer).first
|
232
|
+
result_metadata = nil
|
233
|
+
result_metadata = Coder.read_metadata_v3(buffer).first if protocol_version > 1
|
234
|
+
|
235
|
+
PreparedResultResponse.new(id, params_metadata, result_metadata, trace_id)
|
236
|
+
when 0x0005 # SchemaChange
|
237
|
+
change = buffer.read_string
|
238
|
+
target = buffer.read_string
|
239
|
+
keyspace = buffer.read_string
|
240
|
+
|
241
|
+
if target == 'KEYSPACE'
|
242
|
+
SchemaChangeResultResponse.new(change, keyspace, nil, trace_id, target)
|
243
|
+
else
|
244
|
+
SchemaChangeResultResponse.new(change, keyspace, buffer.read_string, trace_id, target)
|
245
|
+
end
|
246
|
+
else
|
247
|
+
raise Errors::DecodingError, "Unsupported result type: #{result_type.inspect}"
|
248
|
+
end
|
249
|
+
when 0x0C # EVENT
|
250
|
+
event_type = buffer.read_string
|
251
|
+
case event_type
|
252
|
+
when 'SCHEMA_CHANGE'
|
253
|
+
change = buffer.read_string
|
254
|
+
target = buffer.read_string
|
255
|
+
keyspace = buffer.read_string
|
256
|
+
|
257
|
+
if target == 'KEYSPACE'
|
258
|
+
SchemaChangeEventResponse.new(change, keyspace, nil, target)
|
259
|
+
else
|
260
|
+
SchemaChangeEventResponse.new(change, keyspace, buffer.read_string, target)
|
261
|
+
end
|
262
|
+
when 'STATUS_CHANGE'
|
263
|
+
StatusChangeEventResponse.new(buffer.read_string, *buffer.read_inet)
|
264
|
+
when 'TOPOLOGY_CHANGE'
|
265
|
+
TopologyChangeEventResponse.new(buffer.read_string, *buffer.read_inet)
|
266
|
+
else
|
267
|
+
raise Errors::DecodingError, "Unsupported event type: #{event_type.inspect}"
|
268
|
+
end
|
269
|
+
when 0x0E # AUTH_CHALLENGE
|
270
|
+
AuthChallengeResponse.new(buffer.read_bytes)
|
271
|
+
when 0x10 # AUTH_SUCCESS
|
272
|
+
AuthSuccessResponse.new(buffer.read_bytes)
|
273
|
+
else
|
274
|
+
raise Errors::DecodingError, "Unsupported response opcode: #{opcode.inspect}"
|
275
|
+
end
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
end
|
280
|
+
end
|
data/lib/cassandra/result.rb
CHANGED
data/lib/cassandra/retry.rb
CHANGED