active_record_host_pool 4.0.0 → 4.2.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 +4 -4
- data/Changelog.md +18 -1
- data/Readme.md +16 -1
- data/lib/active_record_host_pool/clear_query_cache_patch.rb +0 -11
- data/lib/active_record_host_pool/connection_adapter_mixin.rb +16 -38
- data/lib/active_record_host_pool/pool_proxy.rb +25 -35
- data/lib/active_record_host_pool/version.rb +1 -1
- data/lib/active_record_host_pool.rb +7 -14
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3944318de7c004909c8bc75a447e01e9ec1c5a44d0eb99f0449cc53880ec0d74
|
4
|
+
data.tar.gz: 1b0ec3c13a90206c9a2f02a6c0c51b92a9053ba3858a979268eea071c52c26ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9742fce5b0960f281e1e119f2e326b1b90a921f534da452f2fd67c289d18cbbdec6324dafab53e6053745f5a5bd69f01b927dcde2005fe6daaab184943758de
|
7
|
+
data.tar.gz: 69766e4f3747c105c4b98b86609faa3cb9eee8105951faa82627da8117c4eb36f66c4b5edf34e59f6fb44b25c0a47ca9242065de1eef65dcc15636a7188312bd
|
data/Changelog.md
CHANGED
@@ -6,6 +6,23 @@ and as of v1.0.0 this project adheres to [Semantic Versioning](https://semver.or
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [4.2.0]
|
10
|
+
|
11
|
+
### Changed
|
12
|
+
- ActiveRecordHostPool can now work with `mysql2` and `trilogy` if both gems are loaded.
|
13
|
+
|
14
|
+
### Added
|
15
|
+
- Testing with Rails 8.0.
|
16
|
+
|
17
|
+
### Removed
|
18
|
+
- Support for Rails 6.1 & 7.0.
|
19
|
+
- Support for Ruby 3.1.
|
20
|
+
|
21
|
+
## [4.1.0]
|
22
|
+
|
23
|
+
### Changed
|
24
|
+
- Remove dependency on `mutex_m`, instead using `Thread::Mutex` directly.
|
25
|
+
|
9
26
|
## [4.0.0]
|
10
27
|
|
11
28
|
### Changed
|
@@ -23,7 +40,7 @@ and as of v1.0.0 this project adheres to [Semantic Versioning](https://semver.or
|
|
23
40
|
## [3.1.1]
|
24
41
|
|
25
42
|
### Fixed
|
26
|
-
- A typo causing `#clean!` to not run.
|
43
|
+
- A typo causing `#clean!` to not run.
|
27
44
|
|
28
45
|
## [3.1.0]
|
29
46
|
|
data/Readme.md
CHANGED
@@ -50,7 +50,7 @@ Postgres, from an informal reading of the docs, will never support the concept o
|
|
50
50
|
|
51
51
|
$ gem install active_record_host_pool
|
52
52
|
|
53
|
-
and make sure to require '
|
53
|
+
and make sure to require 'active_record_host_pool' in some way.
|
54
54
|
|
55
55
|
## Testing
|
56
56
|
You need a local user called 'john-doe'.
|
@@ -68,6 +68,21 @@ With mysql running locally, run
|
|
68
68
|
|
69
69
|
BUNDLE_GEMFILE=gemfiles/rails6.1.gemfile ruby test/test_arhp.rb --seed 19911 --verbose
|
70
70
|
|
71
|
+
### Releasing a new version
|
72
|
+
A new version is published to RubyGems.org every time a change to `version.rb` is pushed to the `main` branch.
|
73
|
+
In short, follow these steps:
|
74
|
+
1. Update `version.rb`,
|
75
|
+
2. update version in all `Gemfile.lock` files,
|
76
|
+
3. merge this change into `main`, and
|
77
|
+
4. look at [the action](https://github.com/zendesk/active_record_host_pool/actions/workflows/publish.yml) for output.
|
78
|
+
|
79
|
+
To create a pre-release from a non-main branch:
|
80
|
+
1. change the version in `version.rb` to something like `1.2.0.pre.1` or `2.0.0.beta.2`,
|
81
|
+
2. push this change to your branch,
|
82
|
+
3. go to [Actions → “Publish to RubyGems.org” on GitHub](https://github.com/zendesk/active_record_host_pool/actions/workflows/publish.yml),
|
83
|
+
4. click the “Run workflow” button,
|
84
|
+
5. pick your branch from a dropdown.
|
85
|
+
|
71
86
|
## Copyright
|
72
87
|
|
73
88
|
Copyright (c) 2011 Zendesk. See MIT-LICENSE for details.
|
@@ -25,21 +25,10 @@ module ActiveRecordHostPool
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
28
|
-
|
29
|
-
# For Rails 6.1 & 7.0.
|
30
|
-
module ClearOnHandlerPatch
|
31
|
-
def clear_on_handler(handler)
|
32
|
-
handler.all_connection_pools.each do |pool|
|
33
|
-
pool._unproxied_connection.clear_query_cache if pool.active_connection?
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
28
|
end
|
38
29
|
|
39
30
|
case "#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"
|
40
31
|
when "7.1"
|
41
32
|
# Fix https://github.com/rails/rails/commit/401e2f24161ed6047ae33c322aaf6584b7728ab9
|
42
33
|
ActiveRecord::Base.singleton_class.prepend(ActiveRecordHostPool::ClearQueryCachePatch)
|
43
|
-
when "6.1", "7.0"
|
44
|
-
ActiveRecord::Base.singleton_class.prepend(ActiveRecordHostPool::ClearOnHandlerPatch)
|
45
34
|
end
|
@@ -1,18 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
when :mysql2
|
3
|
+
begin
|
5
4
|
require "active_record/connection_adapters/mysql2_adapter"
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
raise "Unsupported version of Rails (v#{ActiveRecord::VERSION::STRING})"
|
15
|
-
end
|
5
|
+
rescue LoadError
|
6
|
+
:noop
|
7
|
+
end
|
8
|
+
|
9
|
+
begin
|
10
|
+
require "active_record/connection_adapters/trilogy_adapter"
|
11
|
+
rescue LoadError
|
12
|
+
:noop
|
16
13
|
end
|
17
14
|
|
18
15
|
module ActiveRecordHostPool
|
@@ -28,24 +25,10 @@ module ActiveRecordHostPool
|
|
28
25
|
@config[:database] = _host_pool_desired_database
|
29
26
|
end
|
30
27
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
43
|
-
end
|
44
|
-
end
|
45
|
-
else
|
46
|
-
def execute(...)
|
47
|
-
_switch_connection(raw_connection) if _host_pool_desired_database && !_no_switch
|
48
|
-
super
|
28
|
+
def with_raw_connection(...)
|
29
|
+
super do |real_connection|
|
30
|
+
_switch_connection(real_connection) if _host_pool_desired_database && !_no_switch
|
31
|
+
yield real_connection
|
49
32
|
end
|
50
33
|
end
|
51
34
|
|
@@ -94,7 +77,7 @@ module ActiveRecordHostPool
|
|
94
77
|
|
95
78
|
# rubocop:disable Lint/DuplicateMethods
|
96
79
|
case "#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"
|
97
|
-
when "
|
80
|
+
when "7.1"
|
98
81
|
def _real_connection_object_id
|
99
82
|
@connection.object_id
|
100
83
|
end
|
@@ -122,11 +105,6 @@ module ActiveRecordHostPool
|
|
122
105
|
end
|
123
106
|
end
|
124
107
|
|
125
|
-
|
126
|
-
|
127
|
-
ActiveRecord::ConnectionAdapters::Mysql2Adapter.prepend(ActiveRecordHostPool::DatabaseSwitch)
|
128
|
-
when :trilogy
|
129
|
-
ActiveRecord::ConnectionAdapters::TrilogyAdapter.prepend(ActiveRecordHostPool::DatabaseSwitch)
|
130
|
-
end
|
131
|
-
|
108
|
+
ActiveRecord::ConnectionAdapters::Mysql2Adapter.prepend(ActiveRecordHostPool::DatabaseSwitch) if defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter)
|
109
|
+
ActiveRecord::ConnectionAdapters::TrilogyAdapter.prepend(ActiveRecordHostPool::DatabaseSwitch) if defined?(ActiveRecord::ConnectionAdapters::TrilogyAdapter)
|
132
110
|
ActiveRecord::ConnectionAdapters::PoolConfig.prepend(ActiveRecordHostPool::PoolConfigPatch)
|
@@ -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,19 +15,28 @@ 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
|
-
|
18
|
+
rescuable_db_error = []
|
19
|
+
begin
|
20
|
+
require "mysql2"
|
21
|
+
rescuable_db_error << Mysql2::Error
|
22
|
+
rescue LoadError
|
23
|
+
:noop
|
24
|
+
end
|
20
25
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
+
begin
|
27
|
+
require "trilogy"
|
28
|
+
rescuable_db_error << Trilogy::ProtocolError
|
29
|
+
rescue LoadError
|
30
|
+
:noop
|
26
31
|
end
|
27
32
|
|
33
|
+
RESCUABLE_DB_ERROR = rescuable_db_error.freeze
|
34
|
+
|
28
35
|
def initialize(pool_config)
|
29
|
-
super
|
36
|
+
super
|
30
37
|
@pool_config = pool_config
|
31
38
|
@config = pool_config.db_config.configuration_hash
|
39
|
+
@mutex = Mutex.new
|
32
40
|
end
|
33
41
|
|
34
42
|
def __getobj__
|
@@ -45,11 +53,11 @@ module ActiveRecordHostPool
|
|
45
53
|
|
46
54
|
# rubocop:disable Lint/DuplicateMethods
|
47
55
|
case "#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"
|
48
|
-
when "
|
56
|
+
when "7.1"
|
49
57
|
def connection(*args)
|
50
58
|
real_connection = _unproxied_connection(*args)
|
51
59
|
_connection_proxy_for(real_connection, @config[:database])
|
52
|
-
rescue RESCUABLE_DB_ERROR, ActiveRecord::NoDatabaseError, ActiveRecord::StatementInvalid
|
60
|
+
rescue *RESCUABLE_DB_ERROR, ActiveRecord::NoDatabaseError, ActiveRecord::StatementInvalid
|
53
61
|
_connection_pools.delete(_pool_key)
|
54
62
|
Kernel.raise
|
55
63
|
end
|
@@ -61,7 +69,7 @@ module ActiveRecordHostPool
|
|
61
69
|
def lease_connection(*args)
|
62
70
|
real_connection = _unproxied_connection(*args)
|
63
71
|
_connection_proxy_for(real_connection, @config[:database])
|
64
|
-
rescue RESCUABLE_DB_ERROR, ActiveRecord::NoDatabaseError, ActiveRecord::StatementInvalid
|
72
|
+
rescue *RESCUABLE_DB_ERROR, ActiveRecord::NoDatabaseError, ActiveRecord::StatementInvalid
|
65
73
|
_connection_pools.delete(_pool_key)
|
66
74
|
Kernel.raise
|
67
75
|
end
|
@@ -86,7 +94,7 @@ module ActiveRecordHostPool
|
|
86
94
|
end
|
87
95
|
|
88
96
|
case "#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"
|
89
|
-
when "
|
97
|
+
when "7.1"
|
90
98
|
def with_connection
|
91
99
|
cx = checkout
|
92
100
|
yield cx
|
@@ -133,7 +141,7 @@ module ActiveRecordHostPool
|
|
133
141
|
p = _connection_pool(false)
|
134
142
|
return unless p
|
135
143
|
|
136
|
-
synchronize do
|
144
|
+
@mutex.synchronize do
|
137
145
|
p.disconnect!
|
138
146
|
p.automatic_reconnect = true
|
139
147
|
_clear_connection_proxy_cache
|
@@ -199,30 +207,12 @@ module ActiveRecordHostPool
|
|
199
207
|
pool
|
200
208
|
end
|
201
209
|
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
when "6.1", "7.0"
|
206
|
-
def _connection_proxy_for(connection, database)
|
207
|
-
@connection_proxy_cache ||= {}
|
208
|
-
key = [connection, database]
|
210
|
+
def _connection_proxy_for(connection, database)
|
211
|
+
@connection_proxy_cache ||= {}
|
212
|
+
key = [connection, database]
|
209
213
|
|
210
|
-
|
211
|
-
cx = ActiveRecordHostPool::ConnectionProxy.new(connection, database)
|
212
|
-
cx.execute("SELECT 1")
|
213
|
-
|
214
|
-
cx
|
215
|
-
end
|
216
|
-
end
|
217
|
-
else
|
218
|
-
def _connection_proxy_for(connection, database)
|
219
|
-
@connection_proxy_cache ||= {}
|
220
|
-
key = [connection, database]
|
221
|
-
|
222
|
-
@connection_proxy_cache[key] ||= ActiveRecordHostPool::ConnectionProxy.new(connection, database)
|
223
|
-
end
|
214
|
+
@connection_proxy_cache[key] ||= ActiveRecordHostPool::ConnectionProxy.new(connection, database)
|
224
215
|
end
|
225
|
-
# standard:enable Lint/DuplicateMethods
|
226
216
|
|
227
217
|
def _clear_connection_proxy_cache
|
228
218
|
@connection_proxy_cache = {}
|
@@ -4,23 +4,16 @@ require "active_record"
|
|
4
4
|
require "active_record/base"
|
5
5
|
require "active_record/connection_adapters/abstract_adapter"
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
begin
|
8
|
+
require "mysql2"
|
9
|
+
rescue LoadError
|
10
|
+
:noop
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
require "mysql2"
|
15
|
-
ActiveRecordHostPool.loaded_db_adapter = :mysql2
|
16
|
-
elsif Gem.loaded_specs.include?("trilogy")
|
13
|
+
begin
|
17
14
|
require "trilogy"
|
18
|
-
|
19
|
-
|
20
|
-
require "trilogy_adapter/version"
|
21
|
-
raise "ActiveRecordHostPool is only compatible with activerecord-trilogy-adapter v3.1+" if Gem::Version.new("3.1") > TrilogyAdapter::VERSION
|
22
|
-
end
|
23
|
-
ActiveRecordHostPool.loaded_db_adapter = :trilogy
|
15
|
+
rescue LoadError
|
16
|
+
:noop
|
24
17
|
end
|
25
18
|
|
26
19
|
require "active_record_host_pool/clear_query_cache_patch"
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_host_pool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Quorning
|
8
8
|
- Gabe Martin-Dempesy
|
9
9
|
- Pierre Schambacher
|
10
10
|
- Ben Osheroff
|
11
|
-
autorequire:
|
11
|
+
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2025-04-18 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activerecord
|
@@ -19,14 +19,14 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
22
|
+
version: 7.1.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 7.1.0
|
30
30
|
description: ''
|
31
31
|
email:
|
32
32
|
- bquorning@zendesk.com
|
@@ -51,7 +51,7 @@ homepage: https://github.com/zendesk/active_record_host_pool
|
|
51
51
|
licenses:
|
52
52
|
- MIT
|
53
53
|
metadata: {}
|
54
|
-
post_install_message:
|
54
|
+
post_install_message:
|
55
55
|
rdoc_options: []
|
56
56
|
require_paths:
|
57
57
|
- lib
|
@@ -59,15 +59,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
59
59
|
requirements:
|
60
60
|
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: 3.
|
62
|
+
version: 3.2.0
|
63
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
65
|
- - ">="
|
66
66
|
- !ruby/object:Gem::Version
|
67
67
|
version: '0'
|
68
68
|
requirements: []
|
69
|
-
rubygems_version: 3.
|
70
|
-
signing_key:
|
69
|
+
rubygems_version: 3.4.19
|
70
|
+
signing_key:
|
71
71
|
specification_version: 4
|
72
72
|
summary: Allow ActiveRecord to share a connection to multiple databases on the same
|
73
73
|
host
|