fibered_mysql2 0.2.0.pre.1 → 1.0.0.colin.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/.github/CODEOWNERS +1 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +12 -6
- data/fibered_mysql2.gemspec +1 -1
- data/lib/active_record/connection_adapters/fibered_mysql2_adapter.rb +30 -46
- data/lib/fibered_mysql2/async_task.rb +18 -0
- data/lib/fibered_mysql2/fibered_database_connection_pool.rb +19 -220
- data/lib/fibered_mysql2/fibered_mysql2_connection_factory.rb +2 -53
- data/lib/fibered_mysql2/version.rb +1 -1
- data/lib/fibered_mysql2.rb +1 -0
- metadata +10 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75d1eaf3701caa8823cdfbec61e7d9734d1e5f463e7936010c5636715591c2c9
|
4
|
+
data.tar.gz: 715db9f2e07df69a6cf51a2389404f030cd9c257524544cb77c16f53de36b944
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a21b639b0b0ab6afcb558978a7e1060510e7fc7ca5e9a833b27d2b8c9eb49d023ac5beb5e0c500c3a3ff711d7f6ee0e49ae61f4e72f941c7a07420f60b9c866
|
7
|
+
data.tar.gz: 99adce5422229bdea37a08ed76a4dad71c6f4108ce3588d42dadc3b6c6fbb2895f65532842739dbe83cd7d6c748ea4b0cf7d57d05ca8fc26cbd0c6e65ab17e41
|
data/.github/CODEOWNERS
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
* @Invoca/octothorpe
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
3.2.1
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,10 @@ 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.2.0] - 2023-01-12
|
8
|
+
### Added
|
9
|
+
- Added support for Rails 6+ by adding knowledge of lazy transactions to the adapter.
|
10
|
+
|
7
11
|
## [0.1.5] - 2022-03-25
|
8
12
|
### Changed
|
9
13
|
- Upgraded Bundler to 2.2.29 and Ruby to 2.7.5. Removed support for Rails 4.
|
@@ -37,6 +41,7 @@ threaded, not fibered.
|
|
37
41
|
- Added TravisCI unit test pipeline.
|
38
42
|
- Added coverage reports via Coveralls.
|
39
43
|
|
44
|
+
[0.2.0]: https://github.com/Invoca/fibered_mysql2/compare/v0.1.5..v0.2.0
|
40
45
|
[0.1.5]: https://github.com/Invoca/fibered_mysql2/compare/v0.1.4..v0.1.5
|
41
46
|
[0.1.4]: https://github.com/Invoca/fibered_mysql2/compare/v0.1.3..v0.1.4
|
42
47
|
[0.1.3]: https://github.com/Invoca/fibered_mysql2/compare/v0.1.2..v0.1.3
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fibered_mysql2 (0.
|
5
|
-
|
4
|
+
fibered_mysql2 (1.0.0.colin.1)
|
5
|
+
async
|
6
6
|
rails (>= 5.2, < 7)
|
7
7
|
|
8
8
|
GEM
|
@@ -67,10 +67,16 @@ GEM
|
|
67
67
|
bundler
|
68
68
|
rake
|
69
69
|
thor (>= 0.14.0)
|
70
|
+
async (2.5.1)
|
71
|
+
console (~> 1.10)
|
72
|
+
io-event (~> 1.1)
|
73
|
+
timers (~> 4.1)
|
70
74
|
builder (3.2.4)
|
71
75
|
byebug (11.1.3)
|
72
76
|
coderay (1.1.3)
|
73
77
|
concurrent-ruby (1.1.8)
|
78
|
+
console (1.16.2)
|
79
|
+
fiber-local
|
74
80
|
coveralls (0.8.23)
|
75
81
|
json (>= 1.8, < 3)
|
76
82
|
simplecov (~> 0.16.1)
|
@@ -80,14 +86,13 @@ GEM
|
|
80
86
|
crass (1.0.6)
|
81
87
|
diff-lcs (1.4.4)
|
82
88
|
docile (1.3.2)
|
83
|
-
em-synchrony (1.0.6)
|
84
|
-
eventmachine (>= 1.0.0.beta.1)
|
85
89
|
erubi (1.10.0)
|
86
|
-
|
90
|
+
fiber-local (1.0.0)
|
87
91
|
globalid (0.4.2)
|
88
92
|
activesupport (>= 4.2.0)
|
89
93
|
i18n (1.8.7)
|
90
94
|
concurrent-ruby (~> 1.0)
|
95
|
+
io-event (1.2.2)
|
91
96
|
json (2.3.1)
|
92
97
|
loofah (2.8.0)
|
93
98
|
crass (~> 1.0.2)
|
@@ -103,7 +108,7 @@ GEM
|
|
103
108
|
mini_mime (1.0.2)
|
104
109
|
mini_portile2 (2.6.1)
|
105
110
|
minitest (5.14.3)
|
106
|
-
mysql2 (0.5.
|
111
|
+
mysql2 (0.5.5)
|
107
112
|
nio4r (2.5.4)
|
108
113
|
nokogiri (1.12.5)
|
109
114
|
mini_portile2 (~> 2.6.1)
|
@@ -175,6 +180,7 @@ GEM
|
|
175
180
|
tins (~> 1.0)
|
176
181
|
thor (1.0.1)
|
177
182
|
thread_safe (0.3.6)
|
183
|
+
timers (4.3.5)
|
178
184
|
tins (1.25.0)
|
179
185
|
sync
|
180
186
|
tzinfo (1.2.9)
|
data/fibered_mysql2.gemspec
CHANGED
@@ -29,6 +29,6 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
30
|
spec.require_paths = ["lib"]
|
31
31
|
|
32
|
-
spec.add_dependency '
|
32
|
+
spec.add_dependency 'async'
|
33
33
|
spec.add_dependency 'rails', '>= 5.2', '< 7'
|
34
34
|
end
|
@@ -1,88 +1,72 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'em-synchrony'
|
4
3
|
require 'active_model'
|
5
4
|
require 'active_record/errors'
|
6
|
-
require 'active_record/connection_adapters/
|
5
|
+
require 'active_record/connection_adapters/mysql2_adapter'
|
6
|
+
require_relative '../../fibered_mysql2/async_task'
|
7
7
|
|
8
8
|
module FiberedMysql2
|
9
|
-
module
|
9
|
+
module FiberedMysql2Adapter_6
|
10
10
|
def lease
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
module FiberedMysql2Adapter_5_2
|
20
|
-
def lease
|
21
|
-
if in_use?
|
22
|
-
msg = "Cannot lease connection, ".dup
|
23
|
-
if owner_fiber == Fiber.current
|
24
|
-
msg << "it is already leased by the current fiber."
|
11
|
+
if (ot = owner_task)
|
12
|
+
msg = +"Cannot lease connection; "
|
13
|
+
if ot == (current_task = AsyncTask.current_or_none)
|
14
|
+
msg << "it is already leased by the current Async::Task."
|
25
15
|
else
|
26
|
-
msg << "it is already in use by a different
|
27
|
-
"Current
|
16
|
+
msg << "it is already in use by a different Async::Task: #{ot}. " \
|
17
|
+
"Current Async::Task: #{current_task}."
|
28
18
|
end
|
29
19
|
raise ::ActiveRecord::ActiveRecordError, msg
|
30
20
|
end
|
31
21
|
|
32
|
-
@owner =
|
22
|
+
@owner = AsyncTask.current_or_none
|
33
23
|
end
|
34
24
|
|
35
25
|
def expire
|
36
|
-
if
|
37
|
-
# Because we are actively releasing connections from dead
|
38
|
-
# to enforce that we're expiring the current
|
26
|
+
if (ot = owner_task)
|
27
|
+
# Because we are actively releasing connections from dead tasks, we only want
|
28
|
+
# to enforce that we're expiring the current task's connection, iff the owner
|
39
29
|
# of the connection is still alive.
|
40
|
-
if
|
41
|
-
raise ::ActiveRecord::ActiveRecordError, "Cannot expire connection
|
42
|
-
"it is owned by a different
|
43
|
-
"Current
|
30
|
+
if ot.alive? && ot != (current_task = AsyncTask.current_or_none)
|
31
|
+
raise ::ActiveRecord::ActiveRecordError, "Cannot expire connection; " \
|
32
|
+
"it is owned by a different Async::Task: #{ot}. " \
|
33
|
+
"Current Async::Task: #{current_task}."
|
44
34
|
end
|
45
35
|
|
46
36
|
@idle_since = ::Concurrent.monotonic_time
|
47
37
|
@owner = nil
|
48
38
|
else
|
49
|
-
raise ::ActiveRecord::ActiveRecordError, "Cannot expire connection
|
39
|
+
raise ::ActiveRecord::ActiveRecordError, "Cannot expire connection; it is not currently leased."
|
50
40
|
end
|
51
41
|
end
|
52
42
|
|
53
43
|
def steal!
|
54
|
-
if
|
55
|
-
if
|
56
|
-
pool.send :remove_connection_from_thread_cache, self,
|
44
|
+
if (ot = owner_task)
|
45
|
+
if ot != (current_task = AsyncTask.current_or_none)
|
46
|
+
pool.send :remove_connection_from_thread_cache, self, ot
|
57
47
|
|
58
|
-
@owner =
|
48
|
+
@owner = current_task
|
59
49
|
end
|
60
50
|
else
|
61
|
-
raise ::ActiveRecord::ActiveRecordError, "Cannot steal connection
|
51
|
+
raise ::ActiveRecord::ActiveRecordError, "Cannot steal connection; it is not currently leased."
|
62
52
|
end
|
63
53
|
end
|
64
54
|
|
65
55
|
private
|
66
56
|
|
67
|
-
def
|
68
|
-
@owner.nil? || @owner.is_a?(
|
69
|
-
raise "@owner must be
|
57
|
+
def owner_task
|
58
|
+
@owner.nil? || @owner == AsyncTask::NoTaskPlaceholder || @owner.is_a?(Async::Task) or
|
59
|
+
raise "@owner must be an Async::Task or FiberedMysql2::AsyncTask::NoTaskPlaceholder! Found #{@owner.inspect}"
|
70
60
|
@owner
|
71
61
|
end
|
72
62
|
end
|
73
63
|
|
74
|
-
class FiberedMysql2Adapter < ::ActiveRecord::ConnectionAdapters::
|
64
|
+
class FiberedMysql2Adapter < ::ActiveRecord::ConnectionAdapters::Mysql2Adapter
|
75
65
|
case ::Rails::VERSION::MAJOR
|
76
|
-
when 4
|
77
|
-
include FiberedMysql2Adapter_4_2
|
78
|
-
when 5
|
79
|
-
include FiberedMysql2Adapter_5_2
|
80
66
|
when 6
|
81
|
-
include
|
82
|
-
|
83
|
-
|
84
|
-
false
|
85
|
-
end
|
67
|
+
include FiberedMysql2Adapter_6
|
68
|
+
else
|
69
|
+
raise ArgumentError, "unexpected Rails version #{Rails::VERSION::MAJOR}"
|
86
70
|
end
|
87
71
|
|
88
72
|
def initialize(*args)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FiberedMysql2
|
4
|
+
module AsyncTask
|
5
|
+
class NoTaskPlaceholder
|
6
|
+
class << self
|
7
|
+
def alive? = true
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class << self
|
12
|
+
# Adapted from https://github.com/socketry/async/blob/main/lib/async/task.rb#L236-L238
|
13
|
+
def current_or_none
|
14
|
+
Thread.current[:async_task] || NoTaskPlaceholder
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,240 +1,39 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# This class behaves the same as ActiveRecord's ConnectionPool, but synchronizes with fibers rather than threads.
|
3
|
+
# This class behaves the same as ActiveRecord's ConnectionPool, but synchronizes with Async::Task fibers rather than threads.
|
4
4
|
|
5
5
|
# Note - trace statements have been commented out. This is useful trace but we do not want it on by default.
|
6
6
|
# When we have configurable logging we can put this back and have it off by default.
|
7
7
|
|
8
|
-
require 'em-synchrony'
|
9
|
-
require 'em-synchrony/thread'
|
10
|
-
require 'fibered_mysql2/fibered_mutex_with_waiter_priority'
|
11
|
-
|
12
|
-
EventMachine::Synchrony::Thread::Mutex.prepend(FiberedMysql2::FiberedMutexWithWaiterPriority)
|
13
|
-
|
14
8
|
module FiberedMysql2
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
# FIXME: This isn't documented in Nutshell.
|
21
|
-
#
|
22
|
-
# Since MonitorMixin.new_cond returns a ConditionVariable, and the example
|
23
|
-
# above calls while_wait and signal, this class should be documented.
|
24
|
-
#
|
25
|
-
class Timeout < Exception; end
|
26
|
-
|
27
|
-
#
|
28
|
-
# Releases the lock held in the associated monitor and waits; reacquires the lock on wakeup.
|
29
|
-
#
|
30
|
-
# If +timeout+ is given, this method returns after +timeout+ seconds passed,
|
31
|
-
# even if no other thread doesn't signal.
|
32
|
-
#
|
33
|
-
def wait(timeout = nil)
|
34
|
-
Thread.handle_interrupt(EXCEPTION_NEVER) do
|
35
|
-
@monitor.__send__(:mon_check_owner)
|
36
|
-
count = @monitor.__send__(:mon_exit_for_cond)
|
37
|
-
begin
|
38
|
-
Thread.handle_interrupt(EXCEPTION_IMMEDIATE) do
|
39
|
-
@cond.wait(@monitor.instance_variable_get(:@mon_mutex), timeout)
|
40
|
-
end
|
41
|
-
return true
|
42
|
-
ensure
|
43
|
-
@monitor.__send__(:mon_enter_for_cond, count)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
#
|
49
|
-
# Calls wait repeatedly while the given block yields a truthy value.
|
50
|
-
#
|
51
|
-
def wait_while
|
52
|
-
while yield
|
53
|
-
wait
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
#
|
58
|
-
# Calls wait repeatedly until the given block yields a truthy value.
|
59
|
-
#
|
60
|
-
def wait_until
|
61
|
-
until yield
|
62
|
-
wait
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
#
|
67
|
-
# Wakes up the first thread in line waiting for this lock.
|
68
|
-
#
|
69
|
-
def signal
|
70
|
-
@monitor.__send__(:mon_check_owner)
|
71
|
-
@cond.signal
|
72
|
-
end
|
73
|
-
|
74
|
-
#
|
75
|
-
# Wakes up all threads waiting for this lock.
|
76
|
-
#
|
77
|
-
def broadcast
|
78
|
-
@monitor.__send__(:mon_check_owner)
|
79
|
-
@cond.broadcast
|
80
|
-
end
|
81
|
-
|
82
|
-
def initialize(monitor)
|
83
|
-
@monitor = monitor
|
84
|
-
@cond = EM::Synchrony::Thread::ConditionVariable.new
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
# From Ruby's MonitorMixin, with all occurrences of Thread changed to Fiber
|
89
|
-
module FiberedMonitorMixin
|
90
|
-
def self.extend_object(obj)
|
91
|
-
super
|
92
|
-
obj.__send__(:mon_initialize)
|
93
|
-
end
|
94
|
-
|
95
|
-
#
|
96
|
-
# Attempts to enter exclusive section. Returns +false+ if lock fails.
|
97
|
-
#
|
98
|
-
def mon_try_enter
|
99
|
-
if @mon_owner != Fiber.current
|
100
|
-
@mon_mutex.try_lock or return false
|
101
|
-
@mon_owner = Fiber.current
|
102
|
-
@mon_count = 0
|
103
|
-
end
|
104
|
-
@mon_count += 1
|
105
|
-
true
|
9
|
+
module FiberedDatabaseConnectionPool
|
10
|
+
case ::Rails::VERSION::MAJOR
|
11
|
+
when 6
|
12
|
+
else
|
13
|
+
raise ArgumentError, "unexpected Rails version #{Rails::VERSION::MAJOR}"
|
106
14
|
end
|
107
15
|
|
108
|
-
|
109
|
-
|
110
|
-
#
|
111
|
-
def mon_enter
|
112
|
-
if @mon_owner != Fiber.current
|
113
|
-
@mon_mutex.lock
|
114
|
-
@mon_owner = Fiber.current
|
115
|
-
@mon_count = 0
|
116
|
-
end
|
117
|
-
@mon_count += 1
|
16
|
+
def cached_connections
|
17
|
+
@thread_cached_conns
|
118
18
|
end
|
119
19
|
|
120
|
-
|
121
|
-
|
122
|
-
#
|
123
|
-
def mon_exit
|
124
|
-
mon_check_owner
|
125
|
-
@mon_count -= 1
|
126
|
-
if @mon_count == 0
|
127
|
-
@mon_owner = nil
|
128
|
-
@mon_mutex.unlock
|
129
|
-
end
|
20
|
+
def current_connection_id
|
21
|
+
connection_cache_key(current_thread)
|
130
22
|
end
|
131
23
|
|
132
|
-
|
133
|
-
# Enters exclusive section and executes the block. Leaves the exclusive
|
134
|
-
# section automatically when the block exits. See example under
|
135
|
-
# +MonitorMixin+.
|
136
|
-
#
|
137
|
-
def mon_synchronize
|
138
|
-
mon_enter
|
24
|
+
def checkout(checkout_timeout = @checkout_timeout)
|
139
25
|
begin
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
mon_exit
|
144
|
-
rescue => ex
|
145
|
-
ActiveRecord::Base.logger.error("Exception occurred while executing mon_exit: #{ex}")
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
|
-
alias synchronize mon_synchronize
|
150
|
-
|
151
|
-
#
|
152
|
-
# Creates a new FiberedConditionVariable associated with the
|
153
|
-
# receiver.
|
154
|
-
#
|
155
|
-
def new_cond
|
156
|
-
FiberedConditionVariable.new(self)
|
157
|
-
end
|
158
|
-
|
159
|
-
# Initializes the FiberedMonitorMixin after being included in a class
|
160
|
-
def mon_initialize
|
161
|
-
@mon_owner = nil
|
162
|
-
@mon_count = 0
|
163
|
-
@mon_mutex = EM::Synchrony::Thread::Mutex.new
|
164
|
-
end
|
165
|
-
|
166
|
-
def mon_check_owner
|
167
|
-
@mon_owner == Fiber.current or raise FiberError, "current fiber not owner"
|
168
|
-
end
|
169
|
-
|
170
|
-
private
|
171
|
-
|
172
|
-
def mon_enter_for_cond(count)
|
173
|
-
@mon_owner = Fiber.current
|
174
|
-
@mon_count = count
|
175
|
-
end
|
176
|
-
|
177
|
-
# returns the old mon_count
|
178
|
-
def mon_exit_for_cond
|
179
|
-
count = @mon_count
|
180
|
-
@mon_owner = nil
|
181
|
-
@mon_count = 0
|
182
|
-
count
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
module FiberedDatabaseConnectionPool
|
187
|
-
include FiberedMonitorMixin
|
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
|
26
|
+
reap_connections
|
27
|
+
rescue => ex
|
28
|
+
ActiveRecord::Base.logger.error("Exception occurred while executing reap_connections: #{ex.class}: #{ex.message}")
|
205
29
|
end
|
30
|
+
super
|
206
31
|
end
|
207
32
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
end
|
212
|
-
|
213
|
-
def current_connection_id
|
214
|
-
connection_cache_key(current_thread)
|
33
|
+
def release_connection(owner_task = AsyncTask.current_or_none)
|
34
|
+
if (conn = @thread_cached_conns.delete(connection_cache_key(owner_task)))
|
35
|
+
checkin(conn)
|
215
36
|
end
|
216
|
-
|
217
|
-
def checkout(checkout_timeout = @checkout_timeout)
|
218
|
-
begin
|
219
|
-
reap_connections
|
220
|
-
rescue => ex
|
221
|
-
ActiveRecord::Base.logger.error("Exception occurred while executing reap_connections: #{ex}")
|
222
|
-
end
|
223
|
-
super
|
224
|
-
end
|
225
|
-
|
226
|
-
def release_connection(owner_thread = Fiber.current)
|
227
|
-
if (conn = @thread_cached_conns.delete(connection_cache_key(owner_thread)))
|
228
|
-
checkin(conn)
|
229
|
-
end
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
case Rails::VERSION::MAJOR
|
234
|
-
when 4
|
235
|
-
include Adapter_4_2
|
236
|
-
when 5, 6
|
237
|
-
include Adapter_5_2
|
238
37
|
end
|
239
38
|
|
240
39
|
def initialize(connection_spec, *args, **keyword_args)
|
@@ -282,7 +81,7 @@ module FiberedMysql2
|
|
282
81
|
end
|
283
82
|
|
284
83
|
def current_thread
|
285
|
-
|
84
|
+
AsyncTask.current_or_none
|
286
85
|
end
|
287
86
|
end
|
288
87
|
end
|
@@ -2,57 +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
|
-
if Rails::VERSION::MAJOR > 5
|
20
|
-
# Overriding the em-synchrony override to bring it up to rails 6 requirements.
|
21
|
-
# Changes from the original Rails 6 source are:
|
22
|
-
# 1. the usage of _current_stack created by em-synchrony instead of the Rails provided @stack instance variable
|
23
|
-
# 2. the usage of Fiber.current.object_id as a part of the savepoint transaction name
|
24
|
-
#
|
25
|
-
# Original EM Synchrony Source:
|
26
|
-
# https://github.com/igrigorik/em-synchrony/blob/master/lib/em-synchrony/activerecord_4_2.rb#L35-L44
|
27
|
-
#
|
28
|
-
# Original Rails Source:
|
29
|
-
# https://github.com/rails/rails/blob/6-0-stable/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb#L205-L224
|
30
|
-
def begin_transaction(options = {})
|
31
|
-
@connection.lock.synchronize do
|
32
|
-
run_commit_callbacks = !current_transaction.joinable?
|
33
|
-
transaction =
|
34
|
-
if _current_stack.empty?
|
35
|
-
::ActiveRecord::ConnectionAdapters::RealTransaction.new(@connection, options, run_commit_callbacks: run_commit_callbacks)
|
36
|
-
else
|
37
|
-
::ActiveRecord::ConnectionAdapters::SavepointTransaction.new(@connection, "active_record_#{Fiber.current.object_id}_#{open_transactions}", _current_stack.last, options,
|
38
|
-
run_commit_callbacks: run_commit_callbacks)
|
39
|
-
end
|
40
|
-
|
41
|
-
if @connection.supports_lazy_transactions? && lazy_transactions_enabled? && options[:_lazy] != false
|
42
|
-
@has_unmaterialized_transactions = true
|
43
|
-
else
|
44
|
-
transaction.materialize!
|
45
|
-
end
|
46
|
-
_current_stack.push(transaction)
|
47
|
-
transaction
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
5
|
module FiberedMysql2
|
57
6
|
module FiberedMysql2ConnectionFactory
|
58
7
|
def fibered_mysql2_connection(raw_config)
|
@@ -63,10 +12,10 @@ module FiberedMysql2
|
|
63
12
|
|
64
13
|
client =
|
65
14
|
begin
|
66
|
-
Mysql2::
|
15
|
+
Mysql2::Client.new(config)
|
67
16
|
rescue Mysql2::Error => error
|
68
17
|
if error.message.include?("Unknown database")
|
69
|
-
raise ActiveRecord::NoDatabaseError.new(error.message
|
18
|
+
raise ActiveRecord::NoDatabaseError.new(error.message)
|
70
19
|
else
|
71
20
|
raise
|
72
21
|
end
|
data/lib/fibered_mysql2.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fibered_mysql2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0.colin.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: 2023-
|
11
|
+
date: 2023-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: async
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rails
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -51,6 +51,7 @@ executables: []
|
|
51
51
|
extensions: []
|
52
52
|
extra_rdoc_files: []
|
53
53
|
files:
|
54
|
+
- ".github/CODEOWNERS"
|
54
55
|
- ".github/workflows/build.yml"
|
55
56
|
- ".github/workflows/release.yml"
|
56
57
|
- ".gitignore"
|
@@ -69,6 +70,7 @@ files:
|
|
69
70
|
- gemfiles/rails_6.gemfile
|
70
71
|
- lib/active_record/connection_adapters/fibered_mysql2_adapter.rb
|
71
72
|
- lib/fibered_mysql2.rb
|
73
|
+
- lib/fibered_mysql2/async_task.rb
|
72
74
|
- lib/fibered_mysql2/fibered_database_connection_pool.rb
|
73
75
|
- lib/fibered_mysql2/fibered_mutex_with_waiter_priority.rb
|
74
76
|
- lib/fibered_mysql2/fibered_mysql2_connection_factory.rb
|
@@ -93,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
95
|
- !ruby/object:Gem::Version
|
94
96
|
version: 1.3.1
|
95
97
|
requirements: []
|
96
|
-
rubygems_version: 3.
|
98
|
+
rubygems_version: 3.4.6
|
97
99
|
signing_key:
|
98
100
|
specification_version: 4
|
99
101
|
summary: An adapter for fibered mysql2
|