active_record_host_pool 4.1.0 → 4.3.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 +24 -0
- data/Readme.md +19 -8
- data/lib/active_record_host_pool/connection_adapter_mixin.rb +28 -49
- data/lib/active_record_host_pool/connection_proxy.rb +10 -5
- data/lib/active_record_host_pool/pool_proxy.rb +56 -91
- data/lib/active_record_host_pool/version.rb +1 -1
- data/lib/active_record_host_pool.rb +7 -15
- metadata +9 -10
- data/lib/active_record_host_pool/clear_query_cache_patch.rb +0 -45
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fced473565b601f6ec0a0e682b254c251d653c10be16690c46470d418dd9f346
|
|
4
|
+
data.tar.gz: 7281ce45c44d5209f16444e55caaaf4c2a059981d6a41a48d45d0f394c08b4a3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a053ec7e487686f9ab3aa0b5c01912292aee086f3d9e2444e715c99f9ef278c564b2a48b8eceb68030972c10ac20c04b20745689e88efdd9ae333256a033a371
|
|
7
|
+
data.tar.gz: d6f6bc52d1e46987faf4b7d57b7e6df43464e60ed978b3337056957f3e8d5b98ed1fc38f156ea1766b7c299ee1094a68e3ec6a13e8741117e311cb23d54ce385
|
data/Changelog.md
CHANGED
|
@@ -6,6 +6,30 @@ and as of v1.0.0 this project adheres to [Semantic Versioning](https://semver.or
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [4.3.0]
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
- `.class_eval` now raises an exception when called on `ConnectionProxy`. Use `.arhp_connection_proxy_class_eval` if you _really_ need to modify the `ConnectionProxy` class.
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
- Testing with Rails 8.1.
|
|
16
|
+
|
|
17
|
+
### Removed
|
|
18
|
+
- `ConnectionProxy` no longer overrides `#class` to return the class of the proxied connection adapter.
|
|
19
|
+
- Support for Rails 7.1.
|
|
20
|
+
|
|
21
|
+
## [4.2.0]
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
- ActiveRecordHostPool can now work with `mysql2` and `trilogy` if both gems are loaded.
|
|
25
|
+
|
|
26
|
+
### Added
|
|
27
|
+
- Testing with Rails 8.0.
|
|
28
|
+
|
|
29
|
+
### Removed
|
|
30
|
+
- Support for Rails 6.1 & 7.0.
|
|
31
|
+
- Support for Ruby 3.1.
|
|
32
|
+
|
|
9
33
|
## [4.1.0]
|
|
10
34
|
|
|
11
35
|
### Changed
|
data/Readme.md
CHANGED
|
@@ -50,24 +50,35 @@ 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
|
-
You need a local user called 'john-doe'.
|
|
57
56
|
|
|
58
|
-
|
|
59
|
-
CREATE USER 'john-doe'@'localhost';
|
|
60
|
-
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX ON *.* TO 'john-doe'@'localhost';
|
|
61
|
-
FLUSH PRIVILEGES;
|
|
57
|
+
TestContainers will take care of setting up the necessary MySQL servers for you. You just need to have e.g. Docker running.
|
|
62
58
|
|
|
63
|
-
|
|
59
|
+
Run e.g.
|
|
64
60
|
|
|
65
61
|
BUNDLE_GEMFILE=gemfiles/rails6.1.gemfile bundle exec rake test
|
|
66
62
|
|
|
67
|
-
|
|
63
|
+
or
|
|
68
64
|
|
|
69
65
|
BUNDLE_GEMFILE=gemfiles/rails6.1.gemfile ruby test/test_arhp.rb --seed 19911 --verbose
|
|
70
66
|
|
|
67
|
+
### Releasing a new version
|
|
68
|
+
A new version is published to RubyGems.org every time a change to `version.rb` is pushed to the `main` branch.
|
|
69
|
+
In short, follow these steps:
|
|
70
|
+
1. Update `version.rb`,
|
|
71
|
+
2. update version in all `Gemfile.lock` files,
|
|
72
|
+
3. merge this change into `main`, and
|
|
73
|
+
4. look at [the action](https://github.com/zendesk/active_record_host_pool/actions/workflows/publish.yml) for output.
|
|
74
|
+
|
|
75
|
+
To create a pre-release from a non-main branch:
|
|
76
|
+
1. change the version in `version.rb` to something like `1.2.0.pre.1` or `2.0.0.beta.2`,
|
|
77
|
+
2. push this change to your branch,
|
|
78
|
+
3. go to [Actions → “Publish to RubyGems.org” on GitHub](https://github.com/zendesk/active_record_host_pool/actions/workflows/publish.yml),
|
|
79
|
+
4. click the “Run workflow” button,
|
|
80
|
+
5. pick your branch from a dropdown.
|
|
81
|
+
|
|
71
82
|
## Copyright
|
|
72
83
|
|
|
73
84
|
Copyright (c) 2011 Zendesk. See MIT-LICENSE for details.
|
|
@@ -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
|
|
|
@@ -79,7 +62,7 @@ module ActiveRecordHostPool
|
|
|
79
62
|
_desired_database_changed? ||
|
|
80
63
|
_real_connection_changed?
|
|
81
64
|
)
|
|
82
|
-
log(
|
|
65
|
+
log(select_db_log_arg, "SQL") do
|
|
83
66
|
clear_cache!
|
|
84
67
|
real_connection.select_db(_host_pool_desired_database)
|
|
85
68
|
end
|
|
@@ -88,22 +71,23 @@ module ActiveRecordHostPool
|
|
|
88
71
|
end
|
|
89
72
|
end
|
|
90
73
|
|
|
74
|
+
if ActiveRecord.version < Gem::Version.new("8.2.a")
|
|
75
|
+
def select_db_log_arg
|
|
76
|
+
"select_db #{_host_pool_desired_database}"
|
|
77
|
+
end
|
|
78
|
+
else
|
|
79
|
+
def select_db_log_arg
|
|
80
|
+
ActiveRecord::ConnectionAdapters::QueryIntent.new(processed_sql: "select_db #{_host_pool_desired_database}")
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
91
84
|
def _desired_database_changed?
|
|
92
85
|
_host_pool_desired_database != @_cached_current_database
|
|
93
86
|
end
|
|
94
87
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
when "6.1", "7.0", "7.1"
|
|
98
|
-
def _real_connection_object_id
|
|
99
|
-
@connection.object_id
|
|
100
|
-
end
|
|
101
|
-
else
|
|
102
|
-
def _real_connection_object_id
|
|
103
|
-
@raw_connection.object_id
|
|
104
|
-
end
|
|
88
|
+
def _real_connection_object_id
|
|
89
|
+
@raw_connection.object_id
|
|
105
90
|
end
|
|
106
|
-
# rubocop:enable Lint/DuplicateMethods
|
|
107
91
|
|
|
108
92
|
def _real_connection_changed?
|
|
109
93
|
_real_connection_object_id != @_cached_connection_object_id
|
|
@@ -122,11 +106,6 @@ module ActiveRecordHostPool
|
|
|
122
106
|
end
|
|
123
107
|
end
|
|
124
108
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
ActiveRecord::ConnectionAdapters::Mysql2Adapter.prepend(ActiveRecordHostPool::DatabaseSwitch)
|
|
128
|
-
when :trilogy
|
|
129
|
-
ActiveRecord::ConnectionAdapters::TrilogyAdapter.prepend(ActiveRecordHostPool::DatabaseSwitch)
|
|
130
|
-
end
|
|
131
|
-
|
|
109
|
+
ActiveRecord::ConnectionAdapters::Mysql2Adapter.prepend(ActiveRecordHostPool::DatabaseSwitch) if defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter)
|
|
110
|
+
ActiveRecord::ConnectionAdapters::TrilogyAdapter.prepend(ActiveRecordHostPool::DatabaseSwitch) if defined?(ActiveRecord::ConnectionAdapters::TrilogyAdapter)
|
|
132
111
|
ActiveRecord::ConnectionAdapters::PoolConfig.prepend(ActiveRecordHostPool::PoolConfigPatch)
|
|
@@ -6,6 +6,16 @@ require "delegate"
|
|
|
6
6
|
# for each call to the connection. upon executing a statement, the connection will switch to that database.
|
|
7
7
|
module ActiveRecordHostPool
|
|
8
8
|
class ConnectionProxy < Delegator
|
|
9
|
+
class << self
|
|
10
|
+
def class_eval
|
|
11
|
+
raise "You probably want to call .class_eval on the ActiveRecord connection adapter and not on ActiveRecordHostPool's connection proxy. Use .arhp_connection_proxy_class_eval if you _really_ know what you're doing."
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def arhp_connection_proxy_class_eval(...)
|
|
15
|
+
method(:class_eval).super_method.call(...)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
9
19
|
attr_reader :database
|
|
10
20
|
def initialize(cx, database)
|
|
11
21
|
super(cx)
|
|
@@ -26,11 +36,6 @@ module ActiveRecordHostPool
|
|
|
26
36
|
@cx
|
|
27
37
|
end
|
|
28
38
|
|
|
29
|
-
# this is bad. I know. but it allows folks who class_eval on connection.class to do so
|
|
30
|
-
def class
|
|
31
|
-
@cx.class
|
|
32
|
-
end
|
|
33
|
-
|
|
34
39
|
def expects(*args)
|
|
35
40
|
@cx.send(:expects, *args)
|
|
36
41
|
end
|
|
@@ -15,13 +15,23 @@ require "active_record_host_pool/connection_adapter_mixin"
|
|
|
15
15
|
module ActiveRecordHostPool
|
|
16
16
|
# Sits between ConnectionHandler and a bunch of different ConnectionPools (one per host).
|
|
17
17
|
class PoolProxy < Delegator
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
rescuable_db_error = []
|
|
19
|
+
begin
|
|
20
|
+
require "mysql2"
|
|
21
|
+
rescuable_db_error << Mysql2::Error
|
|
22
|
+
rescue LoadError
|
|
23
|
+
:noop
|
|
23
24
|
end
|
|
24
25
|
|
|
26
|
+
begin
|
|
27
|
+
require "trilogy"
|
|
28
|
+
rescuable_db_error << Trilogy::ProtocolError
|
|
29
|
+
rescue LoadError
|
|
30
|
+
:noop
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
RESCUABLE_DB_ERROR = rescuable_db_error.freeze
|
|
34
|
+
|
|
25
35
|
def initialize(pool_config)
|
|
26
36
|
super
|
|
27
37
|
@pool_config = pool_config
|
|
@@ -41,35 +51,18 @@ module ActiveRecordHostPool
|
|
|
41
51
|
|
|
42
52
|
attr_reader :pool_config
|
|
43
53
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
Kernel.raise
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def _unproxied_connection(*args)
|
|
56
|
-
_connection_pool.connection(*args)
|
|
57
|
-
end
|
|
58
|
-
else
|
|
59
|
-
def lease_connection(*args)
|
|
60
|
-
real_connection = _unproxied_connection(*args)
|
|
61
|
-
_connection_proxy_for(real_connection, @config[:database])
|
|
62
|
-
rescue RESCUABLE_DB_ERROR, ActiveRecord::NoDatabaseError, ActiveRecord::StatementInvalid
|
|
63
|
-
_connection_pools.delete(_pool_key)
|
|
64
|
-
Kernel.raise
|
|
65
|
-
end
|
|
66
|
-
alias_method :connection, :lease_connection
|
|
54
|
+
def lease_connection(*args)
|
|
55
|
+
real_connection = _unproxied_connection(*args)
|
|
56
|
+
_connection_proxy_for(real_connection, @config[:database])
|
|
57
|
+
rescue *RESCUABLE_DB_ERROR, ActiveRecord::NoDatabaseError, ActiveRecord::StatementInvalid
|
|
58
|
+
_connection_pools.delete(_pool_key)
|
|
59
|
+
Kernel.raise
|
|
60
|
+
end
|
|
61
|
+
alias_method :connection, :lease_connection
|
|
67
62
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
end
|
|
63
|
+
def _unproxied_connection(*args)
|
|
64
|
+
_connection_pool.lease_connection(*args)
|
|
71
65
|
end
|
|
72
|
-
# rubocop:enable Lint/DuplicateMethods
|
|
73
66
|
|
|
74
67
|
# by the time we are patched into ActiveRecord, the current thread has already established
|
|
75
68
|
# a connection. thus we need to patch both connection and checkout/checkin
|
|
@@ -83,49 +76,39 @@ module ActiveRecordHostPool
|
|
|
83
76
|
_connection_pool.checkin(cx)
|
|
84
77
|
end
|
|
85
78
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
yield cx
|
|
91
|
-
ensure
|
|
92
|
-
checkin cx
|
|
93
|
-
end
|
|
94
|
-
else
|
|
95
|
-
def with_connection(prevent_permanent_checkout: false) # rubocop:disable Lint/DuplicateMethods
|
|
96
|
-
real_connection_lease = _connection_pool.send(:connection_lease)
|
|
97
|
-
sticky_was = real_connection_lease.sticky
|
|
98
|
-
real_connection_lease.sticky = false if prevent_permanent_checkout
|
|
99
|
-
|
|
100
|
-
if real_connection_lease.connection
|
|
101
|
-
begin
|
|
102
|
-
yield _connection_proxy_for(real_connection_lease.connection, @config[:database])
|
|
103
|
-
ensure
|
|
104
|
-
real_connection_lease.sticky = sticky_was if prevent_permanent_checkout && !sticky_was
|
|
105
|
-
end
|
|
106
|
-
else
|
|
107
|
-
begin
|
|
108
|
-
real_connection_lease.connection = _unproxied_connection
|
|
109
|
-
yield _connection_proxy_for(real_connection_lease.connection, @config[:database])
|
|
110
|
-
ensure
|
|
111
|
-
real_connection_lease.sticky = sticky_was if prevent_permanent_checkout && !sticky_was
|
|
112
|
-
_connection_pool.release_connection(real_connection_lease) unless real_connection_lease.sticky
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
end
|
|
79
|
+
def with_connection(prevent_permanent_checkout: false) # rubocop:disable Lint/DuplicateMethods
|
|
80
|
+
real_connection_lease = _connection_pool.send(:connection_lease)
|
|
81
|
+
sticky_was = real_connection_lease.sticky
|
|
82
|
+
real_connection_lease.sticky = false if prevent_permanent_checkout
|
|
116
83
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
84
|
+
if real_connection_lease.connection
|
|
85
|
+
begin
|
|
86
|
+
yield _connection_proxy_for(real_connection_lease.connection, @config[:database])
|
|
87
|
+
ensure
|
|
88
|
+
real_connection_lease.sticky = sticky_was if prevent_permanent_checkout && !sticky_was
|
|
89
|
+
end
|
|
90
|
+
else
|
|
91
|
+
begin
|
|
92
|
+
real_connection_lease.connection = _unproxied_connection
|
|
93
|
+
yield _connection_proxy_for(real_connection_lease.connection, @config[:database])
|
|
94
|
+
ensure
|
|
95
|
+
real_connection_lease.sticky = sticky_was if prevent_permanent_checkout && !sticky_was
|
|
96
|
+
_connection_pool.release_connection(real_connection_lease) unless real_connection_lease.sticky
|
|
121
97
|
end
|
|
122
98
|
end
|
|
123
|
-
|
|
99
|
+
end
|
|
124
100
|
|
|
125
|
-
|
|
126
|
-
|
|
101
|
+
def active_connection?
|
|
102
|
+
real_connection_lease = _connection_pool.send(:connection_lease)
|
|
103
|
+
if real_connection_lease.connection
|
|
104
|
+
_connection_proxy_for(real_connection_lease.connection, @config[:database])
|
|
127
105
|
end
|
|
128
106
|
end
|
|
107
|
+
alias_method :active_connection, :active_connection?
|
|
108
|
+
|
|
109
|
+
def schema_cache
|
|
110
|
+
@schema_cache ||= ActiveRecord::ConnectionAdapters::BoundSchemaReflection.new(_connection_pool.schema_reflection, self)
|
|
111
|
+
end
|
|
129
112
|
|
|
130
113
|
def disconnect!
|
|
131
114
|
p = _connection_pool(false)
|
|
@@ -197,30 +180,12 @@ module ActiveRecordHostPool
|
|
|
197
180
|
pool
|
|
198
181
|
end
|
|
199
182
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
when "6.1", "7.0"
|
|
204
|
-
def _connection_proxy_for(connection, database)
|
|
205
|
-
@connection_proxy_cache ||= {}
|
|
206
|
-
key = [connection, database]
|
|
183
|
+
def _connection_proxy_for(connection, database)
|
|
184
|
+
@connection_proxy_cache ||= {}
|
|
185
|
+
key = [connection, database]
|
|
207
186
|
|
|
208
|
-
|
|
209
|
-
cx = ActiveRecordHostPool::ConnectionProxy.new(connection, database)
|
|
210
|
-
cx.execute("SELECT 1")
|
|
211
|
-
|
|
212
|
-
cx
|
|
213
|
-
end
|
|
214
|
-
end
|
|
215
|
-
else
|
|
216
|
-
def _connection_proxy_for(connection, database)
|
|
217
|
-
@connection_proxy_cache ||= {}
|
|
218
|
-
key = [connection, database]
|
|
219
|
-
|
|
220
|
-
@connection_proxy_cache[key] ||= ActiveRecordHostPool::ConnectionProxy.new(connection, database)
|
|
221
|
-
end
|
|
187
|
+
@connection_proxy_cache[key] ||= ActiveRecordHostPool::ConnectionProxy.new(connection, database)
|
|
222
188
|
end
|
|
223
|
-
# standard:enable Lint/DuplicateMethods
|
|
224
189
|
|
|
225
190
|
def _clear_connection_proxy_cache
|
|
226
191
|
@connection_proxy_cache = {}
|
|
@@ -4,26 +4,18 @@ 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
|
-
require "active_record_host_pool/clear_query_cache_patch"
|
|
27
19
|
require "active_record_host_pool/connection_proxy"
|
|
28
20
|
require "active_record_host_pool/pool_proxy"
|
|
29
21
|
require "active_record_host_pool/connection_adapter_mixin"
|
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.3.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-11-11 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.2.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.2.0
|
|
30
30
|
description: ''
|
|
31
31
|
email:
|
|
32
32
|
- bquorning@zendesk.com
|
|
@@ -42,7 +42,6 @@ files:
|
|
|
42
42
|
- MIT-LICENSE
|
|
43
43
|
- Readme.md
|
|
44
44
|
- lib/active_record_host_pool.rb
|
|
45
|
-
- lib/active_record_host_pool/clear_query_cache_patch.rb
|
|
46
45
|
- lib/active_record_host_pool/connection_adapter_mixin.rb
|
|
47
46
|
- lib/active_record_host_pool/connection_proxy.rb
|
|
48
47
|
- lib/active_record_host_pool/pool_proxy.rb
|
|
@@ -51,7 +50,7 @@ homepage: https://github.com/zendesk/active_record_host_pool
|
|
|
51
50
|
licenses:
|
|
52
51
|
- MIT
|
|
53
52
|
metadata: {}
|
|
54
|
-
post_install_message:
|
|
53
|
+
post_install_message:
|
|
55
54
|
rdoc_options: []
|
|
56
55
|
require_paths:
|
|
57
56
|
- lib
|
|
@@ -59,15 +58,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
59
58
|
requirements:
|
|
60
59
|
- - ">="
|
|
61
60
|
- !ruby/object:Gem::Version
|
|
62
|
-
version: 3.
|
|
61
|
+
version: 3.2.0
|
|
63
62
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
63
|
requirements:
|
|
65
64
|
- - ">="
|
|
66
65
|
- !ruby/object:Gem::Version
|
|
67
66
|
version: '0'
|
|
68
67
|
requirements: []
|
|
69
|
-
rubygems_version: 3.
|
|
70
|
-
signing_key:
|
|
68
|
+
rubygems_version: 3.4.19
|
|
69
|
+
signing_key:
|
|
71
70
|
specification_version: 4
|
|
72
71
|
summary: Allow ActiveRecord to share a connection to multiple databases on the same
|
|
73
72
|
host
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# ActiveRecord 6.0 introduced multiple database support. With that, an update
|
|
4
|
-
# has been made in https://github.com/rails/rails/pull/35089 to ensure that
|
|
5
|
-
# all query caches are cleared across connection handlers and pools. If you
|
|
6
|
-
# write on one connection, the other connection will have the update that
|
|
7
|
-
# occurred.
|
|
8
|
-
#
|
|
9
|
-
# This broke ARHP which implements its own pool, allowing you to access
|
|
10
|
-
# multiple databases with the same connection (e.g. 1 connection for 100
|
|
11
|
-
# shards on the same server).
|
|
12
|
-
#
|
|
13
|
-
# This patch maintains the reference to the database during the cache clearing
|
|
14
|
-
# to ensure that the database doesn't get swapped out mid-way into an
|
|
15
|
-
# operation.
|
|
16
|
-
#
|
|
17
|
-
# This is a private Rails API and may change in future releases as they're
|
|
18
|
-
# actively working on sharding in Rails 6 and above.
|
|
19
|
-
module ActiveRecordHostPool
|
|
20
|
-
# For Rails 7.1.
|
|
21
|
-
module ClearQueryCachePatch
|
|
22
|
-
def clear_query_caches_for_current_thread
|
|
23
|
-
connection_handler.each_connection_pool do |pool|
|
|
24
|
-
pool._unproxied_connection.clear_query_cache if pool.active_connection?
|
|
25
|
-
end
|
|
26
|
-
end
|
|
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
|
-
end
|
|
38
|
-
|
|
39
|
-
case "#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"
|
|
40
|
-
when "7.1"
|
|
41
|
-
# Fix https://github.com/rails/rails/commit/401e2f24161ed6047ae33c322aaf6584b7728ab9
|
|
42
|
-
ActiveRecord::Base.singleton_class.prepend(ActiveRecordHostPool::ClearQueryCachePatch)
|
|
43
|
-
when "6.1", "7.0"
|
|
44
|
-
ActiveRecord::Base.singleton_class.prepend(ActiveRecordHostPool::ClearOnHandlerPatch)
|
|
45
|
-
end
|