cassandra-driver 3.0.0.beta.1-java → 3.0.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 +106 -39
- data/lib/cassandra.rb +396 -148
- 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/attr_boolean.rb +33 -0
- data/lib/cassandra/auth.rb +6 -5
- data/lib/cassandra/auth/providers.rb +1 -1
- data/lib/cassandra/auth/providers/password.rb +5 -13
- data/lib/cassandra/cassandra_logger.rb +80 -0
- data/lib/cassandra/cluster.rb +49 -9
- data/lib/cassandra/cluster/client.rb +835 -209
- data/lib/cassandra/cluster/connection_pool.rb +2 -2
- data/lib/cassandra/cluster/connector.rb +86 -27
- data/lib/cassandra/cluster/control_connection.rb +222 -95
- data/lib/cassandra/cluster/failed_connection.rb +1 -1
- data/lib/cassandra/cluster/metadata.rb +14 -8
- data/lib/cassandra/cluster/options.rb +68 -22
- data/lib/cassandra/cluster/registry.rb +81 -17
- data/lib/cassandra/cluster/schema.rb +70 -8
- data/lib/cassandra/cluster/schema/cql_type_parser.rb +15 -10
- data/lib/cassandra/cluster/schema/fetchers.rb +601 -241
- data/lib/cassandra/cluster/schema/fqcn_type_parser.rb +39 -38
- data/lib/cassandra/cluster/schema/partitioners.rb +1 -1
- data/lib/cassandra/cluster/schema/partitioners/murmur3.rb +6 -8
- 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 +4 -23
- data/lib/cassandra/column_container.rb +322 -0
- data/lib/cassandra/compression.rb +1 -1
- data/lib/cassandra/compression/compressors/lz4.rb +7 -8
- data/lib/cassandra/compression/compressors/snappy.rb +4 -3
- data/lib/cassandra/driver.rb +107 -46
- data/lib/cassandra/errors.rb +303 -52
- data/lib/cassandra/execution/info.rb +16 -5
- data/lib/cassandra/execution/options.rb +102 -55
- 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 +101 -49
- data/lib/cassandra/host.rb +25 -5
- data/lib/cassandra/index.rb +118 -0
- data/lib/cassandra/keyspace.rb +169 -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 +39 -25
- data/lib/cassandra/load_balancing/policies/round_robin.rb +8 -1
- data/lib/cassandra/load_balancing/policies/token_aware.rb +22 -13
- data/lib/cassandra/load_balancing/policies/white_list.rb +18 -5
- data/lib/cassandra/materialized_view.rb +90 -0
- data/lib/cassandra/null_logger.rb +27 -6
- data/lib/cassandra/protocol.rb +1 -1
- data/lib/cassandra/protocol/coder.rb +81 -42
- data/lib/cassandra/protocol/cql_byte_buffer.rb +58 -44
- data/lib/cassandra/protocol/cql_protocol_handler.rb +57 -54
- data/lib/cassandra/protocol/request.rb +6 -7
- data/lib/cassandra/protocol/requests/auth_response_request.rb +3 -3
- data/lib/cassandra/protocol/requests/batch_request.rb +17 -8
- data/lib/cassandra/protocol/requests/credentials_request.rb +3 -3
- data/lib/cassandra/protocol/requests/execute_request.rb +39 -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 +28 -23
- data/lib/cassandra/protocol/requests/register_request.rb +2 -2
- data/lib/cassandra/protocol/requests/startup_request.rb +8 -8
- data/lib/cassandra/protocol/requests/void_query_request.rb +1 -1
- data/lib/cassandra/protocol/response.rb +3 -4
- data/lib/cassandra/protocol/responses/already_exists_error_response.rb +12 -2
- data/lib/cassandra/protocol/responses/auth_challenge_response.rb +4 -5
- data/lib/cassandra/protocol/responses/auth_success_response.rb +4 -5
- data/lib/cassandra/protocol/responses/authenticate_response.rb +4 -5
- data/lib/cassandra/protocol/responses/error_response.rb +104 -17
- data/lib/cassandra/protocol/responses/event_response.rb +3 -4
- data/lib/cassandra/protocol/responses/function_failure_error_response.rb +13 -2
- data/lib/cassandra/protocol/responses/prepared_result_response.rb +14 -9
- 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 +6 -7
- data/lib/cassandra/protocol/responses/result_response.rb +11 -10
- data/lib/cassandra/protocol/responses/rows_result_response.rb +8 -7
- data/lib/cassandra/protocol/responses/schema_change_event_response.rb +8 -8
- data/lib/cassandra/protocol/responses/schema_change_result_response.rb +19 -13
- data/lib/cassandra/protocol/responses/set_keyspace_result_response.rb +5 -6
- data/lib/cassandra/protocol/responses/status_change_event_response.rb +5 -6
- data/lib/cassandra/protocol/responses/supported_response.rb +4 -5
- data/lib/cassandra/protocol/responses/topology_change_event_response.rb +4 -5
- 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 +4 -5
- 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 +98 -37
- data/lib/cassandra/protocol/v3.rb +121 -50
- 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 +55 -20
- 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 +4 -2
- data/lib/cassandra/retry/policies/fallthrough.rb +1 -1
- data/lib/cassandra/session.rb +24 -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 +62 -18
- data/lib/cassandra/statements/simple.rb +23 -10
- data/lib/cassandra/statements/void.rb +1 -1
- data/lib/cassandra/table.rb +53 -185
- data/lib/cassandra/time.rb +11 -6
- data/lib/cassandra/time_uuid.rb +12 -14
- data/lib/cassandra/timestamp_generator.rb +37 -0
- data/lib/cassandra/timestamp_generator/simple.rb +38 -0
- data/lib/cassandra/timestamp_generator/ticking_on_duplicate.rb +58 -0
- data/lib/cassandra/tuple.rb +4 -4
- data/lib/cassandra/types.rb +109 -71
- data/lib/cassandra/udt.rb +66 -50
- data/lib/cassandra/util.rb +155 -15
- data/lib/cassandra/uuid.rb +20 -21
- data/lib/cassandra/uuid/generator.rb +7 -5
- data/lib/cassandra/version.rb +2 -2
- data/lib/cassandra_murmur3.jar +0 -0
- data/lib/datastax/cassandra.rb +1 -1
- metadata +27 -16
@@ -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.
|
@@ -26,31 +26,31 @@ module Cassandra
|
|
26
26
|
Result = Struct.new(:results, :collections)
|
27
27
|
|
28
28
|
@@types = {
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
29
|
+
'org.apache.cassandra.db.marshal.AsciiType' => :ascii,
|
30
|
+
'org.apache.cassandra.db.marshal.LongType' => :bigint,
|
31
|
+
'org.apache.cassandra.db.marshal.BytesType' => :blob,
|
32
|
+
'org.apache.cassandra.db.marshal.BooleanType' => :boolean,
|
33
|
+
'org.apache.cassandra.db.marshal.CounterColumnType' => :counter,
|
34
|
+
'org.apache.cassandra.db.marshal.DecimalType' => :decimal,
|
35
|
+
'org.apache.cassandra.db.marshal.DoubleType' => :double,
|
36
|
+
'org.apache.cassandra.db.marshal.FloatType' => :float,
|
37
|
+
'org.apache.cassandra.db.marshal.InetAddressType' => :inet,
|
38
|
+
'org.apache.cassandra.db.marshal.Int32Type' => :int,
|
39
|
+
'org.apache.cassandra.db.marshal.UTF8Type' => :text,
|
40
|
+
'org.apache.cassandra.db.marshal.TimestampType' => :timestamp,
|
41
|
+
'org.apache.cassandra.db.marshal.DateType' => :timestamp,
|
42
|
+
'org.apache.cassandra.db.marshal.UUIDType' => :uuid,
|
43
|
+
'org.apache.cassandra.db.marshal.IntegerType' => :varint,
|
44
|
+
'org.apache.cassandra.db.marshal.TimeUUIDType' => :timeuuid,
|
45
|
+
'org.apache.cassandra.db.marshal.MapType' => :map,
|
46
|
+
'org.apache.cassandra.db.marshal.SetType' => :set,
|
47
|
+
'org.apache.cassandra.db.marshal.ListType' => :list,
|
48
|
+
'org.apache.cassandra.db.marshal.UserType' => :udt,
|
49
|
+
'org.apache.cassandra.db.marshal.TupleType' => :tuple,
|
50
|
+
'org.apache.cassandra.db.marshal.ShortType' => :smallint,
|
51
|
+
'org.apache.cassandra.db.marshal.ByteType' => :tinyint,
|
52
|
+
'org.apache.cassandra.db.marshal.TimeType' => :time,
|
53
|
+
'org.apache.cassandra.db.marshal.SimpleDateType' => :date
|
54
54
|
}.freeze
|
55
55
|
|
56
56
|
def parse(string)
|
@@ -63,15 +63,16 @@ module Cassandra
|
|
63
63
|
collections = nil
|
64
64
|
results = []
|
65
65
|
|
66
|
-
if node.name ==
|
66
|
+
if node.name == 'org.apache.cassandra.db.marshal.CompositeType'
|
67
67
|
collections = {}
|
68
68
|
|
69
|
-
if node.children.last.name ==
|
69
|
+
if node.children.last.name ==
|
70
|
+
'org.apache.cassandra.db.marshal.ColumnToCollectionType'
|
70
71
|
node.children.pop.children.each do |child|
|
71
|
-
key, name = child.name.split(
|
72
|
+
key, name = child.name.split(':')
|
72
73
|
key = [key].pack('H*').force_encoding(::Encoding::UTF_8)
|
73
74
|
|
74
|
-
if name ==
|
75
|
+
if name == 'org.apache.cassandra.db.marshal.ReversedType'
|
75
76
|
collections[key] = lookup_type(child.children.first)
|
76
77
|
else
|
77
78
|
child.name = name
|
@@ -94,12 +95,12 @@ module Cassandra
|
|
94
95
|
order = :asc
|
95
96
|
frozen = false
|
96
97
|
|
97
|
-
if node.name ==
|
98
|
+
if node.name == 'org.apache.cassandra.db.marshal.ReversedType'
|
98
99
|
order = :desc
|
99
100
|
node = node.children.first
|
100
101
|
end
|
101
102
|
|
102
|
-
if node.name ==
|
103
|
+
if node.name == 'org.apache.cassandra.db.marshal.FrozenType'
|
103
104
|
frozen = true
|
104
105
|
node = node.children.first
|
105
106
|
end
|
@@ -108,11 +109,11 @@ module Cassandra
|
|
108
109
|
end
|
109
110
|
|
110
111
|
def lookup_type(node)
|
111
|
-
if node.name ==
|
112
|
-
return lookup_type(node.children.first)
|
113
|
-
end
|
112
|
+
return lookup_type(node.children.first) if node.name == 'org.apache.cassandra.db.marshal.FrozenType'
|
114
113
|
|
115
|
-
type = @@types.fetch(node.name)
|
114
|
+
type = @@types.fetch(node.name) do
|
115
|
+
return Cassandra::Types.custom(dump_node(node))
|
116
|
+
end
|
116
117
|
|
117
118
|
case type
|
118
119
|
when :set, :list
|
@@ -123,7 +124,7 @@ module Cassandra
|
|
123
124
|
keyspace = node.children.shift.name
|
124
125
|
name = [node.children.shift.name].pack('H*')
|
125
126
|
fields = node.children.map do |child|
|
126
|
-
field_name, child_name = child.name.split(
|
127
|
+
field_name, child_name = child.name.split(':')
|
127
128
|
|
128
129
|
child.name = child_name
|
129
130
|
field_name = [field_name].pack('H*').force_encoding(::Encoding::UTF_8)
|
@@ -166,7 +167,7 @@ module Cassandra
|
|
166
167
|
|
167
168
|
def dump_node(node)
|
168
169
|
str = node.name
|
169
|
-
str << '(' + node.children.map {|n| dump_node(n)}.join(',') + ')' unless node.children.empty?
|
170
|
+
str << '(' + node.children.map { |n| dump_node(n) }.join(',') + ')' unless node.children.empty?
|
170
171
|
str
|
171
172
|
end
|
172
173
|
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.
|
@@ -23,6 +23,11 @@ module Cassandra
|
|
23
23
|
module Partitioners
|
24
24
|
# @private
|
25
25
|
class Murmur3
|
26
|
+
# @private
|
27
|
+
LONG_MIN = -2**63
|
28
|
+
# @private
|
29
|
+
LONG_MAX = 2**63 - 1
|
30
|
+
|
26
31
|
def create_token(partition_key)
|
27
32
|
token = Cassandra::Murmur3.hash(partition_key)
|
28
33
|
token = LONG_MAX if token == LONG_MIN
|
@@ -33,13 +38,6 @@ module Cassandra
|
|
33
38
|
def parse_token(token_string)
|
34
39
|
token_string.to_i
|
35
40
|
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
# @private
|
40
|
-
LONG_MIN = -2 ** 63
|
41
|
-
# @private
|
42
|
-
LONG_MAX = 2 ** 63 - 1
|
43
41
|
end
|
44
42
|
end
|
45
43
|
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,7 +34,7 @@ module Cassandra
|
|
34
34
|
racks[host.datacenter] ||= ::Set.new
|
35
35
|
racks[host.datacenter].add(host.rack)
|
36
36
|
|
37
|
-
datacenter_token_rings[host.datacenter] ||=
|
37
|
+
datacenter_token_rings[host.datacenter] ||= {}
|
38
38
|
datacenter_token_rings[host.datacenter][i] = token
|
39
39
|
end
|
40
40
|
|
@@ -48,8 +48,11 @@ module Cassandra
|
|
48
48
|
replication_options.each do |datacenter, factor|
|
49
49
|
ring = datacenter_token_rings[datacenter]
|
50
50
|
next unless ring
|
51
|
-
factor =
|
52
|
-
|
51
|
+
factor = begin
|
52
|
+
[Integer(factor), ring.size].min
|
53
|
+
rescue
|
54
|
+
next
|
55
|
+
end
|
53
56
|
|
54
57
|
total_racks = racks[datacenter].size
|
55
58
|
visited_racks = visited[datacenter] ||= ::Set.new
|
@@ -68,21 +71,19 @@ module Cassandra
|
|
68
71
|
if rack.nil? || visited_racks.size == total_racks
|
69
72
|
replicas << host
|
70
73
|
added_replicas << host
|
74
|
+
elsif visited_racks.include?(rack)
|
75
|
+
skipped_hosts << host
|
71
76
|
else
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
replicas << skipped_host
|
84
|
-
added_replicas << host
|
85
|
-
end
|
77
|
+
replicas << host
|
78
|
+
visited_racks << rack
|
79
|
+
added_replicas << host
|
80
|
+
|
81
|
+
if visited_racks.size == total_racks
|
82
|
+
skipped_hosts.each do |skipped_host|
|
83
|
+
break if added_replicas.size >= factor
|
84
|
+
|
85
|
+
replicas << skipped_host
|
86
|
+
added_replicas << host
|
86
87
|
end
|
87
88
|
end
|
88
89
|
end
|
data/lib/cassandra/column.rb
CHANGED
@@ -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,36 +21,18 @@ module Cassandra
|
|
21
21
|
# @see Cassandra::Table#each_column
|
22
22
|
# @see Cassandra::Table#column
|
23
23
|
class Column
|
24
|
-
# @private
|
25
|
-
class Index
|
26
|
-
# @return [String] index name
|
27
|
-
attr_reader :name
|
28
|
-
# @return [String] custom index class name
|
29
|
-
attr_reader :custom_class_name
|
30
|
-
|
31
|
-
# @private
|
32
|
-
def initialize(name, custom_class_name = nil)
|
33
|
-
@name = name
|
34
|
-
@custom_class_name = custom_class_name
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
24
|
# @return [String] column name
|
39
25
|
attr_reader :name
|
40
26
|
# @return [Cassandra::Type] column type
|
41
27
|
attr_reader :type
|
42
28
|
# @return [Symbol] column order (`:asc` or `:desc`)
|
43
29
|
attr_reader :order
|
44
|
-
# @private
|
45
|
-
# @return [Cassandra::Column::Index, nil] column index
|
46
|
-
attr_reader :index
|
47
30
|
|
48
31
|
# @private
|
49
|
-
def initialize(name, type, order,
|
32
|
+
def initialize(name, type, order, is_static = false, is_frozen = false)
|
50
33
|
@name = name
|
51
34
|
@type = type
|
52
35
|
@order = order
|
53
|
-
@index = index
|
54
36
|
@static = is_static
|
55
37
|
@frozen = is_frozen
|
56
38
|
end
|
@@ -67,7 +49,7 @@ module Cassandra
|
|
67
49
|
|
68
50
|
# @private
|
69
51
|
def inspect
|
70
|
-
"#<#{self.class.name}:0x#{
|
52
|
+
"#<#{self.class.name}:0x#{object_id.to_s(16)} @name=#{@name} @type=#{@type}>"
|
71
53
|
end
|
72
54
|
|
73
55
|
# @private
|
@@ -76,10 +58,9 @@ module Cassandra
|
|
76
58
|
@name == other.name &&
|
77
59
|
@type == other.type &&
|
78
60
|
@order == other.order &&
|
79
|
-
@index == other.index &&
|
80
61
|
@static == other.static? &&
|
81
62
|
@frozen == other.frozen?
|
82
63
|
end
|
83
|
-
alias
|
64
|
+
alias == eql?
|
84
65
|
end
|
85
66
|
end
|
@@ -0,0 +1,322 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#--
|
4
|
+
# Copyright 2013-2016 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
|
+
# This class contains all the logic needed for manipulating columns of an object.
|
21
|
+
class ColumnContainer
|
22
|
+
# Encapsulates all of the configuration options of a column-container.
|
23
|
+
class Options
|
24
|
+
# @return [String] the comment attribute of this column-container.
|
25
|
+
attr_reader :comment
|
26
|
+
# @return [Float] the chance with which a read repair is triggered for this column-container.
|
27
|
+
attr_reader :read_repair_chance
|
28
|
+
# @return [Float] the cluster local read repair chance for this column-container.
|
29
|
+
attr_reader :local_read_repair_chance
|
30
|
+
# @return [Integer] the tombstone garbage collection grace time in seconds for this column-container.
|
31
|
+
attr_reader :gc_grace_seconds
|
32
|
+
# @return [Hash] the caching options for this column-container.
|
33
|
+
attr_reader :caching
|
34
|
+
# @return [Float] the false positive chance for the Bloom filter of this column-container.
|
35
|
+
attr_reader :bloom_filter_fp_chance
|
36
|
+
# @return [Integer] how often (in milliseconds) to flush the memtable of this column-container.
|
37
|
+
attr_reader :memtable_flush_period_in_ms
|
38
|
+
# @return [Integer] the default TTL for this column-container.
|
39
|
+
attr_reader :default_time_to_live
|
40
|
+
# Return the speculative retry setting of this column-container, which determines how much
|
41
|
+
# response delay the coordinator node will tolerate from the chosen replica before
|
42
|
+
# retrying the request on other replicas. This setting can be expressed as a fixed
|
43
|
+
# delay in ms (e.g. 10ms) or as a percentile indicating "when the response time has
|
44
|
+
# exceeded the Nth percentile of read response times for this object" (e.g. 99percentile).
|
45
|
+
# @return [String] the speculative retry setting of this column-container.
|
46
|
+
attr_reader :speculative_retry
|
47
|
+
# Return the index interval of this column-container; Cassandra will hold `1/index_interval` of row keys in
|
48
|
+
# memory.
|
49
|
+
# @return [Integer] the index interval of this column-container. May be nil, indicating a default value of 128.
|
50
|
+
attr_reader :index_interval
|
51
|
+
# @return [Hash] compression settings
|
52
|
+
attr_reader :compression
|
53
|
+
# When compression is enabled, this option defines the probability
|
54
|
+
# with which checksums for compressed blocks are checked during reads.
|
55
|
+
# @return [Float] the probability of checking checksums on compressed blocks.
|
56
|
+
attr_reader :crc_check_chance
|
57
|
+
# @return [Hash] the extension options of this column-container.
|
58
|
+
attr_reader :extensions
|
59
|
+
|
60
|
+
# @return [ColumnContainer::Compaction] the compaction strategy of this column-container.
|
61
|
+
attr_reader :compaction_strategy
|
62
|
+
|
63
|
+
# @private
|
64
|
+
# rubocop:disable Metrics/ParameterLists
|
65
|
+
def initialize(comment,
|
66
|
+
read_repair_chance,
|
67
|
+
local_read_repair_chance,
|
68
|
+
gc_grace_seconds,
|
69
|
+
caching,
|
70
|
+
bloom_filter_fp_chance,
|
71
|
+
populate_io_cache_on_flush,
|
72
|
+
memtable_flush_period_in_ms,
|
73
|
+
default_time_to_live,
|
74
|
+
speculative_retry,
|
75
|
+
index_interval,
|
76
|
+
replicate_on_write,
|
77
|
+
min_index_interval,
|
78
|
+
max_index_interval,
|
79
|
+
compaction_strategy,
|
80
|
+
compression,
|
81
|
+
compact_storage,
|
82
|
+
crc_check_chance,
|
83
|
+
extensions)
|
84
|
+
@comment = comment
|
85
|
+
@read_repair_chance = read_repair_chance
|
86
|
+
@local_read_repair_chance = local_read_repair_chance
|
87
|
+
@gc_grace_seconds = gc_grace_seconds
|
88
|
+
@caching = caching
|
89
|
+
@bloom_filter_fp_chance = bloom_filter_fp_chance
|
90
|
+
@populate_io_cache_on_flush = populate_io_cache_on_flush
|
91
|
+
@memtable_flush_period_in_ms = memtable_flush_period_in_ms
|
92
|
+
@default_time_to_live = default_time_to_live
|
93
|
+
@speculative_retry = speculative_retry
|
94
|
+
@index_interval = index_interval
|
95
|
+
@replicate_on_write = replicate_on_write
|
96
|
+
@min_index_interval = min_index_interval
|
97
|
+
@max_index_interval = max_index_interval
|
98
|
+
@compaction_strategy = compaction_strategy
|
99
|
+
@compression = compression
|
100
|
+
@compact_storage = compact_storage
|
101
|
+
@crc_check_chance = crc_check_chance
|
102
|
+
@extensions = extensions
|
103
|
+
end
|
104
|
+
|
105
|
+
# Return whether to replicate counter updates to other replicas. It is *strongly* recommended
|
106
|
+
# that this setting be `true`. Otherwise, counter updates are only written to one replica
|
107
|
+
# and fault tolerance is sacrificed.
|
108
|
+
# @return [Boolean] whether to replicate counter updates to other replicas.
|
109
|
+
def replicate_on_write?
|
110
|
+
@replicate_on_write
|
111
|
+
end
|
112
|
+
|
113
|
+
# @return [Boolean] whether to populate the I/O cache on flush of this
|
114
|
+
# column-container. May be nil, indicating a default value of `false`.
|
115
|
+
def populate_io_cache_on_flush?
|
116
|
+
@populate_io_cache_on_flush
|
117
|
+
end
|
118
|
+
|
119
|
+
# @return [Boolean] whether this column-container uses compact storage.
|
120
|
+
def compact_storage?
|
121
|
+
@compact_storage
|
122
|
+
end
|
123
|
+
|
124
|
+
# @private
|
125
|
+
def to_cql
|
126
|
+
options = []
|
127
|
+
|
128
|
+
options << 'COMPACT STORAGE' if @compact_storage
|
129
|
+
unless @bloom_filter_fp_chance.nil?
|
130
|
+
options << "bloom_filter_fp_chance = #{Util.encode_object(@bloom_filter_fp_chance)}"
|
131
|
+
end
|
132
|
+
options << "caching = #{Util.encode_object(@caching)}" unless @caching.nil?
|
133
|
+
options << "comment = #{Util.encode_object(@comment)}" unless @comment.nil?
|
134
|
+
options << "compaction = #{@compaction_strategy.to_cql}" unless @compaction_strategy.nil?
|
135
|
+
options << "compression = #{Util.encode_object(@compression)}" unless @compression.nil?
|
136
|
+
options << "crc_check_chance = #{Util.encode_object(@crc_check_chance)}" unless @crc_check_chance.nil?
|
137
|
+
unless @local_read_repair_chance.nil?
|
138
|
+
options << "dclocal_read_repair_chance = #{Util.encode_object(@local_read_repair_chance)}"
|
139
|
+
end
|
140
|
+
unless @default_time_to_live.nil?
|
141
|
+
options << "default_time_to_live = #{Util.encode_object(@default_time_to_live)}"
|
142
|
+
end
|
143
|
+
options << "gc_grace_seconds = #{Util.encode_object(@gc_grace_seconds)}" unless @gc_grace_seconds.nil?
|
144
|
+
options << "index_interval = #{Util.encode_object(@index_interval)}" unless @index_interval.nil?
|
145
|
+
options << "max_index_interval = #{Util.encode_object(@max_index_interval)}" unless @max_index_interval.nil?
|
146
|
+
unless @memtable_flush_period_in_ms.nil?
|
147
|
+
options << "memtable_flush_period_in_ms = #{Util.encode_object(@memtable_flush_period_in_ms)}"
|
148
|
+
end
|
149
|
+
options << "min_index_interval = #{Util.encode_object(@min_index_interval)}" unless @min_index_interval.nil?
|
150
|
+
unless @populate_io_cache_on_flush.nil?
|
151
|
+
options << "populate_io_cache_on_flush = '#{@populate_io_cache_on_flush}'"
|
152
|
+
end
|
153
|
+
options << "read_repair_chance = #{Util.encode_object(@read_repair_chance)}" unless @read_repair_chance.nil?
|
154
|
+
options << "replicate_on_write = '#{@replicate_on_write}'" unless @replicate_on_write.nil?
|
155
|
+
options << "speculative_retry = #{Util.encode_object(@speculative_retry)}" unless @speculative_retry.nil?
|
156
|
+
|
157
|
+
options.join("\nAND ")
|
158
|
+
end
|
159
|
+
|
160
|
+
# @private
|
161
|
+
def eql?(other)
|
162
|
+
other.is_a?(Options) &&
|
163
|
+
@comment == other.comment &&
|
164
|
+
@read_repair_chance == other.read_repair_chance &&
|
165
|
+
@local_read_repair_chance == other.local_read_repair_chance &&
|
166
|
+
@gc_grace_seconds == other.gc_grace_seconds &&
|
167
|
+
@caching == other.caching &&
|
168
|
+
@bloom_filter_fp_chance == other.bloom_filter_fp_chance &&
|
169
|
+
@populate_io_cache_on_flush == other.populate_io_cache_on_flush? &&
|
170
|
+
@memtable_flush_period_in_ms == other.memtable_flush_period_in_ms &&
|
171
|
+
@default_time_to_live == other.default_time_to_live &&
|
172
|
+
@speculative_retry == other.speculative_retry &&
|
173
|
+
@index_interval == other.index_interval &&
|
174
|
+
@replicate_on_write == other.replicate_on_write? &&
|
175
|
+
@compaction_strategy == other.compaction_strategy &&
|
176
|
+
@compression == other.compression &&
|
177
|
+
@compact_storage == other.compact_storage? &&
|
178
|
+
@crc_check_chance == other.crc_check_chance &&
|
179
|
+
@extensions == other.extensions
|
180
|
+
end
|
181
|
+
alias == eql?
|
182
|
+
end
|
183
|
+
|
184
|
+
# Encapsulates the compaction strategy of a column-container.
|
185
|
+
class Compaction
|
186
|
+
# @return [String] the name of the Cassandra class that performs compaction.
|
187
|
+
attr_reader :class_name
|
188
|
+
# @return [Hash] compaction strategy options
|
189
|
+
attr_reader :options
|
190
|
+
|
191
|
+
# @private
|
192
|
+
def initialize(class_name, options)
|
193
|
+
@class_name = class_name
|
194
|
+
@options = options
|
195
|
+
end
|
196
|
+
|
197
|
+
# @private
|
198
|
+
def to_cql
|
199
|
+
compaction = {'class' => @class_name}
|
200
|
+
compaction.merge!(@options)
|
201
|
+
|
202
|
+
Util.encode_hash(compaction)
|
203
|
+
end
|
204
|
+
|
205
|
+
# @private
|
206
|
+
def eql?(other)
|
207
|
+
other.is_a?(Compaction) &&
|
208
|
+
@class_name == other.class_name &&
|
209
|
+
@options == other.options
|
210
|
+
end
|
211
|
+
alias == eql?
|
212
|
+
end
|
213
|
+
|
214
|
+
# @return [String] name of this column-container
|
215
|
+
attr_reader :name
|
216
|
+
# @return [Cassandra::Uuid] the id of this object in Cassandra.
|
217
|
+
attr_reader :id
|
218
|
+
# @return [Cassandra::Keyspace] the keyspace that this column-container belongs to.
|
219
|
+
attr_reader :keyspace
|
220
|
+
# @return [ColumnContainer::Options] collection of configuration options of this column-container.
|
221
|
+
attr_reader :options
|
222
|
+
# @return [Array<Cassandra::Column>] ordered list of column-names that make up the partition-key.
|
223
|
+
attr_reader :partition_key
|
224
|
+
# @return [Array<Cassandra::Column>] ordered list of column-names that make up the clustering-columns.
|
225
|
+
attr_reader :clustering_columns
|
226
|
+
# @return [Array<Cassandra::Column>] primary key of this column-container. It's the combination of
|
227
|
+
# `partition_key` and `clustering_columns`.
|
228
|
+
# @note This composition produces a flat list, so it will not be possible for the caller to distinguish
|
229
|
+
# partition-key columns from clustering-columns.
|
230
|
+
attr_reader :primary_key
|
231
|
+
|
232
|
+
# @private
|
233
|
+
def initialize(keyspace,
|
234
|
+
name,
|
235
|
+
partition_key,
|
236
|
+
clustering_columns,
|
237
|
+
other_columns,
|
238
|
+
options,
|
239
|
+
id)
|
240
|
+
@keyspace = keyspace
|
241
|
+
@name = name.freeze
|
242
|
+
@partition_key = partition_key.freeze
|
243
|
+
@clustering_columns = clustering_columns.freeze
|
244
|
+
@options = options
|
245
|
+
@id = id
|
246
|
+
|
247
|
+
# Make one array of all the columns, ordered with partition key, clustering
|
248
|
+
# columns, then other columns. Make a hash as well, to support random access
|
249
|
+
# to column metadata for a given column name. Save off the primary key (which
|
250
|
+
# is partition-key + clustering-columns) while we're at it.
|
251
|
+
|
252
|
+
@primary_key = @partition_key.dup.concat(@clustering_columns).freeze
|
253
|
+
@columns = @primary_key.dup.concat(other_columns).freeze
|
254
|
+
@columns_hash = @columns.each_with_object({}) do |col, h|
|
255
|
+
h[col.name] = col
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
# @param name [String] column name
|
260
|
+
# @return [Boolean] whether this column-container has a given column
|
261
|
+
def has_column?(name)
|
262
|
+
@columns_hash.key?(name)
|
263
|
+
end
|
264
|
+
|
265
|
+
# @param name [String] column name
|
266
|
+
# @return [Cassandra::Column, nil] a column or nil
|
267
|
+
def column(name)
|
268
|
+
@columns_hash[name]
|
269
|
+
end
|
270
|
+
|
271
|
+
# Yield or enumerate each column defined in this column-container
|
272
|
+
# @overload each_column
|
273
|
+
# @yieldparam column [Cassandra::Column] current column
|
274
|
+
# @return [Cassandra::ColumnContainer] self
|
275
|
+
# @overload each_column
|
276
|
+
# @return [Array<Cassandra::Column>] a list of columns
|
277
|
+
def each_column(&block)
|
278
|
+
if block_given?
|
279
|
+
@columns.each(&block)
|
280
|
+
self
|
281
|
+
else
|
282
|
+
@columns
|
283
|
+
end
|
284
|
+
end
|
285
|
+
alias columns each_column
|
286
|
+
|
287
|
+
# @private
|
288
|
+
# keyspace attribute may be nil because when this object was constructed, we didn't have
|
289
|
+
# its keyspace constructed yet. So allow updating @keyspace if it's nil, thus
|
290
|
+
# allowing fetchers to create keyspace, table/view, and hook them together without
|
291
|
+
# worrying about chickens and eggs.
|
292
|
+
# NOTE: Ignore the set request if the @keyspace is already set.
|
293
|
+
# rubocop:disable Style/AccessorMethodName
|
294
|
+
def set_keyspace(keyspace)
|
295
|
+
@keyspace = keyspace unless @keyspace
|
296
|
+
end
|
297
|
+
|
298
|
+
# @private
|
299
|
+
def inspect
|
300
|
+
"#<#{self.class.name}:0x#{object_id.to_s(16)} " \
|
301
|
+
"@keyspace=#{@keyspace.name} @name=#{@name}>"
|
302
|
+
end
|
303
|
+
|
304
|
+
# @private
|
305
|
+
def eql?(other)
|
306
|
+
other.is_a?(ColumnContainer) &&
|
307
|
+
@keyspace == other.keyspace &&
|
308
|
+
@name == other.name &&
|
309
|
+
@partition_key == other.partition_key &&
|
310
|
+
@clustering_columns == other.clustering_columns &&
|
311
|
+
@columns == other.raw_columns &&
|
312
|
+
@options == other.options
|
313
|
+
end
|
314
|
+
alias == eql?
|
315
|
+
|
316
|
+
# @private
|
317
|
+
def raw_columns
|
318
|
+
@columns
|
319
|
+
end
|
320
|
+
protected :raw_columns
|
321
|
+
end
|
322
|
+
end
|