active_record_host_pool 3.2.0 → 4.1.0
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b17ac5ef20d2f62f857a6a4a7d62ff801767e00c1d5e72b0ec05c9c9818c004
|
4
|
+
data.tar.gz: a7a6b9847c9fda19f32c0929f1a99a5362c22193b550b45602d9d8dde7efde27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d9acc6b59e50dcbeea61b75ed8f3428487ce287136c0cc95b314eb871bfff39ff7380abd779e07870d8388d775864e13d4c3b56dd91be3723904a35618c5afa
|
7
|
+
data.tar.gz: 96e926441b4e9c70fe7ffbe2f46d76eb8ab729438fa01e967eabcfe043073c928c18c3984d51cb644d6bbcef99fd6cc0d57e23af671fda2fea4665acfdbe4a94
|
data/Changelog.md
CHANGED
@@ -6,6 +6,20 @@ and as of v1.0.0 this project adheres to [Semantic Versioning](https://semver.or
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [4.1.0]
|
10
|
+
|
11
|
+
### Changed
|
12
|
+
- Remove dependency on `mutex_m`, instead using `Thread::Mutex` directly.
|
13
|
+
|
14
|
+
## [4.0.0]
|
15
|
+
|
16
|
+
### Changed
|
17
|
+
- Moved `select_db` inside of the `with_raw_connection` block of the `#raw_execute` method. This should allow for using Rails' built-in reconnect & retry logic with the Trilogy adapter or Rails 7.1+.
|
18
|
+
- In Rails 7.1+, when a new ConnectionProxy is instantiated the database switch is lazily triggered by the subsequent database query instead of immediately.
|
19
|
+
|
20
|
+
### Removed
|
21
|
+
- Calling `#clean!` and `#verified!` on connections because it is no longer necessary.
|
22
|
+
|
9
23
|
## [3.2.0]
|
10
24
|
|
11
25
|
### Added
|
@@ -14,7 +28,7 @@ and as of v1.0.0 this project adheres to [Semantic Versioning](https://semver.or
|
|
14
28
|
## [3.1.1]
|
15
29
|
|
16
30
|
### Fixed
|
17
|
-
- A typo causing `#clean!` to not run.
|
31
|
+
- A typo causing `#clean!` to not run.
|
18
32
|
|
19
33
|
## [3.1.0]
|
20
34
|
|
@@ -8,7 +8,7 @@ when :trilogy
|
|
8
8
|
when "6.1", "7.0"
|
9
9
|
require "trilogy_adapter/connection"
|
10
10
|
ActiveRecord::Base.extend(TrilogyAdapter::Connection)
|
11
|
-
when "7.1", "7.2", "8.0"
|
11
|
+
when "7.1", "7.2", "8.0", "8.1"
|
12
12
|
require "active_record/connection_adapters/trilogy_adapter"
|
13
13
|
else
|
14
14
|
raise "Unsupported version of Rails (v#{ActiveRecord::VERSION::STRING})"
|
@@ -28,20 +28,23 @@ module ActiveRecordHostPool
|
|
28
28
|
@config[:database] = _host_pool_desired_database
|
29
29
|
end
|
30
30
|
|
31
|
-
if ActiveRecord.version >= Gem::Version.new("7.1")
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
31
|
+
if ActiveRecord.version >= Gem::Version.new("7.1")
|
32
|
+
def with_raw_connection(...)
|
33
|
+
super do |real_connection|
|
34
|
+
_switch_connection(real_connection) if _host_pool_desired_database && !_no_switch
|
35
|
+
yield real_connection
|
36
|
+
end
|
37
|
+
end
|
38
|
+
elsif ActiveRecordHostPool.loaded_db_adapter == :trilogy
|
39
|
+
def with_trilogy_connection(...)
|
40
|
+
super do |real_connection|
|
41
|
+
_switch_connection(real_connection) if _host_pool_desired_database && !_no_switch
|
42
|
+
yield real_connection
|
37
43
|
end
|
38
|
-
super
|
39
44
|
end
|
40
45
|
else
|
41
46
|
def execute(...)
|
42
|
-
if _host_pool_desired_database && !_no_switch
|
43
|
-
_switch_connection
|
44
|
-
end
|
47
|
+
_switch_connection(raw_connection) if _host_pool_desired_database && !_no_switch
|
45
48
|
super
|
46
49
|
end
|
47
50
|
end
|
@@ -70,7 +73,7 @@ module ActiveRecordHostPool
|
|
70
73
|
|
71
74
|
attr_accessor :_no_switch
|
72
75
|
|
73
|
-
def _switch_connection
|
76
|
+
def _switch_connection(real_connection)
|
74
77
|
if _host_pool_desired_database &&
|
75
78
|
(
|
76
79
|
_desired_database_changed? ||
|
@@ -78,11 +81,7 @@ module ActiveRecordHostPool
|
|
78
81
|
)
|
79
82
|
log("select_db #{_host_pool_desired_database}", "SQL") do
|
80
83
|
clear_cache!
|
81
|
-
|
82
|
-
if respond_to?(:clean!)
|
83
|
-
clean!
|
84
|
-
verified!
|
85
|
-
end
|
84
|
+
real_connection.select_db(_host_pool_desired_database)
|
86
85
|
end
|
87
86
|
@_cached_current_database = _host_pool_desired_database
|
88
87
|
@_cached_connection_object_id = _real_connection_object_id
|
@@ -3,7 +3,6 @@
|
|
3
3
|
require "delegate"
|
4
4
|
require "active_record"
|
5
5
|
require "active_record_host_pool/connection_adapter_mixin"
|
6
|
-
require "mutex_m"
|
7
6
|
|
8
7
|
# this module sits in between ConnectionHandler and a bunch of different ConnectionPools (one per host).
|
9
8
|
# when a connection is requested, it goes like:
|
@@ -16,8 +15,6 @@ require "mutex_m"
|
|
16
15
|
module ActiveRecordHostPool
|
17
16
|
# Sits between ConnectionHandler and a bunch of different ConnectionPools (one per host).
|
18
17
|
class PoolProxy < Delegator
|
19
|
-
include Mutex_m
|
20
|
-
|
21
18
|
case ActiveRecordHostPool.loaded_db_adapter
|
22
19
|
when :mysql2
|
23
20
|
RESCUABLE_DB_ERROR = Mysql2::Error
|
@@ -26,9 +23,10 @@ module ActiveRecordHostPool
|
|
26
23
|
end
|
27
24
|
|
28
25
|
def initialize(pool_config)
|
29
|
-
super
|
26
|
+
super
|
30
27
|
@pool_config = pool_config
|
31
28
|
@config = pool_config.db_config.configuration_hash
|
29
|
+
@mutex = Mutex.new
|
32
30
|
end
|
33
31
|
|
34
32
|
def __getobj__
|
@@ -133,7 +131,7 @@ module ActiveRecordHostPool
|
|
133
131
|
p = _connection_pool(false)
|
134
132
|
return unless p
|
135
133
|
|
136
|
-
synchronize do
|
134
|
+
@mutex.synchronize do
|
137
135
|
p.disconnect!
|
138
136
|
p.automatic_reconnect = true
|
139
137
|
_clear_connection_proxy_cache
|
@@ -219,12 +217,7 @@ module ActiveRecordHostPool
|
|
219
217
|
@connection_proxy_cache ||= {}
|
220
218
|
key = [connection, database]
|
221
219
|
|
222
|
-
@connection_proxy_cache[key] ||=
|
223
|
-
cx = ActiveRecordHostPool::ConnectionProxy.new(connection, database)
|
224
|
-
cx.raw_execute("SELECT 1", "ARHP SWITCH DB")
|
225
|
-
|
226
|
-
cx
|
227
|
-
end
|
220
|
+
@connection_proxy_cache[key] ||= ActiveRecordHostPool::ConnectionProxy.new(connection, database)
|
228
221
|
end
|
229
222
|
end
|
230
223
|
# standard:enable Lint/DuplicateMethods
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_host_pool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Quorning
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2024-09
|
14
|
+
date: 2024-12-09 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activerecord
|
@@ -66,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
66
|
- !ruby/object:Gem::Version
|
67
67
|
version: '0'
|
68
68
|
requirements: []
|
69
|
-
rubygems_version: 3.5.
|
69
|
+
rubygems_version: 3.5.22
|
70
70
|
signing_key:
|
71
71
|
specification_version: 4
|
72
72
|
summary: Allow ActiveRecord to share a connection to multiple databases on the same
|