fibered_mysql2 0.3.1 → 0.4.0.pre.tstarck.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8cf06a5be94da99bc7d1e0de4b5268ff04a72fd7671e6c4d522186d1ea67dd0b
4
- data.tar.gz: 931890052763e7fcf2f1ffb7925848004dc54c4c583f89d24c258cbe1537a67a
3
+ metadata.gz: f4de2661b6a53134802496ea91ed73ad10623ee8459f1d4ecdb1ebdef6ea4f63
4
+ data.tar.gz: 8846ea290e1ed8ccab648c55458809b63cb4a1ca737f405f0ece815b441104cf
5
5
  SHA512:
6
- metadata.gz: 42cab06e4e9bccd07df1436db08c8fb0e8038027690bc03cc58a34eab99ecfd6cccedbdde27f63f9607ce391bea3de8d941cc720775deb7c0c7d65134f405bae
7
- data.tar.gz: be4a1bd1357e9d51e2e76e48f93ede62f8b7c3cb9cf515a042cf9d10f4d2afe63721349f5afe65a67d2cc9246741aab39a80c7aa903bafde77d95d75c026cd05
6
+ metadata.gz: 68e08cebe9eec799298274fa1be5e3f83f7b896b5cbdebad3b3b5cb082fabb92388b80310cdb8bd376605374db8460dad4f9fde4746385d9e9d03f53278bf0a2
7
+ data.tar.gz: 1ea97ac7495a0bc0085aaf4f45e226ad9110f879d893673ae646c48753f90f4c456156bb29ca63c36ddf827fff96a7aab934f80d43c27dbc534fd602db8472be
@@ -8,11 +8,11 @@ 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, 3.4]
12
12
  gemfile:
13
13
  - Gemfile
14
- - gemfiles/rails_6_1.gemfile
15
14
  - gemfiles/rails_7_0.gemfile
15
+ - gemfiles/rails_7_1.gemfile
16
16
  env:
17
17
  BUNDLE_GEMFILE: ${{ matrix.gemfile }}
18
18
  steps:
@@ -20,6 +20,5 @@ jobs:
20
20
  - uses: ruby/setup-ruby@v1
21
21
  with:
22
22
  ruby-version: ${{ matrix.ruby }}
23
- bundler: 2.2.29
24
23
  bundler-cache: true
25
24
  - run: bundle exec rspec
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.1.6
1
+ 3.3.8
data/Appraisals CHANGED
@@ -2,4 +2,10 @@
2
2
 
3
3
  require "appraisal/matrix"
4
4
 
5
- appraisal_matrix(rails: [">= 6.1", "< 7.1"])
5
+ appraisal_matrix(rails: [">= 7.0", "< 7.2"]) do |rails:|
6
+ if rails < "7.1"
7
+ gem "mutex_m"
8
+ gem "base64"
9
+ gem "bigdecimal"
10
+ end
11
+ end
data/CHANGELOG.md CHANGED
@@ -4,6 +4,23 @@ Inspired by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
4
4
 
5
5
  Note: this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.4.0] - Unreleased
8
+ ### Added
9
+ - Support for Rails 7.1
10
+
11
+ ### Removed
12
+ - Removed support for Rails 6.1 and below.
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.
23
+
7
24
  ## [0.3.1] - 2024-10-30
8
25
  ### Fixed
9
26
  - Fixed bug in FiberedMysqlAdapter.new_client that was causing `uninitialized constant` errors.
data/Gemfile CHANGED
@@ -7,10 +7,9 @@ gemspec
7
7
 
8
8
  gem 'appraisal'
9
9
  gem 'appraisal-matrix'
10
- gem 'coveralls', require: false
11
10
  gem 'mysql2', '~> 0.5'
12
11
  gem 'nokogiri'
13
12
  gem 'pry'
14
13
  gem 'pry-byebug'
15
14
  gem 'rake'
