active_record_host_pool 4.0.0 → 4.3.1
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 +34 -1
- 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 +58 -95
- 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: bbf1c2173865a9d635564bb5cb677e42dedff46a8f44ec186799fdfd78500267
|
|
4
|
+
data.tar.gz: 4e4c49fd589cf06671b0d2a94042179a38321b5c2720cdfc5114366eb7448166
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 670fba2e8c6ca93ea22af70ba7b3642ef22d9dcf60a9afc9dedfd8f7443b47cbd127e910092d61029b41ab99eb273d1dad3ec98be52238011d2c756195168a4a
|
|
7
|
+
data.tar.gz: 7bc8ea4b1998f22474b880e4deee809c8f1f29e9eee7a87befa315e5ab2b46bd4a38c1fa79e629ecb04e37f8a334ecd95c85d02a809b95bc9dd8ab70cc10315c
|
data/Changelog.md
CHANGED
|
@@ -6,6 +6,39 @@ 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.1]
|
|
10
|
+
|
|
11
|
+
- Better compatibility with Rails 8.2 alpha.
|
|
12
|
+
|
|
13
|
+
## [4.3.0]
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
- `.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.
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
- Testing with Rails 8.1.
|
|
20
|
+
|
|
21
|
+
### Removed
|
|
22
|
+
- `ConnectionProxy` no longer overrides `#class` to return the class of the proxied connection adapter.
|
|
23
|
+
- Support for Rails 7.1.
|
|
24
|
+
|
|
25
|
+
## [4.2.0]
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
- ActiveRecordHostPool can now work with `mysql2` and `trilogy` if both gems are loaded.
|
|
29
|
+
|
|
30
|
+
### Added
|
|
31
|
+
- Testing with Rails 8.0.
|
|
32
|
+
|
|
33
|
+
### Removed
|
|
34
|
+
- Support for Rails 6.1 & 7.0.
|
|
35
|
+
- Support for Ruby 3.1.
|
|
36
|
+
|
|
37
|
+
## [4.1.0]
|
|
38
|
+
|
|
39
|
+
### Changed
|
|
40
|
+
- Remove dependency on `mutex_m`, instead using `Thread::Mutex` directly.
|
|
41
|
+
|
|
9
42
|
## [4.0.0]
|
|
10
43
|
|
|
11
44
|
### Changed
|
|
@@ -23,7 +56,7 @@ and as of v1.0.0 this project adheres to [Semantic Versioning](https://semver.or
|
|
|
23
56
|
## [3.1.1]
|
|
24
57
|
|
|
25
58
|
### Fixed
|
|
26
|
-
- A typo causing `#clean!` to not run.
|
|
59
|
+
- A typo causing `#clean!` to not run.
|
|
27
60
|
|
|
28
61
|
## [3.1.0]
|
|
29
62
|
|
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(adapter: self, 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
|
|
@@ -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__
|
|
@@ -43,35 +51,18 @@ module ActiveRecordHostPool
|
|
|
43
51
|
|
|
44
52
|
attr_reader :pool_config
|
|
45
53
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
Kernel.raise
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def _unproxied_connection(*args)
|
|
58
|
-
_connection_pool.connection(*args)
|
|
59
|
-
end
|
|
60
|
-
else
|
|
61
|
-
def lease_connection(*args)
|
|
62
|
-
real_connection = _unproxied_connection(*args)
|
|
63
|
-
_connection_proxy_for(real_connection, @config[:database])
|
|
64
|
-
rescue RESCUABLE_DB_ERROR, ActiveRecord::NoDatabaseError, ActiveRecord::StatementInvalid
|
|
65
|
-
_connection_pools.delete(_pool_key)
|
|
66
|
-
Kernel.raise
|
|
67
|
-
end
|
|
68
|
-
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
|
|
69
62
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
end
|
|
63
|
+
def _unproxied_connection(*args)
|
|
64
|
+
_connection_pool.lease_connection(*args)
|
|
73
65
|
end
|
|
74
|
-
# rubocop:enable Lint/DuplicateMethods
|
|
75
66
|
|
|
76
67
|
# by the time we are patched into ActiveRecord, the current thread has already established
|
|
77
68
|
# a connection. thus we need to patch both connection and checkout/checkin
|
|
@@ -85,55 +76,45 @@ module ActiveRecordHostPool
|
|
|
85
76
|
_connection_pool.checkin(cx)
|
|
86
77
|
end
|
|
87
78
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
yield cx
|
|
93
|
-
ensure
|
|
94
|
-
checkin cx
|
|
95
|
-
end
|
|
96
|
-
else
|
|
97
|
-
def with_connection(prevent_permanent_checkout: false) # rubocop:disable Lint/DuplicateMethods
|
|
98
|
-
real_connection_lease = _connection_pool.send(:connection_lease)
|
|
99
|
-
sticky_was = real_connection_lease.sticky
|
|
100
|
-
real_connection_lease.sticky = false if prevent_permanent_checkout
|
|
101
|
-
|
|
102
|
-
if real_connection_lease.connection
|
|
103
|
-
begin
|
|
104
|
-
yield _connection_proxy_for(real_connection_lease.connection, @config[:database])
|
|
105
|
-
ensure
|
|
106
|
-
real_connection_lease.sticky = sticky_was if prevent_permanent_checkout && !sticky_was
|
|
107
|
-
end
|
|
108
|
-
else
|
|
109
|
-
begin
|
|
110
|
-
real_connection_lease.connection = _unproxied_connection
|
|
111
|
-
yield _connection_proxy_for(real_connection_lease.connection, @config[:database])
|
|
112
|
-
ensure
|
|
113
|
-
real_connection_lease.sticky = sticky_was if prevent_permanent_checkout && !sticky_was
|
|
114
|
-
_connection_pool.release_connection(real_connection_lease) unless real_connection_lease.sticky
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
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
|
|
118
83
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
|
123
97
|
end
|
|
124
98
|
end
|
|
125
|
-
|
|
99
|
+
end
|
|
126
100
|
|
|
127
|
-
|
|
128
|
-
|
|
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])
|
|
129
105
|
end
|
|
130
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
|
|
131
112
|
|
|
132
113
|
def disconnect!
|
|
133
114
|
p = _connection_pool(false)
|
|
134
115
|
return unless p
|
|
135
116
|
|
|
136
|
-
synchronize do
|
|
117
|
+
@mutex.synchronize do
|
|
137
118
|
p.disconnect!
|
|
138
119
|
p.automatic_reconnect = true
|
|
139
120
|
_clear_connection_proxy_cache
|
|
@@ -199,30 +180,12 @@ module ActiveRecordHostPool
|
|
|
199
180
|
pool
|
|
200
181
|
end
|
|
201
182
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
when "6.1", "7.0"
|
|
206
|
-
def _connection_proxy_for(connection, database)
|
|
207
|
-
@connection_proxy_cache ||= {}
|
|
208
|
-
key = [connection, database]
|
|
183
|
+
def _connection_proxy_for(connection, database)
|
|
184
|
+
@connection_proxy_cache ||= {}
|
|
185
|
+
key = [connection, database]
|
|
209
186
|
|
|
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
|
|
187
|
+
@connection_proxy_cache[key] ||= ActiveRecordHostPool::ConnectionProxy.new(connection, database)
|
|
224
188
|
end
|
|
225
|
-
# standard:enable Lint/DuplicateMethods
|
|
226
189
|
|
|
227
190
|
def _clear_connection_proxy_cache
|
|
228
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.1
|
|
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-27 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
|