fibered_mysql2 0.3.2.pre.tstarck.2 → 0.3.2.pre.tstarck.4
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/Gemfile.lock +1 -1
- data/lib/active_record/connection_adapters/fibered_mysql2_adapter.rb +0 -5
- data/lib/fibered_mysql2/fibered_database_connection_pool.rb +34 -24
- data/lib/fibered_mysql2/version.rb +1 -1
- data/lib/fibered_mysql2.rb +0 -1
- metadata +2 -3
- data/lib/fibered_mysql2/transaction_manager_override.rb +0 -99
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4773eb4c6e76109ac68abfc6513d14777501d11615e44024a867752e67700674
|
4
|
+
data.tar.gz: 1965bebf349ba637dd806105f6f1134c816d08609a858d8851dffda2f5805cb4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39a86b9bf560b89c868295bfd191d46c27e6badd19b586f488e0e366182a4e6db7e1293087258d74d4981622d1cc2a69685352936b36113458d64a55a63b0f9a
|
7
|
+
data.tar.gz: cfb223c6ba2c4ac7865be8cf9ac0041a0b7acfe272b4229af75d602092c2726af3bdeaa4bc2cbbf964778777d8b5f028b060e5b02e5e640bff3fbc12d7909175
|
data/Gemfile.lock
CHANGED
@@ -64,7 +64,6 @@ module FiberedMysql2
|
|
64
64
|
|
65
65
|
class FiberedMysql2Adapter < ::ActiveRecord::ConnectionAdapters::Mysql2Adapter
|
66
66
|
include FiberedMysql2Adapter_5_2
|
67
|
-
include FiberedMysql2::TransactionManagerOverride
|
68
67
|
|
69
68
|
class << self
|
70
69
|
# Copied from Mysql2Adapter, except with the EM Mysql2 client
|
@@ -78,9 +77,5 @@ module FiberedMysql2
|
|
78
77
|
end
|
79
78
|
end
|
80
79
|
end
|
81
|
-
|
82
|
-
def initialize(*args)
|
83
|
-
super
|
84
|
-
end
|
85
80
|
end
|
86
81
|
end
|
@@ -186,31 +186,30 @@ module FiberedMysql2
|
|
186
186
|
module FiberedDatabaseConnectionPool
|
187
187
|
include FiberedMonitorMixin
|
188
188
|
|
189
|
-
module
|
190
|
-
def
|
191
|
-
@thread_cached_conns
|
192
|
-
|
193
|
-
|
194
|
-
def current_connection_id
|
195
|
-
connection_cache_key(current_thread)
|
189
|
+
module Adapter_7_0
|
190
|
+
def release_connection(owner_thread = Fiber.current)
|
191
|
+
if (conn = @thread_cached_conns.delete(connection_cache_key(owner_thread)))
|
192
|
+
checkin(conn)
|
193
|
+
end
|
196
194
|
end
|
197
195
|
|
198
|
-
def
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
ActiveRecord::Base.logger.error("Exception occurred while executing reap_connections: #{ex}")
|
196
|
+
def with_connection
|
197
|
+
unless (conn = cached_connections[current_connection_id])
|
198
|
+
conn = connection
|
199
|
+
fresh_connection = true
|
203
200
|
end
|
204
|
-
|
201
|
+
yield conn
|
202
|
+
ensure
|
203
|
+
release_connection if fresh_connection
|
205
204
|
end
|
206
205
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
206
|
+
private
|
207
|
+
|
208
|
+
def current_thread
|
209
|
+
Fiber.current
|
211
210
|
end
|
212
211
|
end
|
213
|
-
include
|
212
|
+
include Adapter_7_0 if ActiveRecord.gem_version < "7.1"
|
214
213
|
|
215
214
|
def initialize(pool_config)
|
216
215
|
if pool_config.db_config.reaping_frequency
|
@@ -238,6 +237,23 @@ module FiberedMysql2
|
|
238
237
|
end
|
239
238
|
end
|
240
239
|
|
240
|
+
def checkout(checkout_timeout = @checkout_timeout)
|
241
|
+
begin
|
242
|
+
reap_connections
|
243
|
+
rescue => ex
|
244
|
+
ActiveRecord::Base.logger.error("Exception occurred while executing reap_connections: #{ex}")
|
245
|
+
end
|
246
|
+
super
|
247
|
+
end
|
248
|
+
|
249
|
+
def cached_connections
|
250
|
+
@thread_cached_conns
|
251
|
+
end
|
252
|
+
|
253
|
+
def current_connection_id
|
254
|
+
connection_cache_key(current_thread)
|
255
|
+
end
|
256
|
+
|
241
257
|
def reap_connections
|
242
258
|
cached_connections.values.each do |connection|
|
243
259
|
unless connection.owner.alive?
|
@@ -245,12 +261,6 @@ module FiberedMysql2
|
|
245
261
|
end
|
246
262
|
end
|
247
263
|
end
|
248
|
-
|
249
|
-
private
|
250
|
-
|
251
|
-
def current_thread
|
252
|
-
Fiber.current
|
253
|
-
end
|
254
264
|
end
|
255
265
|
end
|
256
266
|
|
data/lib/fibered_mysql2.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'fibered_mysql2/version'
|
4
|
-
require 'fibered_mysql2/transaction_manager_override'
|
5
4
|
require_relative '../lib/active_record/connection_adapters/fibered_mysql2_adapter'
|
6
5
|
require 'fibered_mysql2/fibered_database_connection_pool'
|
7
6
|
require 'fibered_mysql2/fibered_mutex_with_waiter_priority'
|
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.2.pre.tstarck.
|
4
|
+
version: 0.3.2.pre.tstarck.4
|
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-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: em-synchrony
|
@@ -73,7 +73,6 @@ files:
|
|
73
73
|
- lib/fibered_mysql2/fibered_mutex_with_waiter_priority.rb
|
74
74
|
- lib/fibered_mysql2/fibered_mysql2_connection_factory.rb
|
75
75
|
- lib/fibered_mysql2/hash_config_override.rb
|
76
|
-
- lib/fibered_mysql2/transaction_manager_override.rb
|
77
76
|
- lib/fibered_mysql2/version.rb
|
78
77
|
homepage: https://github.com/Invoca/fibered_mysql2
|
79
78
|
licenses: []
|
@@ -1,99 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "active_record"
|
4
|
-
|
5
|
-
module FiberedMysql2
|
6
|
-
module TransactionManagerOverride
|
7
|
-
class TransactionManager < ::ActiveRecord::ConnectionAdapters::TransactionManager
|
8
|
-
def initialize(*args)
|
9
|
-
super
|
10
|
-
@stack = Hash.new { |h, k| h[k] = [] }
|
11
|
-
end
|
12
|
-
|
13
|
-
def current_transaction #:nodoc:
|
14
|
-
_current_stack.last || NULL_TRANSACTION
|
15
|
-
end
|
16
|
-
|
17
|
-
def open_transactions
|
18
|
-
_current_stack.size
|
19
|
-
end
|
20
|
-
|
21
|
-
def begin_transaction(isolation: nil, joinable: true, _lazy: true)
|
22
|
-
@connection.lock.synchronize do
|
23
|
-
run_commit_callbacks = !current_transaction.joinable?
|
24
|
-
transaction =
|
25
|
-
if _current_stack.empty?
|
26
|
-
::ActiveRecord::ConnectionAdapters::RealTransaction.new(@connection, isolation:, joinable:, run_commit_callbacks: run_commit_callbacks)
|
27
|
-
else
|
28
|
-
::ActiveRecord::ConnectionAdapters::SavepointTransaction.new(@connection, "active_record_#{Fiber.current.object_id}_#{open_transactions}", _current_stack.last, isolation:, joinable:, run_commit_callbacks: run_commit_callbacks)
|
29
|
-
end
|
30
|
-
|
31
|
-
if @connection.supports_lazy_transactions? && lazy_transactions_enabled? && _lazy
|
32
|
-
@has_unmaterialized_transactions = true
|
33
|
-
else
|
34
|
-
transaction.materialize!
|
35
|
-
end
|
36
|
-
_current_stack.push(transaction)
|
37
|
-
transaction
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
# Overriding the ActiveRecord::TransactionManager#materialize_transactions method to use
|
42
|
-
# fiber safe the _current_stack instead of the @stack instance variable. when marterializing
|
43
|
-
# transactions.
|
44
|
-
def materialize_transactions
|
45
|
-
return if @materializing_transactions
|
46
|
-
return unless @has_unmaterialized_transactions
|
47
|
-
|
48
|
-
@connection.lock.synchronize do
|
49
|
-
begin
|
50
|
-
@materializing_transactions = true
|
51
|
-
_current_stack.each { |t| t.materialize! unless t.materialized? }
|
52
|
-
ensure
|
53
|
-
@materializing_transactions = false
|
54
|
-
end
|
55
|
-
@has_unmaterialized_transactions = false
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
# Overriding the ActiveRecord::TransactionManager#commit_transaction method to use
|
60
|
-
# fiber safe the _current_stack instead of the @stack instance variable. when marterializing
|
61
|
-
# transactions.
|
62
|
-
def commit_transaction
|
63
|
-
@connection.lock.synchronize do
|
64
|
-
transaction = _current_stack.last
|
65
|
-
|
66
|
-
begin
|
67
|
-
transaction.before_commit_records
|
68
|
-
ensure
|
69
|
-
_current_stack.pop
|
70
|
-
end
|
71
|
-
|
72
|
-
transaction.commit
|
73
|
-
transaction.commit_records
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
# Overriding the ActiveRecord::TransactionManager#rollback_transaction method to use
|
78
|
-
# fiber safe the _current_stack instead of the @stack instance variable. when marterializing
|
79
|
-
# transactions.
|
80
|
-
def rollback_transaction(transaction = nil)
|
81
|
-
@connection.lock.synchronize do
|
82
|
-
transaction ||= _current_stack.pop
|
83
|
-
transaction.rollback
|
84
|
-
transaction.rollback_records
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
private
|
89
|
-
|
90
|
-
def _current_stack
|
91
|
-
@stack[Fiber.current.object_id]
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
# def reset_transaction #:nodoc:
|
96
|
-
# @transaction_manager = ::FiberedMysql2::TransactionManagerOverride::TransactionManager.new(self)
|
97
|
-
# end
|
98
|
-
end
|
99
|
-
end
|