16
- gem 'rspec'
15
+ gem 'rspec', '~> 3.12.0' # Rspec 3.13 is causing segfaults for some reason in CI...
data/Gemfile.lock CHANGED
@@ -1,77 +1,89 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fibered_mysql2 (0.3.1)
4
+ fibered_mysql2 (0.4.0.pre.tstarck.1)
5
5
  em-synchrony (~> 1.0)
6
- rails (>= 6.1, < 7.1)
6
+ rails (>= 7.0, < 7.2)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- actioncable (7.0.8.6)
12
- actionpack (= 7.0.8.6)
13
- activesupport (= 7.0.8.6)
11
+ actioncable (7.1.5.1)
12
+ actionpack (= 7.1.5.1)
13
+ activesupport (= 7.1.5.1)
14
14
  nio4r (~> 2.0)
15
15
  websocket-driver (>= 0.6.1)
16
- actionmailbox (7.0.8.6)
17
- actionpack (= 7.0.8.6)
18
- activejob (= 7.0.8.6)
19
- activerecord (= 7.0.8.6)
20
- activestorage (= 7.0.8.6)
21
- activesupport (= 7.0.8.6)
16
+ zeitwerk (~> 2.6)
17
+ actionmailbox (7.1.5.1)
18
+ actionpack (= 7.1.5.1)
19
+ activejob (= 7.1.5.1)
20
+ activerecord (= 7.1.5.1)
21
+ activestorage (= 7.1.5.1)
22
+ activesupport (= 7.1.5.1)
22
23
  mail (>= 2.7.1)
23
24
  net-imap
24
25
  net-pop
25
26
  net-smtp
26
- actionmailer (7.0.8.6)
27
- actionpack (= 7.0.8.6)
28
- actionview (= 7.0.8.6)
29
- activejob (= 7.0.8.6)
30
- activesupport (= 7.0.8.6)
27
+ actionmailer (7.1.5.1)
28
+ actionpack (= 7.1.5.1)
29
+ actionview (= 7.1.5.1)
30
+ activejob (= 7.1.5.1)
31
+ activesupport (= 7.1.5.1)
31
32
  mail (~> 2.5, >= 2.5.4)
32
33
  net-imap
33
34
  net-pop
34
35
  net-smtp
35
- rails-dom-testing (~> 2.0)
36
- actionpack (7.0.8.6)
37
- actionview (= 7.0.8.6)
38
- activesupport (= 7.0.8.6)
39
- rack (~> 2.0, >= 2.2.4)
36
+ rails-dom-testing (~> 2.2)
37
+ actionpack (7.1.5.1)
38
+ actionview (= 7.1.5.1)
39
+ activesupport (= 7.1.5.1)
40
+ nokogiri (>= 1.8.5)
41
+ racc
42
+ rack (>= 2.2.4)
43
+ rack-session (>= 1.0.1)
40
44
  rack-test (>= 0.6.3)
41
- rails-dom-testing (~> 2.0)
42
- rails-html-sanitizer (~> 1.0, >= 1.2.0)
43
- actiontext (7.0.8.6)
44
- actionpack (= 7.0.8.6)
45
- activerecord (= 7.0.8.6)
46
- activestorage (= 7.0.8.6)
47
- activesupport (= 7.0.8.6)
45
+ rails-dom-testing (~> 2.2)
46
+ rails-html-sanitizer (~> 1.6)
47
+ actiontext (7.1.5.1)
48
+ actionpack (= 7.1.5.1)
49
+ activerecord (= 7.1.5.1)
50
+ activestorage (= 7.1.5.1)
51
+ activesupport (= 7.1.5.1)
48
52
  globalid (>= 0.6.0)
49
53
  nokogiri (>= 1.8.5)
50
- actionview (7.0.8.6)
51
- activesupport (= 7.0.8.6)
54
+ actionview (7.1.5.1)
55
+ activesupport (= 7.1.5.1)
52
56
  builder (~> 3.1)
53
- erubi (~> 1.4)
54
- rails-dom-testing (~> 2.0)
55
- rails-html-sanitizer (~> 1.1, >= 1.2.0)
56
- activejob (7.0.8.6)
57
- activesupport (= 7.0.8.6)
57
+ erubi (~> 1.11)
58
+ rails-dom-testing (~> 2.2)
59
+ rails-html-sanitizer (~> 1.6)
60
+ activejob (7.1.5.1)
61
+ activesupport (= 7.1.5.1)
58
62
  globalid (>= 0.3.6)
59
- activemodel (7.0.8.6)
60
- activesupport (= 7.0.8.6)
61
- activerecord (7.0.8.6)
62
- activemodel (= 7.0.8.6)
63
- activesupport (= 7.0.8.6)
64
- activestorage (7.0.8.6)
65
- actionpack (= 7.0.8.6)
66
- activejob (= 7.0.8.6)
67
- activerecord (= 7.0.8.6)
68
- activesupport (= 7.0.8.6)
63
+ activemodel (7.1.5.1)
64
+ activesupport (= 7.1.5.1)
65
+ activerecord (7.1.5.1)
66
+ activemodel (= 7.1.5.1)
67
+ activesupport (= 7.1.5.1)
68
+ timeout (>= 0.4.0)
69
+ activestorage (7.1.5.1)
70
+ actionpack (= 7.1.5.1)
71
+ activejob (= 7.1.5.1)
72
+ activerecord (= 7.1.5.1)
73
+ activesupport (= 7.1.5.1)
69
74
  marcel (~> 1.0)
70
- mini_mime (>= 1.1.0)
71
- activesupport (7.0.8.6)
75
+ activesupport (7.1.5.1)
76
+ base64
77
+ benchmark (>= 0.3)
78
+ bigdecimal
72
79
  concurrent-ruby (~> 1.0, >= 1.0.2)
80
+ connection_pool (>= 2.2.5)
81
+ drb
73
82
  i18n (>= 1.6, < 2)
83
+ logger (>= 1.4.2)
74
84
  minitest (>= 5.1)
85
+ mutex_m
86
+ securerandom (>= 0.3)
75
87
  tzinfo (~> 2.0)
76
88
  appraisal (2.5.0)
77
89
  bundler
@@ -79,31 +91,36 @@ GEM
79
91
  thor (>= 0.14.0)
80
92
  appraisal-matrix (0.3.0)
81
93
  appraisal (~> 2.2)
82
- bigdecimal (3.1.8)
94
+ base64 (0.3.0)
95
+ benchmark (0.4.1)
96
+ bigdecimal (3.2.2)
83
97
  builder (3.3.0)
84
- byebug (11.1.3)
98
+ byebug (12.0.0)
99
+ cgi (0.5.0)
85
100
  coderay (1.1.3)
86
- concurrent-ruby (1.3.4)
87
- coveralls (0.8.23)
88
- json (>= 1.8, < 3)
89
- simplecov (~> 0.16.1)
90
- term-ansicolor (~> 1.3)
91
- thor (>= 0.19.4, < 2.0)
92
- tins (~> 1.6)
101
+ concurrent-ruby (1.3.5)
102
+ connection_pool (2.5.3)
93
103
  crass (1.0.6)
94
- date (3.3.4)
95
- diff-lcs (1.5.1)
96
- docile (1.4.1)
104
+ date (3.4.1)
105
+ diff-lcs (1.6.2)
106
+ drb (2.2.3)
97
107
  em-synchrony (1.0.6)
98
108
  eventmachine (>= 1.0.0.beta.1)
99
- erubi (1.13.0)
109
+ erb (4.0.4)
110
+ cgi (>= 0.3.3)
111
+ erubi (1.13.1)
100
112
  eventmachine (1.2.7)
101
113
  globalid (1.2.1)
102
114
  activesupport (>= 6.1)
103
- i18n (1.14.6)
115
+ i18n (1.14.7)
104
116
  concurrent-ruby (~> 1.0)
105
- json (2.7.2)
106
- loofah (2.23.1)
117
+ io-console (0.8.1)
118
+ irb (1.15.2)
119
+ pp (>= 0.6.0)
120
+ rdoc (>= 4.0.0)
121
+ reline (>= 0.4.2)
122
+ logger (1.7.0)
123
+ loofah (2.24.1)
107
124
  crass (~> 1.0.2)
108
125
  nokogiri (>= 1.12.0)
109
126
  mail (2.8.1)
@@ -114,90 +131,100 @@ GEM
114
131
  marcel (1.0.4)
115
132
  method_source (1.1.0)
116
133
  mini_mime (1.1.5)
117
- mini_portile2 (2.8.7)
118
- minitest (5.25.1)
134
+ mini_portile2 (2.8.9)
135
+ minitest (5.25.5)
136
+ mutex_m (0.3.0)
119
137
  mysql2 (0.5.6)
120
- net-imap (0.5.0)
138
+ net-imap (0.5.9)
121
139
  date
122
140
  net-protocol
123
141
  net-pop (0.1.2)
124
142
  net-protocol
125
143
  net-protocol (0.2.2)
126
144
  timeout
127
- net-smtp (0.5.0)
145
+ net-smtp (0.5.1)
128
146
  net-protocol
129
147
  nio4r (2.7.4)
130
- nokogiri (1.16.7)
148
+ nokogiri (1.18.9)
131
149
  mini_portile2 (~> 2.8.2)
132
150
  racc (~> 1.4)
133
- pry (0.14.2)
151
+ pp (0.6.2)
152
+ prettyprint
153
+ prettyprint (0.2.0)
154
+ pry (0.15.2)
134
155
  coderay (~> 1.1)
135
156
  method_source (~> 1.0)
136
- pry-byebug (3.10.1)
137
- byebug (~> 11.0)
138
- pry (>= 0.13, < 0.15)
157
+ pry-byebug (3.11.0)
158
+ byebug (~> 12.0)
159
+ pry (>= 0.13, < 0.16)
160
+ psych (5.2.6)
161
+ date
162
+ stringio
139
163
  racc (1.8.1)
140
- rack (2.2.10)
141
- rack-test (2.1.0)
164
+ rack (3.2.0)
165
+ rack-session (2.1.1)
166
+ base64 (>= 0.1.0)
167
+ rack (>= 3.0.0)
168
+ rack-test (2.2.0)
142
169
  rack (>= 1.3)
143
- rails (7.0.8.6)
144
- actioncable (= 7.0.8.6)
145
- actionmailbox (= 7.0.8.6)
146
- actionmailer (= 7.0.8.6)
147
- actionpack (= 7.0.8.6)
148
- actiontext (= 7.0.8.6)
149
- actionview (= 7.0.8.6)
150
- activejob (= 7.0.8.6)
151
- activemodel (= 7.0.8.6)
152
- activerecord (= 7.0.8.6)
153
- activestorage (= 7.0.8.6)
154
- activesupport (= 7.0.8.6)
170
+ rackup (2.2.1)
171
+ rack (>= 3)
172
+ rails (7.1.5.1)
173
+ actioncable (= 7.1.5.1)
174
+ actionmailbox (= 7.1.5.1)
175
+ actionmailer (= 7.1.5.1)
176
+ actionpack (= 7.1.5.1)
177
+ actiontext (= 7.1.5.1)
178
+ actionview (= 7.1.5.1)
179
+ activejob (= 7.1.5.1)
180
+ activemodel (= 7.1.5.1)
181
+ activerecord (= 7.1.5.1)
182
+ activestorage (= 7.1.5.1)
183
+ activesupport (= 7.1.5.1)
155
184
  bundler (>= 1.15.0)
156
- railties (= 7.0.8.6)
157
- rails-dom-testing (2.2.0)
185
+ railties (= 7.1.5.1)
186
+ rails-dom-testing (2.3.0)
158
187
  activesupport (>= 5.0.0)
159
188
  minitest
160
189
  nokogiri (>= 1.6)
161
- rails-html-sanitizer (1.6.0)
190
+ rails-html-sanitizer (1.6.2)
162
191
  loofah (~> 2.21)
163
- nokogiri (~> 1.14)
164
- railties (7.0.8.6)
165
- actionpack (= 7.0.8.6)
166
- activesupport (= 7.0.8.6)
167
- method_source
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.1)
194
+ actionpack (= 7.1.5.1)
195
+ activesupport (= 7.1.5.1)
196
+ irb
197
+ rackup (>= 1.0.0)
168
198
  rake (>= 12.2)
169
- thor (~> 1.0)
170
- zeitwerk (~> 2.5)
171
- rake (13.2.1)
172
- rspec (3.13.0)
173
- rspec-core (~> 3.13.0)
174
- rspec-expectations (~> 3.13.0)
175
- rspec-mocks (~> 3.13.0)
176
- rspec-core (3.13.0)
177
- rspec-support (~> 3.13.0)
178
- rspec-expectations (3.13.1)
199
+ thor (~> 1.0, >= 1.2.2)
200
+ zeitwerk (~> 2.6)
201
+ rake (13.3.0)
202
+ rdoc (6.14.2)
203
+ erb
204
+ psych (>= 4.0.0)
205
+ reline (0.6.2)
206
+ io-console (~> 0.5)
207
+ rspec (3.12.0)
208
+ rspec-core (~> 3.12.0)
209
+ rspec-expectations (~> 3.12.0)
210
+ rspec-mocks (~> 3.12.0)
211
+ rspec-core (3.12.3)
212
+ rspec-support (~> 3.12.0)
213
+ rspec-expectations (3.12.4)
179
214
  diff-lcs (>= 1.2.0, < 2.0)
180
- rspec-support (~> 3.13.0)
181
- rspec-mocks (3.13.1)
215
+ rspec-support (~> 3.12.0)
216
+ rspec-mocks (3.12.7)
182
217
  diff-lcs (>= 1.2.0, < 2.0)
183
- rspec-support (~> 3.13.0)
184
- rspec-support (3.13.1)
185
- simplecov (0.16.1)
186
- docile (~> 1.1)
187
- json (>= 1.8, < 3)
188
- simplecov-html (~> 0.10.0)
189
- simplecov-html (0.10.2)
190
- sync (0.5.0)
191
- term-ansicolor (1.11.2)
192
- tins (~> 1.0)
193
- thor (1.3.2)
194
- timeout (0.4.1)
195
- tins (1.33.0)
196
- bigdecimal
197
- sync
218
+ rspec-support (~> 3.12.0)
219
+ rspec-support (3.12.2)
220
+ securerandom (0.4.1)
221
+ stringio (3.1.7)
222
+ thor (1.4.0)
223
+ timeout (0.4.3)
198
224
  tzinfo (2.0.6)
199
225
  concurrent-ruby (~> 1.0)
200
- websocket-driver (0.7.6)
226
+ websocket-driver (0.8.0)
227
+ base64
201
228
  websocket-extensions (>= 0.1.0)
202
229
  websocket-extensions (0.1.5)
203
230
  zeitwerk (2.6.18)
@@ -208,14 +235,13 @@ PLATFORMS
208
235
  DEPENDENCIES
209
236
  appraisal
210
237
  appraisal-matrix
211
- coveralls
212
238
  fibered_mysql2!
213
239
  mysql2 (~> 0.5)
214
240
  nokogiri
215
241
  pry
216
242
  pry-byebug
217
243
  rake
218
- rspec
244
+ rspec (~> 3.12.0)
219
245
 
220
246
  BUNDLED WITH
221
- 2.2.29
247
+ 2.6.9
@@ -30,5 +30,5 @@ Gem::Specification.new do |spec|
30
30
  spec.require_paths = ["lib"]
31
31
 
32
32
  spec.add_dependency 'em-synchrony', '~> 1.0'
33
- spec.add_dependency 'rails', '>= 6.1', '< 7.1'
33
+ spec.add_dependency 'rails', '>= 7.0', '< 7.2'
34
34
  end
@@ -4,13 +4,15 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "appraisal"
6
6
  gem "appraisal-matrix"
7
- gem "coveralls", require: false
8
7
  gem "mysql2", "~> 0.5"
9
8
  gem "nokogiri"
10
9
  gem "pry"
11
10
  gem "pry-byebug"
12
11
  gem "rake"
13
- gem "rspec"
12
+ gem "rspec", "~> 3.12.0"
14
13
  gem "rails", "~> 7.0.0"
14
+ gem "mutex_m"
15
+ gem "base64"
16
+ gem "bigdecimal"
15
17
 
16
18
  gemspec path: "../"
@@ -4,13 +4,12 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "appraisal"
6
6
  gem "appraisal-matrix"
7
- gem "coveralls", require: false
8
7
  gem "mysql2", "~> 0.5"
9
8
  gem "nokogiri"
10
9
  gem "pry"
11
10
  gem "pry-byebug"
12
11
  gem "rake"
13
- gem "rspec"
14
- gem "rails", "~> 6.1.0"
12
+ gem "rspec", "~> 3.12.0"
13
+ gem "rails", "~> 7.1.0"
15
14
 
16
15
  gemspec path: "../"
@@ -3,11 +3,12 @@
3
3
  require 'em-synchrony'
4
4
  require 'active_model'
5
5
  require 'active_record/errors'
6
+
6
7
  require 'active_record/connection_adapters/mysql2_adapter'
7
- require 'active_record/connection_adapters/em_mysql2_adapter'
8
+ require 'em-synchrony/mysql2'
8
9
 
9
10
  module FiberedMysql2
10
- module FiberedMysql2Adapter_5_2
11
+ module FiberedMysql2Adapter_7_0
11
12
  def lease
12
13
  if in_use?
13
14
  msg = "Cannot lease connection, ".dup
@@ -62,8 +63,10 @@ module FiberedMysql2
62
63
  end
63
64
  end
64
65
 
65
- class FiberedMysql2Adapter < ::ActiveRecord::ConnectionAdapters::EMMysql2Adapter
66
- include FiberedMysql2Adapter_5_2
66
+ class FiberedMysql2Adapter < ::ActiveRecord::ConnectionAdapters::Mysql2Adapter
67
+ if ::ActiveRecord.gem_version < "7.1"
68
+ include FiberedMysql2Adapter_7_0
69
+ end
67
70
 
68
71
  class << self
69
72
  # Copied from Mysql2Adapter, except with the EM Mysql2 client
@@ -77,9 +80,5 @@ module FiberedMysql2
77
80
  end
78
81
  end
79
82
  end
80
-
81
- def initialize(*args)
82
- super
83
- end
84
83
  end
85
84
  end
@@ -184,33 +184,36 @@ module FiberedMysql2
184
184
  end
185
185
 
186
186
  module FiberedDatabaseConnectionPool
187
- include FiberedMonitorMixin
188
-
189
- module Adapter_5_2
190
- def cached_connections
191
- @thread_cached_conns
187
+ module Adapter_7_0
188
+ def release_connection(owner_thread = Fiber.current)
189
+ if (conn = @thread_cached_conns.delete(connection_cache_key(owner_thread)))
190
+ checkin(conn)
191
+ end
192
192
  end
193
193
 
194
- def current_connection_id
195
- connection_cache_key(current_thread)
194
+ def with_connection
195
+ unless (conn = cached_connections[current_connection_id]) # Invoca Patch to use Fiber
196
+ conn = connection
197
+ fresh_connection = true
198
+ end
199
+ yield conn
200
+ ensure
201
+ release_connection if fresh_connection
196
202
  end
197
203
 
198
- def checkout(checkout_timeout = @checkout_timeout)
199
- begin
200
- reap_connections
201
- rescue => ex
202
- ActiveRecord::Base.logger.error("Exception occurred while executing reap_connections: #{ex}")
203
- end
204
- super
204
+ def current_thread
205
+ Fiber.current
205
206
  end
206
207
 
207
- def release_connection(owner_thread = Fiber.current)
208
- if (conn = @thread_cached_conns.delete(connection_cache_key(owner_thread)))
209
- checkin(conn)
210
- end
208
+ def connection
209
+ cached_connections[current_connection_id] ||= checkout
211
210
  end
212
211
  end
213
- include Adapter_5_2
212
+
213
+ if ::ActiveRecord.gem_version < "7.1"
214
+ include Adapter_7_0
215
+ end
216
+ include FiberedMonitorMixin # This is switches the connection pool's mutex and condition variables to event machine / Fiber compatible ones.
214
217
 
215
218
  def initialize(pool_config)
216
219
  if pool_config.db_config.reaping_frequency
@@ -222,41 +225,23 @@ module FiberedMysql2
222
225
  @reaper = nil # no need to keep a reference to this since it does nothing in this sub-class
223
226
  end
224
227
 
225
- def connection
226
- # this is correctly done double-checked locking
227
- # (ThreadSafe::Cache's lookups have volatile semantics)
228
- if (result = cached_connections[current_connection_id])
229
- result
230
- else
231
- synchronize do
232
- if (result = cached_connections[current_connection_id])
233
- result
234
- else
235
- cached_connections[current_connection_id] = checkout
236
- end
237
- end
238
- end
239
- end
240
-
241
- def reap_connections
242
- cached_connections.values.each do |connection|
243
- unless connection.owner.alive?
244
- checkin(connection)
245
- end
246
- end
228
+ def current_connection_id
229
+ connection_cache_key(current_thread)
247
230
  end
248
231
 
249
- private
250
-
251
- #--
252
- # This hook-in method allows for easier monkey-patching fixes needed by
253
- # JRuby users that use Fibers.
254
- def connection_cache_key(fiber)
255
- fiber
232
+ def cached_connections
233
+ @thread_cached_conns
256
234
  end
257
235
 
258
- def current_thread
259
- Fiber.current
236
+ # Invoca patch that reaps orphaned connections on checkout. This lets us immediately use a connection left open by dead fibers
237
+ # instead of waiting for all connections to be used in the pool before they are reaped.
238
+ def checkout(checkout_timeout = @checkout_timeout)
239
+ begin
240
+ reap
241
+ rescue => ex
242
+ ActiveRecord::Base.logger.error("Exception occurred while executing reap_connections: #{ex}")
243
+ end
244
+ super
260
245
  end
261
246
  end
262
247
  end
@@ -2,101 +2,6 @@
2
2
 
3
3
  require_relative '../active_record/connection_adapters/fibered_mysql2_adapter'
4
4
 
