active_replicas 0.2.7 → 0.2.8
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.
- checksums.yaml +4 -4
- data/gemfiles/rails_4.gemfile.lock +1 -1
- data/lib/active_replicas/proxying_connection_pool.rb +23 -12
- data/lib/active_replicas/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09a494a1422b4168371ae516d05e6afa1c4f9814'
|
4
|
+
data.tar.gz: 3d485d0a6de319a336997fb69738ce62437acff1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ef2a51477d2babfeeecf039f002b93c61834eb8474cb00357da1c83b16ce248373f9caabe92302991ca51ea6d874cc0c390e53f63d40740e51619bb250bd23e
|
7
|
+
data.tar.gz: 25a10e0378a152b69e11c2d91e6cbd66a247ff364bc8dae8c69d44a64045be77fa97a5c0f0e99dfee1ab4fc6e08b5b3094363d55b0393bbfc2ac313b8b188703
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'monitor'
|
1
2
|
require 'active_support/hash_with_indifferent_access'
|
2
3
|
|
3
4
|
module ActiveReplicas
|
@@ -23,6 +24,8 @@ module ActiveReplicas
|
|
23
24
|
# Thread-safe map of the connections from each pool. Cleared in tandem
|
24
25
|
# with the connection pools.
|
25
26
|
@connections = Concurrent::Map.new
|
27
|
+
|
28
|
+
extend MonitorMixin
|
26
29
|
end
|
27
30
|
|
28
31
|
# Returns an instance of `ActiveRecord::ConnectionAdapters::ConnectionPool`
|
@@ -43,22 +46,26 @@ module ActiveReplicas
|
|
43
46
|
def connection
|
44
47
|
pool = current_pool
|
45
48
|
|
46
|
-
@connections[pool]
|
47
|
-
|
48
|
-
|
49
|
+
@connections[pool] || synchronize do
|
50
|
+
@connections[pool] ||= begin
|
51
|
+
conn = pool.connection
|
52
|
+
return unless conn
|
49
53
|
|
50
|
-
|
51
|
-
|
52
|
-
|
54
|
+
ProxyingConnection.new connection: conn,
|
55
|
+
is_primary: pool == @primary_pool,
|
56
|
+
proxy: self
|
57
|
+
end
|
53
58
|
end
|
54
59
|
end
|
55
60
|
|
56
61
|
def release_connection
|
57
|
-
|
62
|
+
synchronize do
|
63
|
+
each_pool &:release_connection
|
58
64
|
|
59
|
-
|
60
|
-
|
61
|
-
|
65
|
+
@primary_depth = 0
|
66
|
+
@current_pool = nil
|
67
|
+
@connections.clear
|
68
|
+
end
|
62
69
|
end
|
63
70
|
|
64
71
|
def with_connection(&block)
|
@@ -66,11 +73,15 @@ module ActiveReplicas
|
|
66
73
|
end
|
67
74
|
|
68
75
|
def connected?
|
69
|
-
|
76
|
+
synchronize do
|
77
|
+
current_pool.connected?
|
78
|
+
end
|
70
79
|
end
|
71
80
|
|
72
81
|
def disconnect!
|
73
|
-
|
82
|
+
synchronize do
|
83
|
+
each_pool &:disconnect!
|
84
|
+
end
|
74
85
|
end
|
75
86
|
|
76
87
|
def current_pool
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_replicas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dirk Gadsden
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|