ebisu_connection 2.4.2 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/Appraisals +11 -11
- data/README.md +40 -44
- data/ebisu_connection.gemspec +4 -5
- data/gemfiles/rails50.gemfile +2 -2
- data/gemfiles/rails51.gemfile +2 -2
- data/gemfiles/rails52.gemfile +10 -0
- data/lib/ebisu_connection.rb +2 -6
- data/lib/ebisu_connection/config.rb +51 -0
- data/lib/ebisu_connection/connection_manager.rb +16 -31
- data/lib/ebisu_connection/load_balancer.rb +32 -0
- data/lib/ebisu_connection/replica.rb +7 -0
- data/lib/ebisu_connection/version.rb +1 -1
- metadata +26 -33
- data/gemfiles/rails42.gemfile +0 -10
- data/lib/ebisu_connection/conf_file.rb +0 -64
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1492ff4f579ef693566907ad31141dea9207cedc046502ccc6a3ee6b17ba4a56
|
4
|
+
data.tar.gz: 3d96c7e13ca8452787270f25c91a1c97d75f7defe4ca0d5a4d1fa7d477bf48ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb7daa78160f1707d39419c78d23833cdd5d11fd356223ee2f58cb3916d086b9b622173f12f2a35064a275d5bcccde47f68ddc5a53b6286b94fe683a357f4a56
|
7
|
+
data.tar.gz: d620a6cb1fdca4b80f3e6e52cfed313284634e93ee13eaa2ecced333cf595719f6f668f4fd448a4d9b4b8f6b392ca98750df9b0ab82f874ab3cc0ba6f79bddc3
|
data/.travis.yml
CHANGED
data/Appraisals
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
appraise "rails42" do
|
2
|
-
gem "activerecord", "~> 4.2.0"
|
3
|
-
gem 'activesupport', '~> 4.2.0'
|
4
|
-
gem 'mysql2', '>= 0.3.13', '< 0.5'
|
5
|
-
gem 'pg', '~> 0.15'
|
6
|
-
end
|
7
|
-
|
8
1
|
appraise "rails50" do
|
9
2
|
gem "activerecord", "~> 5.0.0"
|
10
3
|
gem 'activesupport', '~> 5.0.0'
|
11
|
-
gem 'mysql2', '>= 0.3.18', '< 0.
|
12
|
-
gem 'pg', '
|
4
|
+
gem 'mysql2', '>= 0.3.18', '< 0.6.0'
|
5
|
+
gem 'pg', '>= 0.18', '< 2.0'
|
13
6
|
end
|
14
7
|
|
15
8
|
appraise "rails51" do
|
16
9
|
gem 'activerecord', '~> 5.1.0'
|
17
10
|
gem 'activesupport', '~> 5.1.0'
|
18
|
-
gem 'mysql2', '>= 0.3.18', '< 0.
|
19
|
-
gem 'pg', '
|
11
|
+
gem 'mysql2', '>= 0.3.18', '< 0.6.0'
|
12
|
+
gem 'pg', '>= 0.18', '< 2.0'
|
13
|
+
end
|
14
|
+
|
15
|
+
appraise "rails52" do
|
16
|
+
gem 'activerecord', '~> 5.2.0'
|
17
|
+
gem 'activesupport', '~> 5.2.0'
|
18
|
+
gem 'mysql2', '>= 0.4.4', '< 0.6.0'
|
19
|
+
gem 'pg', '>= 0.18', '< 2.0'
|
20
20
|
end
|
data/README.md
CHANGED
@@ -50,9 +50,8 @@ article.destory
|
|
50
50
|
```
|
51
51
|
|
52
52
|
## Support ActiveRecord version
|
53
|
-
EbisuConnection supports ActiveRecord version
|
54
|
-
If you are using Rails 4.
|
55
|
-
If you are using Rails 3.2, could use EbisuConnection version 1.0.0 or before.
|
53
|
+
EbisuConnection supports ActiveRecord version 5.0 or later.
|
54
|
+
If you are using Rails 4.2, you can use EbisuConnection version 2.4.2 or before.
|
56
55
|
|
57
56
|
## Support DB
|
58
57
|
EbisuConnection supports MySQL and PostgreSQL.
|
@@ -82,26 +81,27 @@ $ gem install ebisu_connection
|
|
82
81
|
config/database.yml
|
83
82
|
|
84
83
|
```yaml
|
85
|
-
|
84
|
+
default: &default
|
86
85
|
adapter: mysql2
|
87
86
|
encoding: utf8
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
87
|
+
pool: <%%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
|
88
|
+
username: root
|
89
|
+
password:
|
90
|
+
|
91
|
+
production:
|
92
|
+
<<: *default
|
93
|
+
database: blog_production
|
94
|
+
username: master_db_user
|
95
|
+
password: <%= ENV['MASTER_DATABASE_PASSWORD'] %>
|
96
|
+
host: master_db
|
95
97
|
|
96
98
|
replica:
|
97
|
-
username:
|
98
|
-
password:
|
99
|
-
host: replica
|
99
|
+
username: replica_db_user
|
100
|
+
password: <%= ENV['REPLICA_DATABASE_PASSWORD'] %>
|
100
101
|
```
|
101
102
|
|
102
|
-
|
103
|
-
|
104
|
-
|
103
|
+
`replica` is the configuration used for connecting read-only queries to the database replica. All other connections will use the database master settings.
|
104
|
+
|
105
105
|
Config of each replica server fill out to `config/replica.yml`
|
106
106
|
|
107
107
|
```yaml
|
@@ -123,26 +123,27 @@ String format is it. You can write config with hash.
|
|
123
123
|
If you may want to user multiple replica group, write multiple replica group to config/database.yml.
|
124
124
|
|
125
125
|
```yaml
|
126
|
-
|
126
|
+
default: &default
|
127
127
|
adapter: mysql2
|
128
128
|
encoding: utf8
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
129
|
+
pool: <%%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
|
130
|
+
username: root
|
131
|
+
password:
|
132
|
+
|
133
|
+
production:
|
134
|
+
<<: *default
|
135
|
+
database: blog_production
|
136
|
+
username: master_db_user
|
137
|
+
password: <%= ENV['MASTER_DATABASE_PASSWORD'] %>
|
138
|
+
host: master_db
|
136
139
|
|
137
140
|
replica:
|
138
|
-
username:
|
139
|
-
password:
|
140
|
-
host: replica
|
141
|
+
username: replica_db_user
|
142
|
+
password: <%= ENV['REPLICA_DATABASE_PASSWORD'] %>
|
141
143
|
|
142
144
|
admin_replica:
|
143
|
-
username:
|
144
|
-
password:
|
145
|
-
host: admin_replica
|
145
|
+
username: admin_replica_db_user
|
146
|
+
password: <%= ENV['ADMIN_REPLICA_DATABASE_PASSWORD'] %>
|
146
147
|
```
|
147
148
|
|
148
149
|
Config of each replica server fill out to `config/replica.yml`
|
@@ -160,7 +161,7 @@ production:
|
|
160
161
|
- "replica5, 20"
|
161
162
|
```
|
162
163
|
|
163
|
-
|
164
|
+
The custom replica stanza can then be applied as an argument to the `establish_fresh_connection` method in the models that should use it. For example:
|
164
165
|
|
165
166
|
```ruby
|
166
167
|
class AdminUser < ActiveRecord::Base
|
@@ -168,7 +169,7 @@ class AdminUser < ActiveRecord::Base
|
|
168
169
|
end
|
169
170
|
```
|
170
171
|
|
171
|
-
The
|
172
|
+
The child (sub) classes of the configured model will inherit the same access as the parent class. Example:
|
172
173
|
|
173
174
|
```ruby
|
174
175
|
class Parent < ActiveRecord::Base
|
@@ -182,10 +183,12 @@ class Benefit < Parent
|
|
182
183
|
end
|
183
184
|
```
|
184
185
|
|
185
|
-
AdminUser and Benefit access
|
186
|
+
The `AdminUser` and `Benefit` models will access the database configured for the `admin_replica` group.
|
187
|
+
|
186
188
|
|
189
|
+
### Master-only Models
|
187
190
|
|
188
|
-
|
191
|
+
It is possible to declare that specific models always use the DB master for all connections, using the `master_db_only!` method:
|
189
192
|
|
190
193
|
```ruby
|
191
194
|
class SomethingModel < ActiveRecord::Base
|
@@ -193,10 +196,9 @@ class SomethingModel < ActiveRecord::Base
|
|
193
196
|
end
|
194
197
|
```
|
195
198
|
|
196
|
-
|
197
|
-
The model that master_db_only model's child is always access to master db.
|
199
|
+
All queries generated by methods on the `CustomerState` model will be directed to the DB master.
|
198
200
|
|
199
|
-
###
|
201
|
+
### Using EbisuConnection With Unicorn
|
200
202
|
|
201
203
|
```ruby
|
202
204
|
before_fork do |server, worker|
|
@@ -204,12 +206,6 @@ before_fork do |server, worker|
|
|
204
206
|
ActiveRecord::Base.clear_all_replica_connections!
|
205
207
|
...
|
206
208
|
end
|
207
|
-
|
208
|
-
after_fork do |server, worker|
|
209
|
-
...
|
210
|
-
ActiveRecord::Base.establish_fresh_connection
|
211
|
-
...
|
212
|
-
end
|
213
209
|
```
|
214
210
|
|
215
211
|
## Contributing
|
data/ebisu_connection.gemspec
CHANGED
@@ -21,14 +21,13 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
spec.required_ruby_version = '>= 2.2'
|
23
23
|
|
24
|
-
spec.add_dependency 'fresh_connection', '~>
|
25
|
-
spec.add_dependency 'concurrent-ruby', '~> 1.0.0'
|
24
|
+
spec.add_dependency 'fresh_connection', '~> 3.0.0'
|
26
25
|
|
27
|
-
spec.add_development_dependency 'mysql2', '>= 0.3.
|
28
|
-
spec.add_development_dependency 'pg', '
|
26
|
+
spec.add_development_dependency 'mysql2', '>= 0.3.18', '< 0.6.0'
|
27
|
+
spec.add_development_dependency 'pg', '>= 0.18', '< 2.0'
|
29
28
|
spec.add_development_dependency "bundler", ">= 1.3.0", "< 2.0"
|
30
29
|
spec.add_development_dependency "rake", ">= 0.8.7"
|
31
30
|
spec.add_development_dependency 'appraisal'
|
32
|
-
spec.add_development_dependency "minitest"
|
31
|
+
spec.add_development_dependency "minitest", "~> 5.10.0"
|
33
32
|
spec.add_development_dependency "minitest-reporters"
|
34
33
|
end
|
data/gemfiles/rails50.gemfile
CHANGED
data/gemfiles/rails51.gemfile
CHANGED
data/lib/ebisu_connection.rb
CHANGED
@@ -1,17 +1,13 @@
|
|
1
1
|
require 'active_support'
|
2
2
|
require "fresh_connection"
|
3
|
-
require "ebisu_connection/
|
3
|
+
require "ebisu_connection/config"
|
4
4
|
|
5
5
|
module EbisuConnection
|
6
6
|
class << self
|
7
7
|
attr_writer :env
|
8
8
|
|
9
9
|
def replica_file=(file)
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
def slaves_file=(file)
|
14
|
-
ConfFile.slaves_file = file
|
10
|
+
Config.replica_file = file
|
15
11
|
end
|
16
12
|
|
17
13
|
def env
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module EbisuConnection
|
4
|
+
class Config
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_writer :replica_file
|
9
|
+
|
10
|
+
def config
|
11
|
+
return @config if defined?(@config)
|
12
|
+
|
13
|
+
conf = YAML.load_file(replica_file)
|
14
|
+
@config = conf[EbisuConnection.env.to_s] || {}
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def replica_file
|
20
|
+
return @replica_file if @replica_file
|
21
|
+
|
22
|
+
raise "nothing replica_file. You have to set a file path using EbisuConnection.replica_file= method" unless defined?(Rails)
|
23
|
+
|
24
|
+
file = %w(yml yaml).map{|ext| Rails.root.join("config/replica.#{ext}").to_s }.detect {|f| File.exist?(f) }
|
25
|
+
return file if file
|
26
|
+
|
27
|
+
raise "nothing replica_file. You have to put a config/replica.yml file"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def initialize(spec_name)
|
32
|
+
@conf = load_config(spec_name)
|
33
|
+
end
|
34
|
+
|
35
|
+
def each(&block)
|
36
|
+
@conf.each(&block)
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def load_config(spec_name)
|
42
|
+
c = self.class.config
|
43
|
+
|
44
|
+
if c.is_a?(Hash)
|
45
|
+
c[spec_name] || c
|
46
|
+
else
|
47
|
+
c
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -1,6 +1,5 @@
|
|
1
|
-
require "concurrent"
|
2
1
|
require "ebisu_connection/replica"
|
3
|
-
require "ebisu_connection/
|
2
|
+
require "ebisu_connection/load_balancer"
|
4
3
|
|
5
4
|
module EbisuConnection
|
6
5
|
class ConnectionManager < FreshConnection::AbstractConnectionManager
|
@@ -9,65 +8,51 @@ module EbisuConnection
|
|
9
8
|
def initialize(spec_name = nil)
|
10
9
|
super
|
11
10
|
|
12
|
-
@replicas =
|
13
|
-
|
14
|
-
replica_conf.each do |conf|
|
15
|
-
@replicas << Replica.new(conf, spec_name)
|
11
|
+
@replicas = replica_conf.map do |conf|
|
12
|
+
Replica.new(conf, spec_name)
|
16
13
|
end
|
17
|
-
|
18
|
-
recalc_roulette
|
19
14
|
end
|
20
15
|
|
21
16
|
def replica_connection
|
22
17
|
raise AllReplicaHasGoneError if @replicas.empty?
|
23
|
-
|
18
|
+
load_balancer.replica.connection
|
24
19
|
end
|
25
20
|
|
26
21
|
def put_aside!
|
27
|
-
@replicas.each
|
28
|
-
pool.release_connection if pool.active_connection? && !pool.connection.transaction_open?
|
29
|
-
end
|
22
|
+
@replicas.each(&:put_aside!)
|
30
23
|
end
|
31
24
|
|
32
25
|
def clear_all_connections!
|
33
|
-
@replicas.each
|
34
|
-
pool.disconnect!
|
35
|
-
end
|
26
|
+
@replicas.each(&:disconnect!)
|
36
27
|
end
|
37
28
|
|
38
29
|
def recovery?
|
39
|
-
dead_replicas = @replicas.select do |
|
40
|
-
c =
|
30
|
+
dead_replicas = @replicas.select do |replica|
|
31
|
+
c = replica.connection rescue nil
|
41
32
|
!c || !c.active?
|
42
33
|
end
|
34
|
+
|
43
35
|
return false if dead_replicas.empty?
|
44
36
|
|
45
|
-
dead_replicas.each do |
|
46
|
-
|
47
|
-
@replicas.delete(
|
37
|
+
dead_replicas.each do |replica|
|
38
|
+
replica.disconnect!
|
39
|
+
@replicas.delete(replica)
|
48
40
|
end
|
49
41
|
|
50
42
|
raise AllReplicaHasGoneError if @replicas.empty?
|
51
43
|
|
52
|
-
|
44
|
+
@load_balancer = nil
|
53
45
|
true
|
54
46
|
end
|
55
47
|
|
56
48
|
private
|
57
49
|
|
58
|
-
def
|
59
|
-
|
60
|
-
|
61
|
-
@roulette = []
|
62
|
-
gcd = GreatestCommonDivisor.calc(weight_list)
|
63
|
-
weight_list.each_with_index do |w, index|
|
64
|
-
weight = w / gcd
|
65
|
-
@roulette.concat([index] * weight)
|
66
|
-
end
|
50
|
+
def load_balancer
|
51
|
+
@load_balancer ||= LoadBalancer.new(@replicas)
|
67
52
|
end
|
68
53
|
|
69
54
|
def replica_conf
|
70
|
-
|
55
|
+
@replica_conf ||= Config.new(spec_name)
|
71
56
|
end
|
72
57
|
end
|
73
58
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "ebisu_connection/greatest_common_divisor"
|
2
|
+
|
3
|
+
module EbisuConnection
|
4
|
+
class LoadBalancer
|
5
|
+
def initialize(replicas)
|
6
|
+
@replicas = replicas
|
7
|
+
end
|
8
|
+
|
9
|
+
def replica
|
10
|
+
@replicas[roulette.sample]
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def roulette
|
16
|
+
@roulette ||= calc_roulette
|
17
|
+
end
|
18
|
+
|
19
|
+
def calc_roulette
|
20
|
+
set = []
|
21
|
+
weight_list = @replicas.map(&:weight)
|
22
|
+
gcd = GreatestCommonDivisor.calc(weight_list)
|
23
|
+
|
24
|
+
weight_list.each_with_index do |w, index|
|
25
|
+
weight = w / gcd
|
26
|
+
set.concat([index] * weight)
|
27
|
+
end
|
28
|
+
|
29
|
+
set
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -28,6 +28,13 @@ module EbisuConnection
|
|
28
28
|
def connection
|
29
29
|
@pool.connection
|
30
30
|
end
|
31
|
+
|
32
|
+
def put_aside!
|
33
|
+
return unless active_connection?
|
34
|
+
return if connection.transaction_open?
|
35
|
+
|
36
|
+
release_connection
|
37
|
+
end
|
31
38
|
|
32
39
|
def active_connection?
|
33
40
|
@pool.active_connection?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ebisu_connection
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tsukasaoishi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fresh_connection
|
@@ -16,62 +16,54 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 3.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: concurrent-ruby
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 1.0.0
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 1.0.0
|
26
|
+
version: 3.0.0
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: mysql2
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
44
30
|
requirements:
|
45
31
|
- - ">="
|
46
32
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.3.
|
33
|
+
version: 0.3.18
|
48
34
|
- - "<"
|
49
35
|
- !ruby/object:Gem::Version
|
50
|
-
version:
|
36
|
+
version: 0.6.0
|
51
37
|
type: :development
|
52
38
|
prerelease: false
|
53
39
|
version_requirements: !ruby/object:Gem::Requirement
|
54
40
|
requirements:
|
55
41
|
- - ">="
|
56
42
|
- !ruby/object:Gem::Version
|
57
|
-
version: 0.3.
|
43
|
+
version: 0.3.18
|
58
44
|
- - "<"
|
59
45
|
- !ruby/object:Gem::Version
|
60
|
-
version:
|
46
|
+
version: 0.6.0
|
61
47
|
- !ruby/object:Gem::Dependency
|
62
48
|
name: pg
|
63
49
|
requirement: !ruby/object:Gem::Requirement
|
64
50
|
requirements:
|
65
|
-
- - "
|
51
|
+
- - ">="
|
66
52
|
- !ruby/object:Gem::Version
|
67
|
-
version: '0.
|
53
|
+
version: '0.18'
|
54
|
+
- - "<"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '2.0'
|
68
57
|
type: :development
|
69
58
|
prerelease: false
|
70
59
|
version_requirements: !ruby/object:Gem::Requirement
|
71
60
|
requirements:
|
72
|
-
- - "
|
61
|
+
- - ">="
|
73
62
|
- !ruby/object:Gem::Version
|
74
|
-
version: '0.
|
63
|
+
version: '0.18'
|
64
|
+
- - "<"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '2.0'
|
75
67
|
- !ruby/object:Gem::Dependency
|
76
68
|
name: bundler
|
77
69
|
requirement: !ruby/object:Gem::Requirement
|
@@ -124,16 +116,16 @@ dependencies:
|
|
124
116
|
name: minitest
|
125
117
|
requirement: !ruby/object:Gem::Requirement
|
126
118
|
requirements:
|
127
|
-
- - "
|
119
|
+
- - "~>"
|
128
120
|
- !ruby/object:Gem::Version
|
129
|
-
version:
|
121
|
+
version: 5.10.0
|
130
122
|
type: :development
|
131
123
|
prerelease: false
|
132
124
|
version_requirements: !ruby/object:Gem::Requirement
|
133
125
|
requirements:
|
134
|
-
- - "
|
126
|
+
- - "~>"
|
135
127
|
- !ruby/object:Gem::Version
|
136
|
-
version:
|
128
|
+
version: 5.10.0
|
137
129
|
- !ruby/object:Gem::Dependency
|
138
130
|
name: minitest-reporters
|
139
131
|
requirement: !ruby/object:Gem::Requirement
|
@@ -167,13 +159,14 @@ files:
|
|
167
159
|
- bin/setup
|
168
160
|
- bin/test
|
169
161
|
- ebisu_connection.gemspec
|
170
|
-
- gemfiles/rails42.gemfile
|
171
162
|
- gemfiles/rails50.gemfile
|
172
163
|
- gemfiles/rails51.gemfile
|
164
|
+
- gemfiles/rails52.gemfile
|
173
165
|
- lib/ebisu_connection.rb
|
174
|
-
- lib/ebisu_connection/
|
166
|
+
- lib/ebisu_connection/config.rb
|
175
167
|
- lib/ebisu_connection/connection_manager.rb
|
176
168
|
- lib/ebisu_connection/greatest_common_divisor.rb
|
169
|
+
- lib/ebisu_connection/load_balancer.rb
|
177
170
|
- lib/ebisu_connection/replica.rb
|
178
171
|
- lib/ebisu_connection/version.rb
|
179
172
|
homepage: https://github.com/tsukasaoishi/ebisu_connection
|
@@ -196,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
196
189
|
version: '0'
|
197
190
|
requirements: []
|
198
191
|
rubyforge_project:
|
199
|
-
rubygems_version: 2.7.
|
192
|
+
rubygems_version: 2.7.6
|
200
193
|
signing_key:
|
201
194
|
specification_version: 4
|
202
195
|
summary: EbisuConnection supports connections with configured replica servers.
|
data/gemfiles/rails42.gemfile
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
require 'active_support/deprecation'
|
3
|
-
|
4
|
-
module EbisuConnection
|
5
|
-
class ConfFile
|
6
|
-
class << self
|
7
|
-
attr_writer :replica_file
|
8
|
-
|
9
|
-
def slaves_file=(file)
|
10
|
-
ActiveSupport::Deprecation.warn(
|
11
|
-
"'slaves_file=' is deprecated and will removed from version 2.5.0. use 'replica_file=' instead."
|
12
|
-
)
|
13
|
-
|
14
|
-
self.replica_file = file
|
15
|
-
end
|
16
|
-
|
17
|
-
def replica_conf(spec_name)
|
18
|
-
return config unless config.is_a?(Hash)
|
19
|
-
|
20
|
-
c = config[spec_name]
|
21
|
-
return c if c
|
22
|
-
|
23
|
-
if spec_name == "replica" && config.key?("slave")
|
24
|
-
ActiveSupport::Deprecation.warn(
|
25
|
-
"'slave' in replica.yml is deprecated and will ignored from version 2.5.0. use 'replica' insted."
|
26
|
-
)
|
27
|
-
|
28
|
-
c = config["slave"]
|
29
|
-
end
|
30
|
-
|
31
|
-
c || config
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def config
|
37
|
-
return @config if defined?(@config)
|
38
|
-
|
39
|
-
conf = YAML.load_file(replica_file)
|
40
|
-
@config = conf[EbisuConnection.env.to_s] || {}
|
41
|
-
end
|
42
|
-
|
43
|
-
def replica_file
|
44
|
-
return @replica_file if @replica_file
|
45
|
-
|
46
|
-
raise "nothing replica_file. You have to set a file path using EbisuConnection.replica_file= method" unless defined?(Rails)
|
47
|
-
|
48
|
-
file = %w(yml yaml).map{|ext| Rails.root.join("config/replica.#{ext}").to_s }.detect {|f| File.exist?(f) }
|
49
|
-
return file if file
|
50
|
-
|
51
|
-
file = %w(yml yaml).map{|ext| Rails.root.join("config/slave.#{ext}").to_s }.detect {|f| File.exist?(f) }
|
52
|
-
if file
|
53
|
-
ActiveSupport::Deprecation.warn(
|
54
|
-
"file name 'config/#{file}' is deprecated and will ignored from version 2.5.0. use 'config/replica.yml' insted."
|
55
|
-
)
|
56
|
-
|
57
|
-
return file
|
58
|
-
end
|
59
|
-
|
60
|
-
raise "nothing replica_file. You have to put a config/replica.yml file"
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|