fibered_mysql2 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +1 -1
- data/Appraisals +1 -1
- data/CHANGELOG.md +12 -1
- data/Gemfile.lock +69 -70
- data/fibered_mysql2.gemspec +1 -1
- data/gemfiles/{rails_6_0.gemfile → rails_7_0.gemfile} +1 -1
- data/lib/active_record/connection_adapters/fibered_mysql2_adapter.rb +17 -15
- data/lib/fibered_mysql2/fibered_database_connection_pool.rb +5 -35
- data/lib/fibered_mysql2/fibered_mysql2_connection_factory.rb +73 -89
- data/lib/fibered_mysql2/hash_config_override.rb +2 -0
- data/lib/fibered_mysql2/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b26f8b41b8008965bde3defa980553ef3f5ee82dc750d510f98d1728db1dfb2b
|
4
|
+
data.tar.gz: 8a6ff673f5be6e742bb010c217061a78012206d515cd2450efaf17159d208d90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2f5e70e6f236fcd7fea48e50bc09e33571d2d301e0f1eaa204f90d04e22fbd80585de33c3afd1dea13dea40076a56a158e2e39eeed7203c4b6c6b79b5a6fce4
|
7
|
+
data.tar.gz: 3b5e28792b82a53a7c43e937b30d953617c31399c6a34a74aba2e8d8e454661dc9a2c19728e6ccffa21b6e1a8481052073ccc48f2db84567baa5fb4bfe2b6707
|
data/.github/workflows/build.yml
CHANGED
data/Appraisals
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,9 +4,20 @@ 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.3.0] - 2024-10-23
|
8
|
+
### Added
|
9
|
+
- Support for Rails 7.0.
|
10
|
+
|
11
|
+
### Removed
|
12
|
+
- Removed support for Rails 6.0 and Rails 5.
|
13
|
+
|
14
|
+
### Changed
|
15
|
+
- Clean up FiberedMysql2ConnectionFactory#fibered_mysql2_connection to better match Mysql2Adapter behavior.
|
16
|
+
- Change FiberedMysql2::FiberedDatabaseConnectionPool#initialize to match ActiveRecord::ConnectionAdapters::ConnectionPool#initialize arguments.
|
17
|
+
|
7
18
|
## [0.2.1] - 2024-08-19
|
8
19
|
### Fixed
|
9
|
-
- Fixed bugs in Rails 6.1
|
20
|
+
- Fixed bugs in Rails 6.1
|
10
21
|
|
11
22
|
## [0.2.0] - 2023-01-12
|
12
23
|
### Added
|
data/Gemfile.lock
CHANGED
@@ -1,72 +1,78 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fibered_mysql2 (0.
|
4
|
+
fibered_mysql2 (0.3.0)
|
5
5
|
em-synchrony (~> 1.0)
|
6
|
-
rails (>=
|
6
|
+
rails (>= 6.1, < 7.1)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
actioncable (
|
12
|
-
actionpack (=
|
13
|
-
activesupport (=
|
11
|
+
actioncable (7.0.8.5)
|
12
|
+
actionpack (= 7.0.8.5)
|
13
|
+
activesupport (= 7.0.8.5)
|
14
14
|
nio4r (~> 2.0)
|
15
15
|
websocket-driver (>= 0.6.1)
|
16
|
-
actionmailbox (
|
17
|
-
actionpack (=
|
18
|
-
activejob (=
|
19
|
-
activerecord (=
|
20
|
-
activestorage (=
|
21
|
-
activesupport (=
|
16
|
+
actionmailbox (7.0.8.5)
|
17
|
+
actionpack (= 7.0.8.5)
|
18
|
+
activejob (= 7.0.8.5)
|
19
|
+
activerecord (= 7.0.8.5)
|
20
|
+
activestorage (= 7.0.8.5)
|
21
|
+
activesupport (= 7.0.8.5)
|
22
22
|
mail (>= 2.7.1)
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
net-imap
|
24
|
+
net-pop
|
25
|
+
net-smtp
|
26
|
+
actionmailer (7.0.8.5)
|
27
|
+
actionpack (= 7.0.8.5)
|
28
|
+
actionview (= 7.0.8.5)
|
29
|
+
activejob (= 7.0.8.5)
|
30
|
+
activesupport (= 7.0.8.5)
|
28
31
|
mail (~> 2.5, >= 2.5.4)
|
32
|
+
net-imap
|
33
|
+
net-pop
|
34
|
+
net-smtp
|
29
35
|
rails-dom-testing (~> 2.0)
|
30
|
-
actionpack (
|
31
|
-
actionview (=
|
32
|
-
activesupport (=
|
33
|
-
rack (~> 2.0, >= 2.
|
36
|
+
actionpack (7.0.8.5)
|
37
|
+
actionview (= 7.0.8.5)
|
38
|
+
activesupport (= 7.0.8.5)
|
39
|
+
rack (~> 2.0, >= 2.2.4)
|
34
40
|
rack-test (>= 0.6.3)
|
35
41
|
rails-dom-testing (~> 2.0)
|
36
42
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
37
|
-
actiontext (
|
38
|
-
actionpack (=
|
39
|
-
activerecord (=
|
40
|
-
activestorage (=
|
41
|
-
activesupport (=
|
43
|
+
actiontext (7.0.8.5)
|
44
|
+
actionpack (= 7.0.8.5)
|
45
|
+
activerecord (= 7.0.8.5)
|
46
|
+
activestorage (= 7.0.8.5)
|
47
|
+
activesupport (= 7.0.8.5)
|
48
|
+
globalid (>= 0.6.0)
|
42
49
|
nokogiri (>= 1.8.5)
|
43
|
-
actionview (
|
44
|
-
activesupport (=
|
50
|
+
actionview (7.0.8.5)
|
51
|
+
activesupport (= 7.0.8.5)
|
45
52
|
builder (~> 3.1)
|
46
53
|
erubi (~> 1.4)
|
47
54
|
rails-dom-testing (~> 2.0)
|
48
55
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
49
|
-
activejob (
|
50
|
-
activesupport (=
|
56
|
+
activejob (7.0.8.5)
|
57
|
+
activesupport (= 7.0.8.5)
|
51
58
|
globalid (>= 0.3.6)
|
52
|
-
activemodel (
|
53
|
-
activesupport (=
|
54
|
-
activerecord (
|
55
|
-
activemodel (=
|
56
|
-
activesupport (=
|
57
|
-
activestorage (
|
58
|
-
actionpack (=
|
59
|
-
activejob (=
|
60
|
-
activerecord (=
|
61
|
-
activesupport (=
|
59
|
+
activemodel (7.0.8.5)
|
60
|
+
activesupport (= 7.0.8.5)
|
61
|
+
activerecord (7.0.8.5)
|
62
|
+
activemodel (= 7.0.8.5)
|
63
|
+
activesupport (= 7.0.8.5)
|
64
|
+
activestorage (7.0.8.5)
|
65
|
+
actionpack (= 7.0.8.5)
|
66
|
+
activejob (= 7.0.8.5)
|
67
|
+
activerecord (= 7.0.8.5)
|
68
|
+
activesupport (= 7.0.8.5)
|
62
69
|
marcel (~> 1.0)
|
63
70
|
mini_mime (>= 1.1.0)
|
64
|
-
activesupport (
|
71
|
+
activesupport (7.0.8.5)
|
65
72
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
66
73
|
i18n (>= 1.6, < 2)
|
67
74
|
minitest (>= 5.1)
|
68
75
|
tzinfo (~> 2.0)
|
69
|
-
zeitwerk (~> 2.3)
|
70
76
|
appraisal (2.5.0)
|
71
77
|
bundler
|
72
78
|
rake
|
@@ -94,7 +100,7 @@ GEM
|
|
94
100
|
eventmachine (1.2.7)
|
95
101
|
globalid (1.2.1)
|
96
102
|
activesupport (>= 6.1)
|
97
|
-
i18n (1.14.
|
103
|
+
i18n (1.14.6)
|
98
104
|
concurrent-ruby (~> 1.0)
|
99
105
|
json (2.7.2)
|
100
106
|
loofah (2.22.0)
|
@@ -111,7 +117,7 @@ GEM
|
|
111
117
|
mini_portile2 (2.8.7)
|
112
118
|
minitest (5.25.1)
|
113
119
|
mysql2 (0.5.6)
|
114
|
-
net-imap (0.
|
120
|
+
net-imap (0.5.0)
|
115
121
|
date
|
116
122
|
net-protocol
|
117
123
|
net-pop (0.1.2)
|
@@ -131,24 +137,23 @@ GEM
|
|
131
137
|
byebug (~> 11.0)
|
132
138
|
pry (>= 0.13, < 0.15)
|
133
139
|
racc (1.8.1)
|
134
|
-
rack (2.2.
|
140
|
+
rack (2.2.10)
|
135
141
|
rack-test (2.1.0)
|
136
142
|
rack (>= 1.3)
|
137
|
-
rails (
|
138
|
-
actioncable (=
|
139
|
-
actionmailbox (=
|
140
|
-
actionmailer (=
|
141
|
-
actionpack (=
|
142
|
-
actiontext (=
|
143
|
-
actionview (=
|
144
|
-
activejob (=
|
145
|
-
activemodel (=
|
146
|
-
activerecord (=
|
147
|
-
activestorage (=
|
148
|
-
activesupport (=
|
143
|
+
rails (7.0.8.5)
|
144
|
+
actioncable (= 7.0.8.5)
|
145
|
+
actionmailbox (= 7.0.8.5)
|
146
|
+
actionmailer (= 7.0.8.5)
|
147
|
+
actionpack (= 7.0.8.5)
|
148
|
+
actiontext (= 7.0.8.5)
|
149
|
+
actionview (= 7.0.8.5)
|
150
|
+
activejob (= 7.0.8.5)
|
151
|
+
activemodel (= 7.0.8.5)
|
152
|
+
activerecord (= 7.0.8.5)
|
153
|
+
activestorage (= 7.0.8.5)
|
154
|
+
activesupport (= 7.0.8.5)
|
149
155
|
bundler (>= 1.15.0)
|
150
|
-
railties (=
|
151
|
-
sprockets-rails (>= 2.0.0)
|
156
|
+
railties (= 7.0.8.5)
|
152
157
|
rails-dom-testing (2.2.0)
|
153
158
|
activesupport (>= 5.0.0)
|
154
159
|
minitest
|
@@ -156,12 +161,13 @@ GEM
|
|
156
161
|
rails-html-sanitizer (1.6.0)
|
157
162
|
loofah (~> 2.21)
|
158
163
|
nokogiri (~> 1.14)
|
159
|
-
railties (
|
160
|
-
actionpack (=
|
161
|
-
activesupport (=
|
164
|
+
railties (7.0.8.5)
|
165
|
+
actionpack (= 7.0.8.5)
|
166
|
+
activesupport (= 7.0.8.5)
|
162
167
|
method_source
|
163
168
|
rake (>= 12.2)
|
164
169
|
thor (~> 1.0)
|
170
|
+
zeitwerk (~> 2.5)
|
165
171
|
rake (13.2.1)
|
166
172
|
rspec (3.13.0)
|
167
173
|
rspec-core (~> 3.13.0)
|
@@ -181,17 +187,10 @@ GEM
|
|
181
187
|
json (>= 1.8, < 3)
|
182
188
|
simplecov-html (~> 0.10.0)
|
183
189
|
simplecov-html (0.10.2)
|
184
|
-
sprockets (4.2.1)
|
185
|
-
concurrent-ruby (~> 1.0)
|
186
|
-
rack (>= 2.2.4, < 4)
|
187
|
-
sprockets-rails (3.5.2)
|
188
|
-
actionpack (>= 6.1)
|
189
|
-
activesupport (>= 6.1)
|
190
|
-
sprockets (>= 3.0.0)
|
191
190
|
sync (0.5.0)
|
192
191
|
term-ansicolor (1.11.2)
|
193
192
|
tins (~> 1.0)
|
194
|
-
thor (1.3.
|
193
|
+
thor (1.3.2)
|
195
194
|
timeout (0.4.1)
|
196
195
|
tins (1.33.0)
|
197
196
|
bigdecimal
|
@@ -201,7 +200,7 @@ GEM
|
|
201
200
|
websocket-driver (0.7.6)
|
202
201
|
websocket-extensions (>= 0.1.0)
|
203
202
|
websocket-extensions (0.1.5)
|
204
|
-
zeitwerk (2.6.
|
203
|
+
zeitwerk (2.6.18)
|
205
204
|
|
206
205
|
PLATFORMS
|
207
206
|
ruby
|
data/fibered_mysql2.gemspec
CHANGED
@@ -6,16 +6,6 @@ require 'active_record/errors'
|
|
6
6
|
require 'active_record/connection_adapters/em_mysql2_adapter'
|
7
7
|
|
8
8
|
module FiberedMysql2
|
9
|
-
module FiberedMysql2Adapter_4_2
|
10
|
-
def lease
|
11
|
-
synchronize do
|
12
|
-
unless in_use?
|
13
|
-
@owner = Fiber.current
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
9
|
module FiberedMysql2Adapter_5_2
|
20
10
|
def lease
|
21
11
|
if in_use?
|
@@ -72,11 +62,23 @@ module FiberedMysql2
|
|
72
62
|
end
|
73
63
|
|
74
64
|
class FiberedMysql2Adapter < ::ActiveRecord::ConnectionAdapters::EMMysql2Adapter
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
65
|
+
include FiberedMysql2Adapter_5_2
|
66
|
+
|
67
|
+
class << self
|
68
|
+
# Copied from Mysql2Adapter, except with the EM Mysql2 client
|
69
|
+
def new_client(config)
|
70
|
+
Mysql2::EM::Client.new(config)
|
71
|
+
rescue Mysql2::Error => error
|
72
|
+
if error.error_number == ConnectionAdapters::Mysql2Adapter::ER_BAD_DB_ERROR
|
73
|
+
raise ActiveRecord::NoDatabaseError.db_error(config[:database])
|
74
|
+
elsif error.error_number == ConnectionAdapters::Mysql2Adapter::ER_ACCESS_DENIED_ERROR
|
75
|
+
raise ActiveRecord::DatabaseConnectionError.username_error(config[:username])
|
76
|
+
elsif [ConnectionAdapters::Mysql2Adapter::ER_CONN_HOST_ERROR, ConnectionAdapters::Mysql2Adapter::ER_UNKNOWN_HOST_ERROR].include?(error.error_number)
|
77
|
+
raise ActiveRecord::DatabaseConnectionError.hostname_error(config[:host])
|
78
|
+
else
|
79
|
+
raise ActiveRecord::ConnectionNotEstablished, error.message
|
80
|
+
end
|
81
|
+
end
|
80
82
|
end
|
81
83
|
|
82
84
|
def initialize(*args)
|
@@ -186,25 +186,6 @@ module FiberedMysql2
|
|
186
186
|
module FiberedDatabaseConnectionPool
|
187
187
|
include FiberedMonitorMixin
|
188
188
|
|
189
|
-
module Adapter_4_2
|
190
|
-
def cached_connections
|
191
|
-
@reserved_connections
|
192
|
-
end
|
193
|
-
|
194
|
-
def current_connection_id
|
195
|
-
ActiveRecord::Base.connection_id ||= Fiber.current.object_id
|
196
|
-
end
|
197
|
-
|
198
|
-
def checkout
|
199
|
-
begin
|
200
|
-
reap_connections
|
201
|
-
rescue => ex
|
202
|
-
ActiveRecord::Base.logger.error("Exception occurred while executing reap_connections: #{ex}")
|
203
|
-
end
|
204
|
-
super
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
189
|
module Adapter_5_2
|
209
190
|
def cached_connections
|
210
191
|
@thread_cached_conns
|
@@ -229,27 +210,16 @@ module FiberedMysql2
|
|
229
210
|
end
|
230
211
|
end
|
231
212
|
end
|
213
|
+
include Adapter_5_2
|
232
214
|
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
when 5, 6
|
237
|
-
include Adapter_5_2
|
238
|
-
end
|
239
|
-
|
240
|
-
def initialize(connection_spec, *args, **keyword_args)
|
241
|
-
if ActiveRecord.gem_version < "6.1"
|
242
|
-
connection_spec.config[:reaping_frequency] and raise "reaping_frequency is not supported (the ActiveRecord Reaper is thread-based)"
|
243
|
-
connection_spec.config[:reaping_frequency] = nil # starting in Rails 5, this defaults to 60 if not explicitly set
|
244
|
-
elsif connection_spec.db_config.reaping_frequency
|
245
|
-
connection_spec.db_config.reaping_frequency > 0 and raise "reaping_frequency is not supported (the ActiveRecord Reaper is thread-based)"
|
215
|
+
def initialize(pool_config)
|
216
|
+
if pool_config.db_config.reaping_frequency
|
217
|
+
pool_config.db_config.reaping_frequency > 0 and raise "reaping_frequency is not supported (the ActiveRecord Reaper is thread-based)"
|
246
218
|
end
|
247
219
|
|
248
|
-
super(
|
220
|
+
super(pool_config)
|
249
221
|
|
250
222
|
@reaper = nil # no need to keep a reference to this since it does nothing in this sub-class
|
251
|
-
|
252
|
-
# note that @reserved_connections is a ThreadSafe::Cache which is overkill in a fibered world, but harmless
|
253
223
|
end
|
254
224
|
|
255
225
|
def connection
|
@@ -16,90 +16,80 @@ module EM::Synchrony
|
|
16
16
|
|
17
17
|
_ = TransactionManager
|
18
18
|
class TransactionManager < _
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
else
|
44
|
-
::ActiveRecord::ConnectionAdapters::SavepointTransaction.new(@connection, "active_record_#{Fiber.current.object_id}_#{open_transactions}", _current_stack.last, **options, run_commit_callbacks: run_commit_callbacks)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
if @connection.supports_lazy_transactions? && lazy_transactions_enabled? && options[:_lazy] != false
|
49
|
-
@has_unmaterialized_transactions = true
|
50
|
-
else
|
51
|
-
transaction.materialize!
|
52
|
-
end
|
53
|
-
_current_stack.push(transaction)
|
54
|
-
transaction
|
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!
|
55
43
|
end
|
44
|
+
_current_stack.push(transaction)
|
45
|
+
transaction
|
56
46
|
end
|
47
|
+
end
|
57
48
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
end
|
72
|
-
@has_unmaterialized_transactions = false
|
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
|
73
62
|
end
|
63
|
+
@has_unmaterialized_transactions = false
|
74
64
|
end
|
65
|
+
end
|
75
66
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
transaction.commit
|
90
|
-
transaction.commit_records
|
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
|
91
78
|
end
|
79
|
+
|
80
|
+
transaction.commit
|
81
|
+
transaction.commit_records
|
92
82
|
end
|
83
|
+
end
|
93
84
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
end
|
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
|
103
93
|
end
|
104
94
|
end
|
105
95
|
end
|
@@ -111,23 +101,17 @@ module FiberedMysql2
|
|
111
101
|
module FiberedMysql2ConnectionFactory
|
112
102
|
def fibered_mysql2_connection(raw_config)
|
113
103
|
config = raw_config.symbolize_keys
|
104
|
+
config[:flags] ||= 0
|
114
105
|
|
106
|
+
if config[:flags].kind_of? Array
|
107
|
+
config[:flags].push "FOUND_ROWS"
|
108
|
+
else
|
109
|
+
config[:flags] |= Mysql2::Client::FOUND_ROWS
|
110
|
+
end
|
115
111
|
config[:username] = 'root' if config[:username].nil?
|
116
|
-
config[:flags] = Mysql2::Client::FOUND_ROWS if Mysql2::Client.const_defined?(:FOUND_ROWS)
|
117
|
-
|
118
|
-
client =
|
119
|
-
begin
|
120
|
-
Mysql2::EM::Client.new(config)
|
121
|
-
rescue Mysql2::Error => error
|
122
|
-
if error.message.include?("Unknown database")
|
123
|
-
raise ActiveRecord::NoDatabaseError.new(error.message, error)
|
124
|
-
else
|
125
|
-
raise
|
126
|
-
end
|
127
|
-
end
|
128
112
|
|
129
|
-
|
130
|
-
FiberedMysql2Adapter.new(client, logger,
|
113
|
+
client = FiberedMysql2Adapter.new_client(config)
|
114
|
+
FiberedMysql2Adapter.new(client, logger, nil, config)
|
131
115
|
end
|
132
116
|
end
|
133
117
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "active_record/database_configurations/hash_config"
|
4
|
+
|
3
5
|
module FiberedMysql2
|
4
6
|
module HashConfigOverride
|
5
7
|
# Override the reaping_frequency method to return nil so that the connection pool does not reap connections when in fibered mode.
|
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
|
+
version: 0.3.0
|
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-
|
11
|
+
date: 2024-10-23 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: '
|
33
|
+
version: '6.1'
|
34
34
|
- - "<"
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version: '7'
|
36
|
+
version: '7.1'
|
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: '
|
43
|
+
version: '6.1'
|
44
44
|
- - "<"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: '7'
|
46
|
+
version: '7.1'
|
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_0.gemfile
|
70
69
|
- gemfiles/rails_6_1.gemfile
|
70
|
+
- gemfiles/rails_7_0.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
|