fibered_mysql2 0.3.2.pre.tstarck.1 → 0.3.2.pre.tstarck.3

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: 6d5ffddcba35cf6e56e907a78223d599cfb8059b3886b1e323f51a79a58ebe04
4
- data.tar.gz: 29ab8df4fb4fc505ae38a30e2c8b2cac14b950d84abf974368b1217608a7553c
3
+ metadata.gz: 66c97a135c9f7bc28aaf696c7ffea850182ad3ef6e4ea7edbbd048e31451fd8a
4
+ data.tar.gz: 495ea234c2494981a54432ca7c93a9afd2f491c59178d9f7e342e4853b79253f
5
5
  SHA512:
6
- metadata.gz: 9abc62b6d6325399935a9ad810dc409a46d5e280b5e486162e643f0473ac25cb58c0ef6afb42e7cfc059fb3fc4cf3656816807bf8efb1a37850712e6599a28b1
7
- data.tar.gz: dfcb809f7520a877ae022636d6f0ff846849c3af20ecc7529691b811c483b96192394e8518c3c3769124998c2d54f88a428196276847f61741031c1a3f05e36b
6
+ metadata.gz: aad30d8c0765a8a2563997711b99683feb235bf577d8611aa3dc8c0252490c34dfa7c40475bc5d6f3c7ab6f526e2f9d337edcf7181ff356cb3b593693d2fc4e5
7
+ data.tar.gz: ec87c505d83ac96610b44ce47c927458d5a4a772c270de9b122e68edc14c464bc4f5e9edcda0a2bcbf612356a78ce5fa6277b18a13a7d52f590968e379c04cdd
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fibered_mysql2 (0.3.2.pre.tstarck.1)
4
+ fibered_mysql2 (0.3.2.pre.tstarck.3)
5
5
  em-synchrony (~> 1.0)
6
6
  rails (>= 7.0, < 7.1)
7
7
 
@@ -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
@@ -186,31 +186,30 @@ module FiberedMysql2
186
186
  module FiberedDatabaseConnectionPool
187
187
  include FiberedMonitorMixin
188
188
 
189
- module Adapter_5_2
190
- def cached_connections
191
- @thread_cached_conns
192
- end
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 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}")
196
+ def with_connection
197
+ unless (conn = cached_connections[current_connection_id])
198
+ conn = connection
199
+ fresh_connection = true
203
200
  end
204
- super
201
+ yield conn
202
+ ensure
203
+ release_connection if fresh_connection
205
204
  end
206
205
 
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
206
+ private
207
+
208
+ def current_thread
209
+ Fiber.current
211
210
  end
212
211
  end
213
- include Adapter_5_2
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FiberedMysql2
4
- VERSION = "0.3.2.pre.tstarck.1"
4
+ VERSION = "0.3.2.pre.tstarck.3"
5
5
  end
@@ -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,7 +1,7 @@
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.1
4
+ version: 0.3.2.pre.tstarck.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Invoca Development
@@ -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