sessionm-cassandra_object 2.5.3 → 2.5.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,14 +8,14 @@ module CassandraObject
8
8
  class_attribute :connection_spec
9
9
 
10
10
  class_eval do
11
- def self.new_event_machine_connection
11
+ def self.new_event_machine_connection(servers=nil)
12
12
  spec = connection_spec.dup
13
13
 
14
14
  require 'thrift_client/event_machine'
15
15
  spec[:thrift].merge!(:transport => Thrift::EventMachineTransport,
16
16
  :transport_wrapper => nil)
17
17
 
18
- Cassandra.new(spec[:keyspace], spec[:servers], spec[:thrift]).tap do |conn|
18
+ Cassandra.new(spec[:keyspace], servers || spec[:servers], spec[:thrift]).tap do |conn|
19
19
  conn.disable_node_auto_discovery! if spec[:disable_node_auto_discovery]
20
20
  if spec[:cache_schema]
21
21
  if @@schema
@@ -31,14 +31,14 @@ module CassandraObject
31
31
  end
32
32
  end
33
33
 
34
- def new_event_machine_connection
35
- self.class.new_event_machine_connection
34
+ def new_event_machine_connection(servers=nil)
35
+ self.class.new_event_machine_connection(servers)
36
36
  end
37
37
 
38
- def self.new_connection
38
+ def self.new_connection(servers=nil)
39
39
  spec = connection_spec.dup
40
40
 
41
- Cassandra.new(spec[:keyspace], spec[:servers], spec[:thrift]).tap do |conn|
41
+ Cassandra.new(spec[:keyspace], servers || spec[:servers], spec[:thrift]).tap do |conn|
42
42
  conn.disable_node_auto_discovery! if spec[:disable_node_auto_discovery]
43
43
  if spec[:cache_schema]
44
44
  if @@schema
@@ -54,8 +54,8 @@ module CassandraObject
54
54
  end
55
55
  end
56
56
 
57
- def new_connection
58
- self.class.new_connection
57
+ def new_connection(servers=nil)
58
+ self.class.new_connection(servers)
59
59
  end
60
60
 
61
61
  @@schema = nil
@@ -89,13 +89,83 @@ module CassandraObject
89
89
  self.class.sync_connection_pool
90
90
  end
91
91
 
92
+ def self.ring
93
+ self.new_connection.ring
94
+ end
95
+
96
+ def self.servers_and_ranges(datacenter)
97
+ datacenter = datacenter.to_s
98
+ ring.map do |t|
99
+ {
100
+ :start_token => sprintf('%032x', t.start_token.to_i),
101
+ :end_token => t.end_token.to_i == 0 ? ('f' * 32) : sprintf('%032x', t.end_token.to_i - 1),
102
+ :servers => t.endpoint_details.select { |d| d.datacenter == datacenter }.map(&:host)
103
+ }
104
+ end
105
+ end
106
+
107
+ @@ranged_connection_pool_key_algo = nil
108
+ def self.ranged_connection_pool_key_algo
109
+ @@ranged_connection_pool_key_algo ||= Proc.new { |key| Digest::MD5.hexdigest key }
110
+ end
111
+
112
+ def self.create_ranged_connection_pool(async)
113
+ require 'with_connection/ranged_connection_pool'
114
+
115
+ adapter_method = Proc.new do
116
+ async ? self.new_event_machine_connection : self.new_connection
117
+ end
118
+
119
+ spec = ActiveRecord::Base::ConnectionSpecification.new self.connection_spec, adapter_method
120
+ default_pool = WithConnection::ConnectionPool.new "sync cassandra", spec
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])
125
+ 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
+
131
+ ranges_and_pools.size <= 1 ? default_pool : WithConnection::RangedConnectionPool.new(ranges_and_pools, default_pool, self.ranged_connection_pool_key_algo)
132
+ end
133
+
134
+ @@sync_ranged_connection_pool = nil
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)
142
+ end
143
+
144
+ if defined?(EM)
145
+ def self.ranged_connection_pool
146
+ EM.reactor_running? ? self.async_ranged_connection_pool : self.sync_ranged_connection_pool
147
+ end
148
+ else
149
+ def self.ranged_connection_pool
150
+ self.sync_ranged_connection_pool
151
+ end
152
+ end
153
+
154
+ def ranged_connection_pool
155
+ self.class.ranged_connection_pool
156
+ end
157
+
92
158
  if defined?(EM)
93
159
  def self.connection_pool
94
- EM.reactor_running? ? self.async_connection_pool : self.sync_connection_pool
160
+ if self.connection_spec[:datacenter]
161
+ EM.reactor_running? ? self.async_ranged_connection_pool : self.sync_ranged_connection_pool
162
+ else
163
+ EM.reactor_running? ? self.async_connection_pool : self.sync_connection_pool
164
+ end
95
165
  end
96
166
  else
97
167
  def self.connection_pool
