fibered_mysql2 0.4.0.pre.tstarck.3 → 0.4.0.pre.tstarck.10
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/.github/workflows/build.yml +3 -2
- data/.ruby-version +1 -1
- data/Appraisals +1 -7
- data/CHANGELOG.md +3 -12
- data/Gemfile +1 -1
- data/Gemfile.lock +60 -60
- data/gemfiles/rails_7_0.gemfile +1 -4
- data/gemfiles/rails_7_1.gemfile +1 -1
- data/lib/active_record/connection_adapters/fibered_mysql2_adapter.rb +23 -94
- data/lib/fibered_mysql2/fibered_database_connection_pool.rb +40 -24
- data/lib/fibered_mysql2/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d06e5fc60f480741cc45b28c4eb4ee10b36e364cea461ebc07f0817381e40021
|
4
|
+
data.tar.gz: 30ae5bf495212c120fc8920a803b5fa3bac4835dd311c862d905e288cd664b76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 167c87ec227094ecf1b28805735d049e554b413db9bb8f04c65a4b0fde85f987047023074834842090bceb830924684c271246735c9abd64b79622a296081f09
|
7
|
+
data.tar.gz: b4419ac94cc20c2294b3caa28c615995a0f65637ba170b9dd4f405877dca2e660e39b23a33b53b75c529a4ba5a86393da35818b641898f573a50a75d5f4ef27e
|
data/.github/workflows/build.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
---
|
2
2
|
name: FiberedMySQL2 Gem Build
|
3
|
-
on: [push
|
3
|
+
on: [push]
|
4
4
|
jobs:
|
5
5
|
test:
|
6
6
|
name: Unit Tests
|
@@ -8,7 +8,7 @@ jobs:
|
|
8
8
|
strategy:
|
9
9
|
fail-fast: false
|
10
10
|
matrix:
|
11
|
-
ruby: [3.1, 3.2, 3.3
|
11
|
+
ruby: [3.1, 3.2, 3.3]
|
12
12
|
gemfile:
|
13
13
|
- Gemfile
|
14
14
|
- gemfiles/rails_7_0.gemfile
|
@@ -20,5 +20,6 @@ jobs:
|
|
20
20
|
- uses: ruby/setup-ruby@v1
|
21
21
|
with:
|
22
22
|
ruby-version: ${{ matrix.ruby }}
|
23
|
+
bundler: 2.2.29
|
23
24
|
bundler-cache: true
|
24
25
|
- run: bundle exec rspec
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.1.6
|
data/Appraisals
CHANGED
data/CHANGELOG.md
CHANGED
@@ -6,20 +6,11 @@ Note: this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0
|
|
6
6
|
|
7
7
|
## [0.4.0] - Unreleased
|
8
8
|
### Added
|
9
|
-
- Support for Rails 7.1
|
9
|
+
- Support for Rails 7.1.
|
10
10
|
|
11
11
|
### Removed
|
12
|
-
- Removed support for Rails 6.
|
13
|
-
|
14
|
-
### Changed
|
15
|
-
#### FiberedMysql2Adapter
|
16
|
-
- Updated to no longer include EM::Synchrony::ActiveRecord::Adapter_4_2 as it is no longer necessary.
|
17
|
-
- Removed TransactionManager overrides as they are no longer necessary.
|
18
|
-
|
19
|
-
#### FiberedMysql2::FiberedDatabaseConnectionPool
|
20
|
-
- Updated to only override methods needed in Rails 7.0.
|
21
|
-
- Removed double-checking in #connection for cached connection.
|
22
|
-
- Updated #checkout patch to use #reap instead of our custom #reaped_connections method.
|
12
|
+
- Removed support for Rails 6.
|
13
|
+
- Removed usage of EventMachine::Synchrony ActiveRecord Mysql adapter. This adapter code was extremely old and we were overriding their patches back to the current ActiveRecord version.
|
23
14
|
|
24
15
|
## [0.3.1] - 2024-10-30
|
25
16
|
### Fixed
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,42 +1,42 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fibered_mysql2 (0.4.0.pre.tstarck.
|
4
|
+
fibered_mysql2 (0.4.0.pre.tstarck.10)
|
5
5
|
em-synchrony (~> 1.0)
|
6
6
|
rails (>= 7.0, < 7.2)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
actioncable (7.1.5.
|
12
|
-
actionpack (= 7.1.5.
|
13
|
-
activesupport (= 7.1.5.
|
11
|
+
actioncable (7.1.5.2)
|
12
|
+
actionpack (= 7.1.5.2)
|
13
|
+
activesupport (= 7.1.5.2)
|
14
14
|
nio4r (~> 2.0)
|
15
15
|
websocket-driver (>= 0.6.1)
|
16
16
|
zeitwerk (~> 2.6)
|
17
|
-
actionmailbox (7.1.5.
|
18
|
-
actionpack (= 7.1.5.
|
19
|
-
activejob (= 7.1.5.
|
20
|
-
activerecord (= 7.1.5.
|
21
|
-
activestorage (= 7.1.5.
|
22
|
-
activesupport (= 7.1.5.
|
17
|
+
actionmailbox (7.1.5.2)
|
18
|
+
actionpack (= 7.1.5.2)
|
19
|
+
activejob (= 7.1.5.2)
|
20
|
+
activerecord (= 7.1.5.2)
|
21
|
+
activestorage (= 7.1.5.2)
|
22
|
+
activesupport (= 7.1.5.2)
|
23
23
|
mail (>= 2.7.1)
|
24
24
|
net-imap
|
25
25
|
net-pop
|
26
26
|
net-smtp
|
27
|
-
actionmailer (7.1.5.
|
28
|
-
actionpack (= 7.1.5.
|
29
|
-
actionview (= 7.1.5.
|
30
|
-
activejob (= 7.1.5.
|
31
|
-
activesupport (= 7.1.5.
|
27
|
+
actionmailer (7.1.5.2)
|
28
|
+
actionpack (= 7.1.5.2)
|
29
|
+
actionview (= 7.1.5.2)
|
30
|
+
activejob (= 7.1.5.2)
|
31
|
+
activesupport (= 7.1.5.2)
|
32
32
|
mail (~> 2.5, >= 2.5.4)
|
33
33
|
net-imap
|
34
34
|
net-pop
|
35
35
|
net-smtp
|
36
36
|
rails-dom-testing (~> 2.2)
|
37
|
-
actionpack (7.1.5.
|
38
|
-
actionview (= 7.1.5.
|
39
|
-
activesupport (= 7.1.5.
|
37
|
+
actionpack (7.1.5.2)
|
38
|
+
actionview (= 7.1.5.2)
|
39
|
+
activesupport (= 7.1.5.2)
|
40
40
|
nokogiri (>= 1.8.5)
|
41
41
|
racc
|
42
42
|
rack (>= 2.2.4)
|
@@ -44,35 +44,35 @@ GEM
|
|
44
44
|
rack-test (>= 0.6.3)
|
45
45
|
rails-dom-testing (~> 2.2)
|
46
46
|
rails-html-sanitizer (~> 1.6)
|
47
|
-
actiontext (7.1.5.
|
48
|
-
actionpack (= 7.1.5.
|
49
|
-
activerecord (= 7.1.5.
|
50
|
-
activestorage (= 7.1.5.
|
51
|
-
activesupport (= 7.1.5.
|
47
|
+
actiontext (7.1.5.2)
|
48
|
+
actionpack (= 7.1.5.2)
|
49
|
+
activerecord (= 7.1.5.2)
|
50
|
+
activestorage (= 7.1.5.2)
|
51
|
+
activesupport (= 7.1.5.2)
|
52
52
|
globalid (>= 0.6.0)
|
53
53
|
nokogiri (>= 1.8.5)
|
54
|
-
actionview (7.1.5.
|
55
|
-
activesupport (= 7.1.5.
|
54
|
+
actionview (7.1.5.2)
|
55
|
+
activesupport (= 7.1.5.2)
|
56
56
|
builder (~> 3.1)
|
57
57
|
erubi (~> 1.11)
|
58
58
|
rails-dom-testing (~> 2.2)
|
59
59
|
rails-html-sanitizer (~> 1.6)
|
60
|
-
activejob (7.1.5.
|
61
|
-
activesupport (= 7.1.5.
|
60
|
+
activejob (7.1.5.2)
|
61
|
+
activesupport (= 7.1.5.2)
|
62
62
|
globalid (>= 0.3.6)
|
63
|
-
activemodel (7.1.5.
|
64
|
-
activesupport (= 7.1.5.
|
65
|
-
activerecord (7.1.5.
|
66
|
-
activemodel (= 7.1.5.
|
67
|
-
activesupport (= 7.1.5.
|
63
|
+
activemodel (7.1.5.2)
|
64
|
+
activesupport (= 7.1.5.2)
|
65
|
+
activerecord (7.1.5.2)
|
66
|
+
activemodel (= 7.1.5.2)
|
67
|
+
activesupport (= 7.1.5.2)
|
68
68
|
timeout (>= 0.4.0)
|
69
|
-
activestorage (7.1.5.
|
70
|
-
actionpack (= 7.1.5.
|
71
|
-
activejob (= 7.1.5.
|
72
|
-
activerecord (= 7.1.5.
|
73
|
-
activesupport (= 7.1.5.
|
69
|
+
activestorage (7.1.5.2)
|
70
|
+
actionpack (= 7.1.5.2)
|
71
|
+
activejob (= 7.1.5.2)
|
72
|
+
activerecord (= 7.1.5.2)
|
73
|
+
activesupport (= 7.1.5.2)
|
74
74
|
marcel (~> 1.0)
|
75
|
-
activesupport (7.1.5.
|
75
|
+
activesupport (7.1.5.2)
|
76
76
|
base64
|
77
77
|
benchmark (>= 0.3)
|
78
78
|
bigdecimal
|
@@ -169,20 +169,20 @@ GEM
|
|
169
169
|
rack (>= 1.3)
|
170
170
|
rackup (2.2.1)
|
171
171
|
rack (>= 3)
|
172
|
-
rails (7.1.5.
|
173
|
-
actioncable (= 7.1.5.
|
174
|
-
actionmailbox (= 7.1.5.
|
175
|
-
actionmailer (= 7.1.5.
|
176
|
-
actionpack (= 7.1.5.
|
177
|
-
actiontext (= 7.1.5.
|
178
|
-
actionview (= 7.1.5.
|
179
|
-
activejob (= 7.1.5.
|
180
|
-
activemodel (= 7.1.5.
|
181
|
-
activerecord (= 7.1.5.
|
182
|
-
activestorage (= 7.1.5.
|
183
|
-
activesupport (= 7.1.5.
|
172
|
+
rails (7.1.5.2)
|
173
|
+
actioncable (= 7.1.5.2)
|
174
|
+
actionmailbox (= 7.1.5.2)
|
175
|
+
actionmailer (= 7.1.5.2)
|
176
|
+
actionpack (= 7.1.5.2)
|
177
|
+
actiontext (= 7.1.5.2)
|
178
|
+
actionview (= 7.1.5.2)
|
179
|
+
activejob (= 7.1.5.2)
|
180
|
+
activemodel (= 7.1.5.2)
|
181
|
+
activerecord (= 7.1.5.2)
|
182
|
+
activestorage (= 7.1.5.2)
|
183
|
+
activesupport (= 7.1.5.2)
|
184
184
|
bundler (>= 1.15.0)
|
185
|
-
railties (= 7.1.5.
|
185
|
+
railties (= 7.1.5.2)
|
186
186
|
rails-dom-testing (2.3.0)
|
187
187
|
activesupport (>= 5.0.0)
|
188
188
|
minitest
|
@@ -190,9 +190,9 @@ GEM
|
|
190
190
|
rails-html-sanitizer (1.6.2)
|
191
191
|
loofah (~> 2.21)
|
192
192
|
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
|
193
|
-
railties (7.1.5.
|
194
|
-
actionpack (= 7.1.5.
|
195
|
-
activesupport (= 7.1.5.
|
193
|
+
railties (7.1.5.2)
|
194
|
+
actionpack (= 7.1.5.2)
|
195
|
+
activesupport (= 7.1.5.2)
|
196
196
|
irb
|
197
197
|
rackup (>= 1.0.0)
|
198
198
|
rake (>= 12.2)
|
@@ -208,15 +208,15 @@ GEM
|
|
208
208
|
rspec-core (~> 3.12.0)
|
209
209
|
rspec-expectations (~> 3.12.0)
|
210
210
|
rspec-mocks (~> 3.12.0)
|
211
|
-
rspec-core (3.12.
|
211
|
+
rspec-core (3.12.2)
|
212
212
|
rspec-support (~> 3.12.0)
|
213
|
-
rspec-expectations (3.12.
|
213
|
+
rspec-expectations (3.12.3)
|
214
214
|
diff-lcs (>= 1.2.0, < 2.0)
|
215
215
|
rspec-support (~> 3.12.0)
|
216
|
-
rspec-mocks (3.12.
|
216
|
+
rspec-mocks (3.12.6)
|
217
217
|
diff-lcs (>= 1.2.0, < 2.0)
|
218
218
|
rspec-support (~> 3.12.0)
|
219
|
-
rspec-support (3.12.
|
219
|
+
rspec-support (3.12.1)
|
220
220
|
securerandom (0.4.1)
|
221
221
|
stringio (3.1.7)
|
222
222
|
thor (1.4.0)
|
@@ -241,7 +241,7 @@ DEPENDENCIES
|
|
241
241
|
pry
|
242
242
|
pry-byebug
|
243
243
|
rake
|
244
|
-
rspec (
|
244
|
+
rspec (< 3.13)
|
245
245
|
|
246
246
|
BUNDLED WITH
|
247
|
-
2.
|
247
|
+
2.2.29
|
data/gemfiles/rails_7_0.gemfile
CHANGED
data/gemfiles/rails_7_1.gemfile
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
require 'em-synchrony'
|
4
4
|
require 'active_model'
|
5
5
|
require 'active_record/errors'
|
6
|
-
|
7
6
|
require 'active_record/connection_adapters/mysql2_adapter'
|
8
7
|
require 'em-synchrony/mysql2'
|
9
8
|
|
@@ -54,98 +53,6 @@ module FiberedMysql2
|
|
54
53
|
end
|
55
54
|
end
|
56
55
|
|
57
|
-
def reset_transaction #:nodoc:
|
58
|
-
@transaction_manager = ::FiberedMysql2::FiberedMysql2Adapter_7_0::TransactionManager.new(self)
|
59
|
-
end
|
60
|
-
|
61
|
-
class TransactionManager < ::ActiveRecord::ConnectionAdapters::TransactionManager
|
62
|
-
def initialize(...)
|
63
|
-
super
|
64
|
-
@stack = Hash.new { |h, k| h[k] = [] }
|
65
|
-
end
|
66
|
-
|
67
|
-
def current_transaction #:nodoc:
|
68
|
-
_current_stack.last || ::ActiveRecord::ConnectionAdapters::TransactionManager::NULL_TRANSACTION
|
69
|
-
end
|
70
|
-
|
71
|
-
def open_transactions
|
72
|
-
_current_stack.size
|
73
|
-
end
|
74
|
-
|
75
|
-
def begin_transaction(isolation: nil, joinable: true, _lazy: true)
|
76
|
-
@connection.lock.synchronize do
|
77
|
-
run_commit_callbacks = !current_transaction.joinable?
|
78
|
-
transaction =
|
79
|
-
if _current_stack.empty?
|
80
|
-
::ActiveRecord::ConnectionAdapters::RealTransaction.new(@connection, isolation:, joinable:, run_commit_callbacks: run_commit_callbacks)
|
81
|
-
else
|
82
|
-
::ActiveRecord::ConnectionAdapters::SavepointTransaction.new(@connection, "active_record_#{Fiber.current.object_id}_#{open_transactions}", _current_stack.last, isolation:, joinable:, run_commit_callbacks: run_commit_callbacks)
|
83
|
-
end
|
84
|
-
|
85
|
-
if @connection.supports_lazy_transactions? && lazy_transactions_enabled? && _lazy
|
86
|
-
@has_unmaterialized_transactions = true
|
87
|
-
else
|
88
|
-
transaction.materialize!
|
89
|
-
end
|
90
|
-
_current_stack.push(transaction)
|
91
|
-
transaction
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
# Overriding the ActiveRecord::TransactionManager#materialize_transactions method to use
|
96
|
-
# fiber safe the _current_stack instead of the @stack instance variable. when marterializing
|
97
|
-
# transactions.
|
98
|
-
def materialize_transactions
|
99
|
-
return if @materializing_transactions
|
100
|
-
return unless @has_unmaterialized_transactions
|
101
|
-
|
102
|
-
@connection.lock.synchronize do
|
103
|
-
begin
|
104
|
-
@materializing_transactions = true
|
105
|
-
_current_stack.each { |t| t.materialize! unless t.materialized? }
|
106
|
-
ensure
|
107
|
-
@materializing_transactions = false
|
108
|
-
end
|
109
|
-
@has_unmaterialized_transactions = false
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
# Overriding the ActiveRecord::TransactionManager#commit_transaction method to use
|
114
|
-
# fiber safe the _current_stack instead of the @stack instance variable. when marterializing
|
115
|
-
# transactions.
|
116
|
-
def commit_transaction
|
117
|
-
@connection.lock.synchronize do
|
118
|
-
transaction = _current_stack.last
|
119
|
-
|
120
|
-
begin
|
121
|
-
transaction.before_commit_records
|
122
|
-
ensure
|
123
|
-
_current_stack.pop
|
124
|
-
end
|
125
|
-
|
126
|
-
transaction.commit
|
127
|
-
transaction.commit_records
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
# Overriding the ActiveRecord::TransactionManager#rollback_transaction method to use
|
132
|
-
# fiber safe the _current_stack instead of the @stack instance variable. when marterializing
|
133
|
-
# transactions.
|
134
|
-
def rollback_transaction(transaction = nil)
|
135
|
-
@connection.lock.synchronize do
|
136
|
-
transaction ||= _current_stack.pop
|
137
|
-
transaction.rollback
|
138
|
-
transaction.rollback_records
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
private
|
143
|
-
|
144
|
-
def _current_stack
|
145
|
-
@stack[Fiber.current.object_id]
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
56
|
private
|
150
57
|
|
151
58
|
def owner_fiber
|
@@ -155,9 +62,31 @@ module FiberedMysql2
|
|
155
62
|
end
|
156
63
|
end
|
157
64
|
|
65
|
+
module FiberedMysql2Adapter_7_1
|
66
|
+
def expire
|
67
|
+
if in_use?
|
68
|
+
# Because we are actively releasing connections from dead fibers, we only want
|
69
|
+
# to enforce that we're expiring the current fibers connection, iff the owner
|
70
|
+
# of the connection is still alive.
|
71
|
+
if @owner.alive? && @owner != ActiveSupport::IsolatedExecutionState.context
|
72
|
+
raise ::ActiveRecord::ActiveRecordError, "Cannot expire connection, " \
|
73
|
+
"it is owned by a different fiber: #{@owner}. " \
|
74
|
+
"Current fiber: #{ActiveSupport::IsolatedExecutionState.context}."
|
75
|
+
end
|
76
|
+
|
77
|
+
@idle_since = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
78
|
+
@owner = nil
|
79
|
+
else
|
80
|
+
raise ::ActiveRecord::ActiveRecordError, "Cannot expire connection, it is not currently leased."
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
158
85
|
class FiberedMysql2Adapter < ::ActiveRecord::ConnectionAdapters::Mysql2Adapter
|
159
|
-
if
|
86
|
+
if Rails.gem_version < "7.1"
|
160
87
|
include FiberedMysql2Adapter_7_0
|
88
|
+
else
|
89
|
+
include FiberedMysql2Adapter_7_1
|
161
90
|
end
|
162
91
|
|
163
92
|
class << self
|
@@ -184,6 +184,9 @@ module FiberedMysql2
|
|
184
184
|
end
|
185
185
|
|
186
186
|
module FiberedDatabaseConnectionPool
|
187
|
+
include FiberedMonitorMixin
|
188
|
+
|
189
|
+
# Methods that only need to be made Fiber safe in Rails 7.0. Rails 7.1 properly supports Fibers for these methods.
|
187
190
|
module Adapter_7_0
|
188
191
|
def release_connection(owner_thread = Fiber.current)
|
189
192
|
if (conn = @thread_cached_conns.delete(connection_cache_key(owner_thread)))
|
@@ -192,7 +195,7 @@ module FiberedMysql2
|
|
192
195
|
end
|
193
196
|
|
194
197
|
def with_connection
|
195
|
-
unless (conn = cached_connections[current_connection_id])
|
198
|
+
unless (conn = cached_connections[current_connection_id])
|
196
199
|
conn = connection
|
197
200
|
fresh_connection = true
|
198
201
|
end
|
@@ -201,15 +204,15 @@ module FiberedMysql2
|
|
201
204
|
release_connection if fresh_connection
|
202
205
|
end
|
203
206
|
|
207
|
+
private
|
208
|
+
|
204
209
|
def current_thread
|
205
210
|
Fiber.current
|
206
211
|
end
|
207
212
|
end
|
208
|
-
|
209
|
-
if ::ActiveRecord.gem_version < "7.1"
|
213
|
+
if ActiveRecord.gem_version < "7.1"
|
210
214
|
include Adapter_7_0
|
211
215
|
end
|
212
|
-
include FiberedMonitorMixin # This is switches the connection pool's mutex and condition variables to event machine / Fiber compatible ones.
|
213
216
|
|
214
217
|
def initialize(pool_config)
|
215
218
|
if pool_config.db_config.reaping_frequency
|
@@ -221,26 +224,6 @@ module FiberedMysql2
|
|
221
224
|
@reaper = nil # no need to keep a reference to this since it does nothing in this sub-class
|
222
225
|
end
|
223
226
|
|
224
|
-
def current_connection_id
|
225
|
-
connection_cache_key(current_thread)
|
226
|
-
end
|
227
|
-
|
228
|
-
def cached_connections
|
229
|
-
@thread_cached_conns
|
230
|
-
end
|
231
|
-
|
232
|
-
# Invoca patch that reaps orphaned connections on checkout. This lets us immediately use a connection left open by dead fibers
|
233
|
-
# instead of waiting for all connections to be used in the pool before they are reaped.
|
234
|
-
def checkout(checkout_timeout = @checkout_timeout)
|
235
|
-
begin
|
236
|
-
reap
|
237
|
-
rescue => ex
|
238
|
-
ActiveRecord::Base.logger.error("Exception occurred while executing reap_connections: #{ex}")
|
239
|
-
end
|
240
|
-
super
|
241
|
-
end
|
242
|
-
|
243
|
-
# Invoca patch to ensure that we are using the current fiber's connection.
|
244
227
|
def connection
|
245
228
|
# this is correctly done double-checked locking
|
246
229
|
# (ThreadSafe::Cache's lookups have volatile semantics)
|
@@ -256,6 +239,39 @@ module FiberedMysql2
|
|
256
239
|
end
|
257
240
|
end
|
258
241
|
end
|
242
|
+
|
243
|
+
# Invoca Patch - Reap connections so we re-use any orphaned connections instead of creating a new connection.
|
244
|
+
# This has been useful in Ringswitch where we have a lot of orphaned connections, as it limits the number of connections we have open.
|
245
|
+
# ActiveRecord only calls reap if there are no more connections available in the pool, i.e. if all connections are in use (and potentially orphaned).
|
246
|
+
def checkout(checkout_timeout = @checkout_timeout)
|
247
|
+
begin
|
248
|
+
reap_connections
|
249
|
+
rescue => ex
|
250
|
+
ActiveRecord::Base.logger.error("Exception occurred while executing reap_connections: #{ex}")
|
251
|
+
end
|
252
|
+
super
|
253
|
+
end
|
254
|
+
|
255
|
+
# Invoca Patch - Only used in our #checkout patch above. The main difference this method has with #reap is that we don't call #steal! on the orphaned connections first.
|
256
|
+
# This may be risky for race conditions but potentially runs faster than the #reap method?
|
257
|
+
# We should look to replace this with the standard #reap method in the future.
|
258
|
+
def reap_connections
|
259
|
+
cached_connections.values.each do |connection|
|
260
|
+
unless connection.owner.alive?
|
261
|
+
checkin(connection)
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
# Invoca Patch - Helper method.
|
267
|
+
def cached_connections
|
268
|
+
@thread_cached_conns
|
269
|
+
end
|
270
|
+
|
271
|
+
# Invoca Patch - Helper method
|
272
|
+
def current_connection_id
|
273
|
+
connection_cache_key(current_thread)
|
274
|
+
end
|
259
275
|
end
|
260
276
|
end
|
261
277
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fibered_mysql2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.0.pre.tstarck.
|
4
|
+
version: 0.4.0.pre.tstarck.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Invoca Development
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-08-
|
11
|
+
date: 2025-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: em-synchrony
|
@@ -91,11 +91,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
91
91
|
version: '0'
|
92
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - ">"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 1.3.1
|
97
97
|
requirements: []
|
98
|
-
rubygems_version: 3.
|
98
|
+
rubygems_version: 3.3.27
|
99
99
|
signing_key:
|
100
100
|
specification_version: 4
|
101
101
|
summary: An adapter for fibered mysql2
|