replidog 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Appraisals +7 -0
- data/README.md +1 -1
- data/gemfiles/rails32.gemfile +1 -0
- data/gemfiles/rails4.gemfile +1 -0
- data/gemfiles/rails41.gemfile +1 -0
- data/gemfiles/rails5.gemfile +7 -0
- data/lib/replidog/model.rb +40 -40
- data/lib/replidog/proxy.rb +4 -6
- data/lib/replidog/proxy_handler.rb +13 -3
- data/lib/replidog/version.rb +1 -1
- data/spec/dummy/config/environments/test.rb +2 -2
- data/spec/spec_helper.rb +0 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44af9edc1ca7b64ca4c802cec1e865f31318533b
|
4
|
+
data.tar.gz: 29a251aad399f14c85813e655dc184b46ecab204
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8a1858c3e07cbe87e516d80705e448d6afc508a1b5e3c0bc6dc30ebade7cebcb99c8bbe0e03d9465b2b8cdc6247ea08b93d5bcae62633d938530b8808820be0
|
7
|
+
data.tar.gz: 09914f2faa17a58fc50f5428efea7b4acc38246da64c57fa3280610c301a20b2e75f255578e5cc665f88dce212157a2c4aba8ff59ccda4a8521c48d3f12a123f
|
data/Appraisals
CHANGED
@@ -1,17 +1,24 @@
|
|
1
1
|
appraise "rails32" do
|
2
2
|
gem "activerecord", "~> 3.2.0"
|
3
|
+
gem "mysql2", '~> 0.3.20'
|
3
4
|
end
|
4
5
|
|
5
6
|
appraise "rails4" do
|
6
7
|
gem "activerecord", "~> 4.0.0"
|
8
|
+
gem "mysql2", '~> 0.3.20'
|
7
9
|
end
|
8
10
|
|
9
11
|
appraise "rails41" do
|
10
12
|
gem "activerecord", "~> 4.1.0"
|
13
|
+
gem "mysql2", '~> 0.3.20'
|
11
14
|
end
|
12
15
|
|
13
16
|
appraise "rails42" do
|
14
17
|
gem "activerecord", "~> 4.2.0"
|
15
18
|
end
|
19
|
+
|
20
|
+
appraise "rails5" do
|
21
|
+
gem "activerecord", "~> 5.0.0"
|
22
|
+
end
|
16
23
|
# vim: ft=ruby
|
17
24
|
#
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@ Based on https://github.com/r7kamura/replicat
|
|
9
9
|
* Multiple master/slave
|
10
10
|
* Auto switching between master/slave
|
11
11
|
* Supports connection management and query cache
|
12
|
-
* Supports Rails 3.2, 4.0, 4,1, 4.2
|
12
|
+
* Supports Rails 3.2, 4.0, 4,1, 4.2, 5.0
|
13
13
|
|
14
14
|
## Installation
|
15
15
|
|
data/gemfiles/rails32.gemfile
CHANGED
data/gemfiles/rails4.gemfile
CHANGED
data/gemfiles/rails41.gemfile
CHANGED
data/lib/replidog/model.rb
CHANGED
@@ -8,28 +8,51 @@ module Replidog
|
|
8
8
|
base.proxy_handler = Replidog::ProxyHandler.new
|
9
9
|
|
10
10
|
class << base
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
alias_method_chain(:clear_active_connections!, :replidog)
|
16
|
-
alias_method_chain(:clear_all_connections!, :replidog)
|
11
|
+
alias_method :connected_without_replidog?, :connected?
|
12
|
+
alias_method :connection_without_replidog, :connection
|
13
|
+
|
14
|
+
prepend BaseWithReplidogSupport
|
17
15
|
end
|
18
16
|
end
|
19
17
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
module BaseWithReplidogSupport
|
19
|
+
def establish_connection(spec = ENV["DATABASE_URL"])
|
20
|
+
super
|
21
|
+
proxy_handler.remove_connection(self)
|
22
|
+
proxy_handler.establish_connection(connection_pool.spec, self)
|
23
|
+
end
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
def connection
|
26
|
+
if replicated?
|
27
|
+
proxy_handler.retrieve_proxy(self).tap do |proxy|
|
28
|
+
proxy.current_model = self
|
29
|
+
end
|
30
|
+
else
|
31
|
+
super
|
30
32
|
end
|
31
|
-
|
32
|
-
|
33
|
+
end
|
34
|
+
|
35
|
+
def connected?
|
36
|
+
if replicated?
|
37
|
+
connection.connected?
|
38
|
+
else
|
39
|
+
super
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def clear_active_connections!
|
44
|
+
super
|
45
|
+
proxy_handler.clear_active_slave_connections! if replicated?
|
46
|
+
end
|
47
|
+
|
48
|
+
def clear_reloadable_connections!
|
49
|
+
super
|
50
|
+
proxy_handler.clear_reloadable_slave_connections! if replicated?
|
51
|
+
end
|
52
|
+
|
53
|
+
def clear_all_connections!
|
54
|
+
super
|
55
|
+
proxy_handler.clear_all_slave_connections! if replicated?
|
33
56
|
end
|
34
57
|
end
|
35
58
|
|
@@ -49,29 +72,6 @@ module Replidog
|
|
49
72
|
end
|
50
73
|
end
|
51
74
|
|
52
|
-
def connected_with_replidog?
|
53
|
-
if replicated?
|
54
|
-
connection.connected?
|
55
|
-
else
|
56
|
-
connected_without_replidog?
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def clear_active_connections_with_replidog!
|
61
|
-
clear_active_connections_without_replidog!
|
62
|
-
proxy_handler.clear_active_slave_connections! if replicated?
|
63
|
-
end
|
64
|
-
|
65
|
-
def clear_reloadable_connections_with_replidog!
|
66
|
-
clear_reloadable_connections_without_replidog!
|
67
|
-
proxy_handler.clear_reloadable_slave_connections! if replicated?
|
68
|
-
end
|
69
|
-
|
70
|
-
def clear_all_connections_with_replidog!
|
71
|
-
clear_all_connections_without_replidog!
|
72
|
-
proxy_handler.clear_all_slave_connections! if replicated?
|
73
|
-
end
|
74
|
-
|
75
75
|
private
|
76
76
|
|
77
77
|
def _using(connection_name)
|
data/lib/replidog/proxy.rb
CHANGED
@@ -172,12 +172,10 @@ module Replidog
|
|
172
172
|
|
173
173
|
def create
|
174
174
|
spec =
|
175
|
-
if ActiveRecord::VERSION::MAJOR >= 4
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new({}).spec(@configuration)
|
180
|
-
end
|
175
|
+
if ActiveRecord::VERSION::MAJOR >= 5 || (ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR >= 1)
|
176
|
+
ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new({}).spec(@configuration)
|
177
|
+
elsif ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR < 1
|
178
|
+
ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new(@configuration, {}).spec
|
181
179
|
else
|
182
180
|
ActiveRecord::Base::ConnectionSpecification::Resolver.new(@configuration, {}).spec
|
183
181
|
end
|
@@ -45,24 +45,34 @@ module Replidog
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def enable_query_cache!
|
48
|
-
ActiveRecord::Base.connection_handler.
|
48
|
+
connection_pool_list_for(ActiveRecord::Base.connection_handler).each do |connection_pool|
|
49
49
|
connection_pool.connection.enable_query_cache!
|
50
50
|
end
|
51
51
|
@proxies.each_value(&:enable_query_cache_for_slaves!)
|
52
52
|
end
|
53
53
|
|
54
54
|
def disable_query_cache!
|
55
|
-
ActiveRecord::Base.connection_handler.
|
55
|
+
connection_pool_list_for(ActiveRecord::Base.connection_handler).each do |connection_pool|
|
56
56
|
connection_pool.connection.disable_query_cache!
|
57
57
|
end
|
58
58
|
@proxies.each_value(&:disable_query_cache_for_slaves!)
|
59
59
|
end
|
60
60
|
|
61
61
|
def clear_query_cache
|
62
|
-
ActiveRecord::Base.connection_handler.
|
62
|
+
connection_pool_list_for(ActiveRecord::Base.connection_handler).each do |connection_pool|
|
63
63
|
connection_pool.connection.clear_query_cache
|
64
64
|
end
|
65
65
|
@proxies.each_value(&:clear_query_cache_for_slaves)
|
66
66
|
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def connection_pool_list_for(connection_handler)
|
71
|
+
if ActiveRecord::VERSION::MAJOR >= 4
|
72
|
+
connection_handler.connection_pool_list
|
73
|
+
else
|
74
|
+
connection_handler.connection_pools.values
|
75
|
+
end
|
76
|
+
end
|
67
77
|
end
|
68
78
|
end
|
data/lib/replidog/version.rb
CHANGED
@@ -8,8 +8,8 @@ Dummy::Application.configure do
|
|
8
8
|
config.cache_classes = true
|
9
9
|
|
10
10
|
# Configure static asset server for tests with Cache-Control for performance
|
11
|
-
config.serve_static_assets = true
|
12
|
-
config.static_cache_control = "public, max-age=3600"
|
11
|
+
#config.serve_static_assets = true
|
12
|
+
#config.static_cache_control = "public, max-age=3600"
|
13
13
|
|
14
14
|
# Show full error reports and disable caching
|
15
15
|
config.consider_all_requests_local = true
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: replidog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Manabu Ejima
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -279,6 +279,7 @@ files:
|
|
279
279
|
- gemfiles/rails4.gemfile
|
280
280
|
- gemfiles/rails41.gemfile
|
281
281
|
- gemfiles/rails42.gemfile
|
282
|
+
- gemfiles/rails5.gemfile
|
282
283
|
- lib/replidog.rb
|
283
284
|
- lib/replidog/active_record.rb
|
284
285
|
- lib/replidog/model.rb
|