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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ca9a6167f644072559d4c08949399d194836f374
4
- data.tar.gz: 7b3d50bba4fa8c7c88ce17700370f598322f66e9
3
+ metadata.gz: '09a494a1422b4168371ae516d05e6afa1c4f9814'
4
+ data.tar.gz: 3d485d0a6de319a336997fb69738ce62437acff1
5
5
  SHA512:
6
- metadata.gz: d45ad8b9d6a94e932ddc397c9985553180e922bbc93032aea69be3d44253a6083d71625160ef693bb5cf6239784d33b8a43b147e0ac86d2da252cefbe02463cc
7
- data.tar.gz: 443ca893adf2d5863cbc777081427743edaf565cb7da446af307eee8669bf2916adbef6bb4182606f8cb68c3bc0f5b0d80562391eefa34205290a32a235b5a20
6
+ metadata.gz: 8ef2a51477d2babfeeecf039f002b93c61834eb8474cb00357da1c83b16ce248373f9caabe92302991ca51ea6d874cc0c390e53f63d40740e51619bb250bd23e
7
+ data.tar.gz: 25a10e0378a152b69e11c2d91e6cbd66a247ff364bc8dae8c69d44a64045be77fa97a5c0f0e99dfee1ab4fc6e08b5b3094363d55b0393bbfc2ac313b8b188703
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- active_replicas (0.2.7)
4
+ active_replicas (0.2.8)
5
5
  concurrent-ruby (~> 1.0)
6
6
 
7
7
  GEM
@@ -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] ||= begin
47
- conn = pool.connection
48
- return unless conn
49
+ @connections[pool] || synchronize do
50
+ @connections[pool] ||= begin
51
+ conn = pool.connection
52
+ return unless conn
49
53
 
50
- ProxyingConnection.new connection: conn,
51
- is_primary: pool == @primary_pool,
52
- proxy: self
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
- each_pool &:release_connection
62
+ synchronize do
63
+ each_pool &:release_connection
58
64
 
59
- @primary_depth = 0
60
- @current_pool = nil
61
- @connections.clear
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
- current_pool.connected?
76
+ synchronize do
77
+ current_pool.connected?
78
+ end
70
79
  end
71
80
 
72
81
  def disconnect!
73
- each_pool &:disconnect!
82
+ synchronize do
83
+ each_pool &:disconnect!
84
+ end
74
85
  end
75
86
 
76
87
  def current_pool
@@ -1,3 +1,3 @@
1
1
  module ActiveReplicas
2
- VERSION = "0.2.7"
2
+ VERSION = "0.2.8"
3
3
  end
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.7
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-22 00:00:00.000000000 Z
11
+ date: 2016-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby