fibered_mysql2 0.4.0.pre.tstarck.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5804c1cde27f4f2a0d3c222c5f49a207930c140ebc911e71b0b4655925b83917
4
- data.tar.gz: dd33b3c3dfba5b858fc2b85832b2d65650661e53513311f9b99a62089dade8c4
3
+ metadata.gz: d06e5fc60f480741cc45b28c4eb4ee10b36e364cea461ebc07f0817381e40021
4
+ data.tar.gz: 30ae5bf495212c120fc8920a803b5fa3bac4835dd311c862d905e288cd664b76
5
5
  SHA512:
6
- metadata.gz: 72b39a4bb7c035e1ab5d7ea7929f51c08d7fd0f7cac223d97444c3352e7bcd0f078d7146a5e2a0f446c1bae69774b0e5246dd77d425a83530e92be02f4215579
7
- data.tar.gz: e4ef21a8acd88205f612d0fe23924527d4ed65f78d54ec5a397317c27ab8a1454f17b9979b830a5ffe90ab2478851114305af3706c958f3cbd559ece21adeeb5
6
+ metadata.gz: 167c87ec227094ecf1b28805735d049e554b413db9bb8f04c65a4b0fde85f987047023074834842090bceb830924684c271246735c9abd64b79622a296081f09
7
+ data.tar.gz: b4419ac94cc20c2294b3caa28c615995a0f65637ba170b9dd4f405877dca2e660e39b23a33b53b75c529a4ba5a86393da35818b641898f573a50a75d5f4ef27e
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: FiberedMySQL2 Gem Build
3
- on: [push, pull_request]
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, 3.4]
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.3.8
1
+ 3.1.6
data/Appraisals CHANGED
@@ -2,10 +2,4 @@
2
2
 
3
3
  require "appraisal/matrix"
4
4
 
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
5
+ appraisal_matrix(rails: [">= 7.0", "< 7.2"])
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.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.
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
@@ -12,4 +12,4 @@ gem 'nokogiri'
12
12
  gem 'pry'
13
13
  gem 'pry-byebug'
14
14
  gem 'rake'
15
- gem 'rspec', '~> 3.12.0' # Rspec 3.13 is causing segfaults for some reason in CI...
15
+ gem 'rspec', '< 3.13'
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.2)
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.1)
12
- actionpack (= 7.1.5.1)
13
- activesupport (= 7.1.5.1)
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.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)
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.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)
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.1)
38
- actionview (= 7.1.5.1)
39
- activesupport (= 7.1.5.1)
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.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)
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.1)
55
- activesupport (= 7.1.5.1)
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.1)
61
- activesupport (= 7.1.5.1)
60
+ activejob (7.1.5.2)
61
+ activesupport (= 7.1.5.2)
62
62
  globalid (>= 0.3.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)
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.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
+ 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.1)
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.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)
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.1)
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.1)
194
- actionpack (= 7.1.5.1)
195
- activesupport (= 7.1.5.1)
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.3)
211
+ rspec-core (3.12.2)
212
212
  rspec-support (~> 3.12.0)
213
- rspec-expectations (3.12.4)
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.7)
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.2)
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 (~> 3.12.0)
244
+ rspec (< 3.13)
245
245
 
246
246
  BUNDLED WITH
247
- 2.6.9
247
+ 2.2.29
@@ -9,10 +9,7 @@ gem "nokogiri"
9
9
  gem "pry"
10
10
  gem "pry-byebug"
11
11
  gem "rake"
12
- gem "rspec", "~> 3.12.0"
12
+ gem "rspec", "< 3.13"
13
13
  gem "rails", "~> 7.0.0"
14
- gem "mutex_m"
15
- gem "base64"
16
- gem "bigdecimal"
17
14
 
18
15
  gemspec path: "../"
@@ -9,7 +9,7 @@ gem "nokogiri"
9
9
  gem "pry"
10
10
  gem "pry-byebug"
11
11
  gem "rake"
12
- gem "rspec", "~> 3.12.0"
12
+ gem "rspec", "< 3.13"
13
13
  gem "rails", "~> 7.1.0"
14
14
 
15
15
  gemspec path: "../"
@@ -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
 
@@ -63,9 +62,31 @@ module FiberedMysql2
63
62
  end
64
63
  end
65
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
+
66
85
  class FiberedMysql2Adapter < ::ActiveRecord::ConnectionAdapters::Mysql2Adapter
67
- if ::ActiveRecord.gem_version < "7.1"
86
+ if Rails.gem_version < "7.1"
68
87
  include FiberedMysql2Adapter_7_0
88
+ else
89
+ include FiberedMysql2Adapter_7_1
69
90
  end
70
91
 
71
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]) # Invoca Patch to use Fiber
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FiberedMysql2
4
- VERSION = "0.4.0.pre.tstarck.2"
4
+ VERSION = "0.4.0.pre.tstarck.10"
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.4.0.pre.tstarck.2
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-06 00:00:00.000000000 Z
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: '0'
96
+ version: 1.3.1
97
97
  requirements: []
98
- rubygems_version: 3.5.22
98
+ rubygems_version: 3.3.27
99
99
  signing_key:
100
100
  specification_version: 4
101
101
  summary: An adapter for fibered mysql2