98
- self.sync_connection_pool
168
+ self.connection_spec[:datacenter] ? self.ranged_connection_pool : self.sync_connection_pool
99
169
  end
100
170
  end
101
171
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'sessionm-cassandra_object'
5
- s.version = '2.5.3'
5
+ s.version = '2.5.4'
6
6
  s.description = 'Cassandra ActiveModel'
7
7
  s.summary = 'Cassandra ActiveModel'
8
8
 
metadata CHANGED
@@ -1,73 +1,75 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: sessionm-cassandra_object
3
- version: !ruby/object:Gem::Version
4
- version: 2.5.3
5
- prerelease:
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 2
7
+ - 5
8
+ - 4
9
+ version: 2.5.4
6
10
  platform: ruby
7
- authors:
11
+ authors:
8
12
  - Michael Koziarski
9
13
  - gotime
10
14
  - sessionm
11
15
  autorequire:
12
16
  bindir: bin
13
17
  cert_chain: []
14
- date: 2013-06-06 00:00:00.000000000 Z
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
18
+
19
+ date: 2013-06-22 00:00:00 -04:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
17
23
  name: rails
18
- requirement: !ruby/object:Gem::Requirement
19
- none: false
20
- requirements:
21
- - - ~>
22
- - !ruby/object:Gem::Version
23
- version: 3.0.9
24
- type: :runtime
25
24
  prerelease: false
26
- version_requirements: !ruby/object:Gem::Requirement
27
- none: false
28
- requirements:
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ requirements:
29
27
  - - ~>
30
- - !ruby/object:Gem::Version
28
+ - !ruby/object:Gem::Version
29
+ segments:
30
+ - 3
31
+ - 0
32
+ - 9
31
33
  version: 3.0.9
32
- - !ruby/object:Gem::Dependency
33
- name: sessionm-cassandra
34
- requirement: !ruby/object:Gem::Requirement
35
- none: false
36
- requirements:
37
- - - ! '>='
38
- - !ruby/object:Gem::Version
39
- version: 1.0.1
40
34
  type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: sessionm-cassandra
41
38
  prerelease: false
42
- version_requirements: !ruby/object:Gem::Requirement
43
- none: false
44
- requirements:
45
- - - ! '>='
46
- - !ruby/object:Gem::Version
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 1
45
+ - 0
46
+ - 1
47
47
  version: 1.0.1
48
- - !ruby/object:Gem::Dependency
48
+ type: :runtime
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
49
51
  name: bundler
50
- requirement: !ruby/object:Gem::Requirement
51
- none: false
52
- requirements:
53
- - - ! '>='
54
- - !ruby/object:Gem::Version
55
- version: 1.0.0
56
- type: :development
57
52
  prerelease: false
58
- version_requirements: !ruby/object:Gem::Requirement
59
- none: false
60
- requirements:
61
- - - ! '>='
62
- - !ruby/object:Gem::Version
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 1
59
+ - 0
60
+ - 0
63
61
  version: 1.0.0
62
+ type: :development
63
+ version_requirements: *id003
64
64
  description: Cassandra ActiveModel
65
65
  email: klange@sessionm.com
66
66
  executables: []
67
+
67
68
  extensions: []
68
- extra_rdoc_files:
69
+
70
+ extra_rdoc_files:
69
71
  - README.markdown
70
- files:
72
+ files:
71
73
  - .gitignore
72
74
  - CHANGELOG
73
75
  - Gemfile
@@ -158,31 +160,41 @@ files:
158
160
  - test/types/time_type_test.rb
159
161
  - test/types/utf8_string_type_test.rb
160
162
  - test/validations_test.rb
163
+ has_rdoc: true
161
164
  homepage: http://github.com/sessionm/cassandra_object
162
165
  licenses: []
166
+
163
167
  post_install_message:
164
168
  rdoc_options: []
165
- require_paths:
169
+
170
+ require_paths:
166
171
  - lib
167
- required_ruby_version: !ruby/object:Gem::Requirement
168
- none: false
169
- requirements:
170
- - - ! '>='
171
- - !ruby/object:Gem::Version
172
+ required_ruby_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ segments:
177
+ - 1
178
+ - 9
179
+ - 2
172
180
  version: 1.9.2
173
- required_rubygems_version: !ruby/object:Gem::Requirement
174
- none: false
175
- requirements:
176
- - - ! '>='
177
- - !ruby/object:Gem::Version
181
+ required_rubygems_version: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - ">="
184
+ - !ruby/object:Gem::Version
185
+ segments:
186
+ - 1
187
+ - 3
188
+ - 5
178
189
  version: 1.3.5
179
190
  requirements: []
191
+
180
192
  rubyforge_project:
181
- rubygems_version: 1.8.23
193
+ rubygems_version: 1.3.6
182
194
  signing_key:
183
195
  specification_version: 3
184
196
  summary: Cassandra ActiveModel
185
- test_files:
197
+ test_files:
186
198
  - test/README
187
199
  - test/active_model_test.rb
188
200
  - test/attributes_test.rb