sessionm-cassandra_object 2.5.8 → 2.5.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/cassandra_object/associations/one_to_many.rb +1 -1
- data/lib/cassandra_object/associations/one_to_one.rb +3 -3
- data/lib/cassandra_object/associations.rb +1 -1
- data/lib/cassandra_object/connection.rb +52 -101
- data/lib/cassandra_object/cursor.rb +1 -1
- data/lib/cassandra_object/finder_methods.rb +6 -6
- data/lib/cassandra_object/persistence.rb +7 -7
- data/sessionm-cassandra_object.gemspec +1 -1
- metadata +3 -3
@@ -19,7 +19,7 @@ module CassandraObject
|
|
19
19
|
def add(owner, record, set_inverse = true)
|
20
20
|
key = owner.key
|
21
21
|
attributes = {@association_name=>{new_key=>record.key.to_s}}
|
22
|
-
CassandraObject::Base.with_connection(key) do
|
22
|
+
CassandraObject::Base.with_connection(key, :write) do
|
23
23
|
ActiveSupport::Notifications.instrument("insert.cassandra_object", :column_family => column_family, :key => key, :attributes => attributes) do
|
24
24
|
connection.insert(column_family, key.to_s, attributes, :consistency => @owner_class.thrift_write_consistency)
|
25
25
|
end
|
@@ -24,7 +24,7 @@ module CassandraObject
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def clear(owner)
|
27
|
-
CassandraObject::Base.with_connection(owner.key) do
|
27
|
+
CassandraObject::Base.with_connection(owner.key, :write) do
|
28
28
|
ActiveSupport::Notifications.instrument("remove.cassandra_object", :column_family => column_family, :key => owner.key, :columns => @association_name) do
|
29
29
|
connection.remove(column_family, owner.key.to_s, @association_name)
|
30
30
|
end
|
@@ -32,7 +32,7 @@ module CassandraObject
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def find(owner)
|
35
|
-
CassandraObject::Base.with_connection(owner.key.to_s) do
|
35
|
+
CassandraObject::Base.with_connection(owner.key.to_s, :read) do
|
36
36
|
if key = connection.get(column_family, owner.key.to_s, @association_name.to_s, :count=>1).values.first
|
37
37
|
target_class.get(key)
|
38
38
|
else
|
@@ -45,7 +45,7 @@ module CassandraObject
|
|
45
45
|
clear(owner)
|
46
46
|
key = owner.key
|
47
47
|
attributes = {@association_name=>{new_key=>record.key.to_s}}
|
48
|
-
CassandraObject::Base.with_connection(key) do
|
48
|
+
CassandraObject::Base.with_connection(key, :write) do
|
49
49
|
ActiveSupport::Notifications.instrument("insert.cassandra_object", :column_family => column_family, :key => key, :attributes => attributes) do
|
50
50
|
connection.insert(column_family, key.to_s, attributes, :consistency => @owner_class.thrift_write_consistency)
|
51
51
|
end
|
@@ -38,7 +38,7 @@ module CassandraObject
|
|
38
38
|
|
39
39
|
def remove(key)
|
40
40
|
begin
|
41
|
-
CassandraObject::Base.with_connection(key) do
|
41
|
+
CassandraObject::Base.with_connection(key, :write) do
|
42
42
|
ActiveSupport::Notifications.instrument("remove.cassandra_object", column_family: relationships_column_family, key: key) do
|
43
43
|
connection.remove(relationships_column_family, key.to_s, consistency: thrift_write_consistency)
|
44
44
|
end
|
@@ -8,36 +8,17 @@ module CassandraObject
|
|
8
8
|
class_attribute :connection_spec
|
9
9
|
|
10
10
|
class_eval do
|
11
|
-
|
11
|
+
|
12
|
+
@@schema = nil
|
13
|
+
def self.new_connection(async, servers)
|
12
14
|
spec = connection_spec.dup
|
13
|
-
|
14
|
-
require 'thrift_client/event_machine'
|
15
|
-
spec[:thrift].merge!(:transport => Thrift::EventMachineTransport,
|
16
|
-
:transport_wrapper => nil)
|
17
|
-
|
18
|
-
Cassandra.new(spec[:keyspace], servers || spec[:servers], spec[:thrift]).tap do |conn|
|
19
|
-
conn.disable_node_auto_discovery! if spec[:disable_node_auto_discovery]
|
20
|
-
if spec[:cache_schema]
|
21
|
-
if @@schema
|
22
|
-
conn.instance_variable_set '@schema', @@schema
|
23
|
-
else
|
24
|
-
begin
|
25
|
-
@@schema = conn.schema
|
26
|
-
rescue CassandraThrift::InvalidRequestException => e
|
27
|
-
# initially the schema doesn't exists
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
15
|
|
34
|
-
|
35
|
-
|
36
|
-
|
16
|
+
if async
|
17
|
+
require 'thrift_client/event_machine'
|
18
|
+
spec[:thrift].merge!(:transport => Thrift::EventMachineTransport,
|
19
|
+
:transport_wrapper => nil)
|
20
|
+
end
|
37
21
|
|
38
|
-
def self.new_connection(servers=nil)
|
39
|
-
spec = connection_spec.dup
|
40
|
-
|
41
22
|
Cassandra.new(spec[:keyspace], servers || spec[:servers], spec[:thrift]).tap do |conn|
|
42
23
|
conn.disable_node_auto_discovery! if spec[:disable_node_auto_discovery]
|
43
24
|
if spec[:cache_schema]
|
@@ -54,43 +35,33 @@ module CassandraObject
|
|
54
35
|
end
|
55
36
|
end
|
56
37
|
|
57
|
-
def
|
58
|
-
|
38
|
+
def self.new_async_connection(servers=nil)
|
39
|
+
new_connection true, servers
|
59
40
|
end
|
60
41
|
|
61
|
-
|
62
|
-
|
63
|
-
@@sync_connection_pool = nil
|
64
|
-
def self.async_connection_pool
|
65
|
-
@@async_connection_pool ||=
|
66
|
-
begin
|
67
|
-
adapter_method = Proc.new do
|
68
|
-
self.new_event_machine_connection
|
69
|
-
end
|
70
|
-
spec = ActiveRecord::Base::ConnectionSpecification.new self.connection_spec, adapter_method
|
71
|
-
WithConnection::ConnectionPool.new "async cassandra", spec
|
72
|
-
end
|
73
|
-
end
|
74
|
-
def async_connection_pool
|
75
|
-
self.class.async_connection_pool
|
42
|
+
def self.new_sync_connection(servers=nil)
|
43
|
+
new_connection false, servers
|
76
44
|
end
|
77
45
|
|
78
|
-
def self.
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
spec = ActiveRecord::Base::ConnectionSpecification.new self.connection_spec, adapter_method
|
85
|
-
WithConnection::ConnectionPool.new "sync cassandra", spec
|
86
|
-
end
|
46
|
+
def self.new_async_connection_pool(servers=nil)
|
47
|
+
adapter_method = Proc.new do
|
48
|
+
self.new_async_connection servers
|
49
|
+
end
|
50
|
+
spec = ActiveRecord::Base::ConnectionSpecification.new self.connection_spec, adapter_method
|
51
|
+
WithConnection::ConnectionPool.new "async cassandra", spec
|
87
52
|
end
|
88
|
-
|
89
|
-
|
53
|
+
|
54
|
+
def self.new_sync_connection_pool(servers=nil)
|
55
|
+
adapter_method = Proc.new do
|
56
|
+
self.new_sync_connection servers
|
57
|
+
end
|
58
|
+
spec = ActiveRecord::Base::ConnectionSpecification.new self.connection_spec, adapter_method
|
59
|
+
WithConnection::ConnectionPool.new "sync cassandra", spec
|
90
60
|
end
|
91
61
|
|
62
|
+
@@ring = nil
|
92
63
|
def self.ring
|
93
|
-
self.
|
64
|
+
@@ring ||= self.new_sync_connection.ring
|
94
65
|
end
|
95
66
|
|
96
67
|
def self.servers_and_ranges(datacenter)
|
@@ -104,55 +75,35 @@ module CassandraObject
|
|
104
75
|
end
|
105
76
|
end
|
106
77
|
|
107
|
-
@@ranged_connection_pool_key_algo = nil
|
108
78
|
def self.ranged_connection_pool_key_algo
|
109
|
-
|
79
|
+
Proc.new { |key| Digest::MD5.hexdigest key.to_s }
|
110
80
|
end
|
111
81
|
|
112
|
-
def self.
|
113
|
-
|
82
|
+
def self.new_ranged_connection_pool(async)
|
83
|
+
if self.connection_spec[:datacenter]
|
84
|
+
require 'with_connection/ranged_connection_pool'
|
114
85
|
|
115
|
-
|
116
|
-
async ? self.new_event_machine_connection : self.new_connection
|
117
|
-
end
|
86
|
+
default_pool = async ? new_async_connection_pool : new_sync_connection_pool
|
118
87
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
ranges_and_pools = self.servers_and_ranges(self.connection_spec[:datacenter]).map do |info|
|
123
|
-
conn_method = Proc.new do
|
124
|
-
async ? self.new_event_machine_connection(info[:servers]) : self.new_connection(info[:servers])
|
88
|
+
ranges_and_pools = self.servers_and_ranges(self.connection_spec[:datacenter]).map do |info|
|
89
|
+
pool = async ? new_async_connection_pool(info[:servers]) : new_sync_connection_pool(info[:servers])
|
90
|
+
[WithConnection::RangedConnectionPool::BasicRange.new(info[:start_token], info[:end_token]), pool]
|
125
91
|
end
|
126
|
-
spec = ActiveRecord::Base::ConnectionSpecification.new self.connection_spec, conn_method
|
127
|
-
pool = WithConnection::ConnectionPool.new "sync cassandra", spec
|
128
|
-
[WithConnection::RangedConnectionPool::BasicRange.new(info[:start_token], info[:end_token]), pool]
|
129
|
-
end
|
130
92
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
@@async_ranged_connection_pool = nil
|
136
|
-
def self.sync_ranged_connection_pool
|
137
|
-
@@sync_ranged_connection_pool ||= create_ranged_connection_pool(false)
|
138
|
-
end
|
139
|
-
|
140
|
-
def self.async_ranged_connection_pool
|
141
|
-
@@async_ranged_connection_pool ||= create_ranged_connection_pool(true)
|
93
|
+
ranges_and_pools.size <= 1 ? default_pool : WithConnection::RangedConnectionPool.new(ranges_and_pools, default_pool, self.ranged_connection_pool_key_algo)
|
94
|
+
else
|
95
|
+
async ? new_async_connection_pool : new_sync_connection_pool
|
96
|
+
end
|
142
97
|
end
|
143
98
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
end
|
148
|
-
else
|
149
|
-
def self.ranged_connection_pool
|
150
|
-
self.sync_ranged_connection_pool
|
151
|
-
end
|
99
|
+
@@sync_connection_pool = nil
|
100
|
+
def self.sync_connection_pool
|
101
|
+
@@sync_connection_pool ||= new_ranged_connection_pool(false)
|
152
102
|
end
|
153
103
|
|
154
|
-
|
155
|
-
|
104
|
+
@@async_connection_pool = nil
|
105
|
+
def self.async_connection_pool
|
106
|
+
@@async_connection_pool ||= new_ranged_connection_pool(true)
|
156
107
|
end
|
157
108
|
|
158
109
|
if defined?(EM)
|
@@ -169,17 +120,17 @@ module CassandraObject
|
|
169
120
|
self.class.connection_pool
|
170
121
|
end
|
171
122
|
|
172
|
-
def self.connection
|
173
|
-
self.
|
123
|
+
def self.connection
|
124
|
+
self.connection_pool.connection
|
174
125
|
end
|
175
|
-
def self.connection
|
126
|
+
def self.connection?; !!connection; end
|
176
127
|
|
177
|
-
def self.with_connection(key=nil, &block)
|
178
|
-
self.
|
128
|
+
def self.with_connection(key=nil, read_write=nil, &block)
|
129
|
+
self.connection_pool.with_connection(key, read_write, &block)
|
179
130
|
end
|
180
131
|
|
181
|
-
def with_connection(key=nil, &block)
|
182
|
-
self.class.with_connection(key, &block)
|
132
|
+
def with_connection(key=nil, read_write=nil, &block)
|
133
|
+
self.class.with_connection(key, read_write, &block)
|
183
134
|
end
|
184
135
|
|
185
136
|
def self.disconnect!
|
@@ -25,7 +25,7 @@ module CassandraObject
|
|
25
25
|
while objects.size < number_to_find && !out_of_keys
|
26
26
|
index_results =
|
27
27
|
begin
|
28
|
-
CassandraObject::Base.with_connection(@key) do
|
28
|
+
CassandraObject::Base.with_connection(@key, :read) do
|
29
29
|
connection.get(@column_family, @key, @super_column,
|
30
30
|
count: limit,
|
31
31
|
start: start_with,
|
@@ -11,7 +11,7 @@ module CassandraObject
|
|
11
11
|
|
12
12
|
attributes =
|
13
13
|
begin
|
14
|
-
CassandraObject::Base.with_connection(key) do
|
14
|
+
CassandraObject::Base.with_connection(key, :read) do
|
15
15
|
ActiveSupport::Notifications.instrument("get.cassandra_object", column_family: column_family, key: key) do
|
16
16
|
connection.get column_family, key, opts.slice(:consistency)
|
17
17
|
end
|
@@ -35,7 +35,7 @@ module CassandraObject
|
|
35
35
|
opts.assert_valid_keys(:consistency)
|
36
36
|
opts[:consistency] ||= thrift_read_consistency
|
37
37
|
|
38
|
-
result = CassandraObject::Base.with_connection(key) do
|
38
|
+
result = CassandraObject::Base.with_connection(key, :read) do
|
39
39
|
ActiveSupport::Notifications.instrument("get_counter.cassandra_object", column_family: column_family, key: key, column: column) do
|
40
40
|
connection.get(column_family, key, column, opts)
|
41
41
|
end
|
@@ -50,7 +50,7 @@ module CassandraObject
|
|
50
50
|
|
51
51
|
def all(options = {})
|
52
52
|
limit = options[:limit] || 100
|
53
|
-
results = CassandraObject::Base.with_connection do
|
53
|
+
results = CassandraObject::Base.with_connection(nil, :read) do
|
54
54
|
ActiveSupport::Notifications.instrument("get_range.cassandra_object", column_family: column_family, key_count: limit) do
|
55
55
|
connection.get_range(column_family, key_count: limit, consistency: thrift_read_consistency)
|
56
56
|
end
|
@@ -88,7 +88,7 @@ module CassandraObject
|
|
88
88
|
|
89
89
|
# Selecting a slice of a super column
|
90
90
|
def get_slice(key, start, finish, opts={})
|
91
|
-
CassandraObject::Base.with_connection(key) do
|
91
|
+
CassandraObject::Base.with_connection(key, :read) do
|
92
92
|
connection.get_slice(column_family,
|
93
93
|
key,
|
94
94
|
start,
|
@@ -118,7 +118,7 @@ module CassandraObject
|
|
118
118
|
end
|
119
119
|
|
120
120
|
def multi_get(keys, options={})
|
121
|
-
attribute_results = CassandraObject::Base.with_connection do
|
121
|
+
attribute_results = CassandraObject::Base.with_connection(nil, :read) do
|
122
122
|
ActiveSupport::Notifications.instrument("multi_get.cassandra_object", column_family: column_family, keys: keys) do
|
123
123
|
connection.multi_get(column_family, keys.map(&:to_s), consistency: thrift_read_consistency)
|
124
124
|
end
|
@@ -130,7 +130,7 @@ module CassandraObject
|
|
130
130
|
def multi_get_by_expression(expression, options={})
|
131
131
|
options = options.reverse_merge(:consistency => thrift_read_consistency)
|
132
132
|
|
133
|
-
attribute_results = CassandraObject::Base.with_connection do
|
133
|
+
attribute_results = CassandraObject::Base.with_connection(nil, :read) do
|
134
134
|
ActiveSupport::Notifications.instrument("multi_get_by_expression.cassandra_object", column_family: column_family, expression: expression) do
|
135
135
|
intermediate_results = connection.get_indexed_slices(column_family, expression, options)
|
136
136
|
connection.send(:multi_columns_to_hash!, column_family, intermediate_results)
|
@@ -4,11 +4,11 @@ module CassandraObject
|
|
4
4
|
|
5
5
|
module ClassMethods
|
6
6
|
def add(key, value, *columns_and_options)
|
7
|
-
column_family, column, sub_column, options = CassandraObject::Base.with_connection { connection.extract_and_validate_params(self.column_family, key, columns_and_options, {}) }
|
7
|
+
column_family, column, sub_column, options = CassandraObject::Base.with_connection(key, :write) { connection.extract_and_validate_params(self.column_family, key, columns_and_options, {}) }
|
8
8
|
# the options are removed, leaving just columns
|
9
9
|
columns = columns_and_options
|
10
10
|
|
11
|
-
CassandraObject::Base.with_connection(key) do
|
11
|
+
CassandraObject::Base.with_connection(key, :write) do
|
12
12
|
ActiveSupport::Notifications.instrument("add.cassandra_object", column_family: column_family, key: key, column: column, sub_column: sub_column, value: value) do
|
13
13
|
connection.add(column_family, key, value, *columns, :consistency => thrift_write_consistency)
|
14
14
|
end
|
@@ -28,7 +28,7 @@ module CassandraObject
|
|
28
28
|
values.uniq!
|
29
29
|
value_spec = values.length == 1 ? values[0] : '<various>'
|
30
30
|
|
31
|
-
CassandraObject::Base.with_connection(key) do
|
31
|
+
CassandraObject::Base.with_connection(key, :write) do
|
32
32
|
ActiveSupport::Notifications.instrument("add.cassandra_object", column_family: column_family, key: key, column: column_spec, value: value_spec) do
|
33
33
|
connection.add_multiple_columns(column_family, key, hash, :consistency => thrift_write_consistency)
|
34
34
|
end
|
@@ -36,7 +36,7 @@ module CassandraObject
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def remove(key)
|
39
|
-
CassandraObject::Base.with_connection(key) do
|
39
|
+
CassandraObject::Base.with_connection(key, :write) do
|
40
40
|
ActiveSupport::Notifications.instrument("remove.cassandra_object", column_family: column_family, key: key) do
|
41
41
|
connection.remove(column_family, key.to_s, consistency: thrift_write_consistency)
|
42
42
|
end
|
@@ -46,7 +46,7 @@ module CassandraObject
|
|
46
46
|
# remove_counter is not exposed by Cassandra gem.
|
47
47
|
# TODO: move this to Cassandra gem.
|
48
48
|
def remove_counter(key)
|
49
|
-
CassandraObject::Base.with_connection(key) do
|
49
|
+
CassandraObject::Base.with_connection(key, :write) do
|
50
50
|
ActiveSupport::Notifications.instrument("remove.cassandra_object", column_family: column_family, key: key) do
|
51
51
|
parent = CassandraThrift::ColumnParent.new(:column_family => column_family)
|
52
52
|
connection.send(:client).remove_counter(key, parent, thrift_write_consistency)
|
@@ -55,7 +55,7 @@ module CassandraObject
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def delete_all
|
58
|
-
CassandraObject::Base.with_connection do
|
58
|
+
CassandraObject::Base.with_connection(nil, :write) do
|
59
59
|
ActiveSupport::Notifications.instrument("truncate.cassandra_object", column_family: column_family) do
|
60
60
|
connection.truncate!(column_family)
|
61
61
|
end
|
@@ -72,7 +72,7 @@ module CassandraObject
|
|
72
72
|
key.tap do |key|
|
73
73
|
unless attributes.blank?
|
74
74
|
attributes = encode_columns_hash(attributes, schema_version)
|
75
|
-
CassandraObject::Base.with_connection(key) do
|
75
|
+
CassandraObject::Base.with_connection(key, :write) do
|
76
76
|
ActiveSupport::Notifications.instrument("insert.cassandra_object", column_family: column_family, key: key, attributes: attributes) do
|
77
77
|
|
78
78
|
options = {}.tap do |options|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 2
|
7
7
|
- 5
|
8
|
-
-
|
9
|
-
version: 2.5.
|
8
|
+
- 9
|
9
|
+
version: 2.5.9
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Michael Koziarski
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2013-06-
|
19
|
+
date: 2013-06-24 00:00:00 -04:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|