5
- module EM::Synchrony
6
- module ActiveRecord
7
- _ = Adapter_4_2
8
- module Adapter_4_2
9
- def configure_connection
10
- super # undo EM::Synchrony's override here
11
- end
12
-
13
- def transaction(*args)
14
- super # and here
15
- end
16
-
17
- _ = TransactionManager
18
- class TransactionManager < _
19
- # Overriding the em-synchrony override to bring it up to rails 6 requirements.
20
- # Changes from the original Rails 6 source are:
21
- # 1. the usage of _current_stack created by em-synchrony instead of the Rails provided @stack instance variable
22
- # 2. the usage of Fiber.current.object_id as a part of the savepoint transaction name
23
- #
24
- # Original EM Synchrony Source:
25
- # https://github.com/igrigorik/em-synchrony/blob/master/lib/em-synchrony/activerecord_4_2.rb#L35-L44
26
- #
27
- # Original Rails Source:
28
- # https://github.com/rails/rails/blob/6-0-stable/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb#L205-L224
29
- def begin_transaction(isolation: nil, joinable: true, _lazy: true)
30
- @connection.lock.synchronize do
31
- run_commit_callbacks = !current_transaction.joinable?
32
- transaction =
33
- if _current_stack.empty?
34
- ::ActiveRecord::ConnectionAdapters::RealTransaction.new(@connection, isolation:, joinable:, run_commit_callbacks: run_commit_callbacks)
35
- else
36
- ::ActiveRecord::ConnectionAdapters::SavepointTransaction.new(@connection, "active_record_#{Fiber.current.object_id}_#{open_transactions}", _current_stack.last, isolation:, joinable:, run_commit_callbacks: run_commit_callbacks)
37
- end
38
-
39
- if @connection.supports_lazy_transactions? && lazy_transactions_enabled? && _lazy
40
- @has_unmaterialized_transactions = true
41
- else
42
- transaction.materialize!
43
- end
44
- _current_stack.push(transaction)
45
- transaction
46
- end
47
- end
48
-
49
- # Overriding the ActiveRecord::TransactionManager#materialize_transactions method to use
50
- # fiber safe the _current_stack instead of the @stack instance variable. when marterializing
51
- # transactions.
52
- def materialize_transactions
53
- return if @materializing_transactions
54
- return unless @has_unmaterialized_transactions
55
-
56
- @connection.lock.synchronize do
57
- begin
58
- @materializing_transactions = true
59
- _current_stack.each { |t| t.materialize! unless t.materialized? }
60
- ensure
61
- @materializing_transactions = false
62
- end
63
- @has_unmaterialized_transactions = false
64
- end
65
- end
66
-
67
- # Overriding the ActiveRecord::TransactionManager#commit_transaction method to use
68
- # fiber safe the _current_stack instead of the @stack instance variable. when marterializing
69
- # transactions.
70
- def commit_transaction
71
- @connection.lock.synchronize do
72
- transaction = _current_stack.last
73
-
74
- begin
75
- transaction.before_commit_records
76
- ensure
77
- _current_stack.pop
78
- end
79
-
80
- transaction.commit
81
- transaction.commit_records
82
- end
83
- end
84
-
85
- # Overriding the ActiveRecord::TransactionManager#rollback_transaction method to use
86
- # fiber safe the _current_stack instead of the @stack instance variable. when marterializing
87
- # transactions.
88
- def rollback_transaction(transaction = nil)
89
- @connection.lock.synchronize do
90
- transaction ||= _current_stack.pop
91
- transaction.rollback
92
- transaction.rollback_records
93
- end
94
- end
95
- end
96
- end
97
- end
98
- end
99
-
100
5
  module FiberedMysql2
101
6
  module FiberedMysql2ConnectionFactory
102
7
  def fibered_mysql2_connection(raw_config)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FiberedMysql2
4
- VERSION = "0.3.1"
4
+ VERSION = "0.4.0.pre.tstarck.1"
5
5
  end
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.3.1
4
+ version: 0.4.0.pre.tstarck.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Invoca Development
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-10-31 00:00:00.000000000 Z
11
+ date: 2025-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: em-synchrony
@@ -30,20 +30,20 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '6.1'
33
+ version: '7.0'
34
34
  - - "<"
35
35
  - !ruby/object:Gem::Version
36
- version: '7.1'
36
+ version: '7.2'
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: '6.1'
43
+ version: '7.0'
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
- version: '7.1'
46
+ version: '7.2'
47
47
  description:
48
48
  email:
49
49
  - development@invoca.com
@@ -66,8 +66,8 @@ files:
66
66
  - bin/setup
67
67
  - fibered_mysql2.gemspec
68
68
  - gemfiles/.bundle/config
69
- - gemfiles/rails_6_1.gemfile
70
69
  - gemfiles/rails_7_0.gemfile
70
+ - gemfiles/rails_7_1.gemfile
71
71
  - lib/active_record/connection_adapters/fibered_mysql2_adapter.rb
72
72
  - lib/fibered_mysql2.rb
73
73
  - lib/fibered_mysql2/fibered_database_connection_pool.rb
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  requirements: []
98
- rubygems_version: 3.3.27
98
+ rubygems_version: 3.5.22
99
99
  signing_key:
100
100
  specification_version: 4
101
101
  summary: An adapter for fibered mysql2