fibered_mysql2 0.4.0.pre.tstarck.2 → 0.4.0.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fcddd19ebaa9bb4c2bcfba7bcb7862b9fb07a31ef4ecd122d46c345a563f8ec
|
4
|
+
data.tar.gz: 65666da2f04f234f15e8945f8b693341599c478a471756963091c19c6391f770
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fdcc099c7c98ec0860a198d7ede37859c1c060c791f2fa33acb8659b02fabdc64f675fcbdc3cb4b555a3f40a3466945b15ebe586a14311ff70eb443e92ad30be
|
7
|
+
data.tar.gz: 755c58904cdd0405c464ba49f662b00c1747a30c61672472a683d17a8c6432e20d3c8c695ca82f34d2d4797c66741d7381ead66084478d634a04f187112c1b02
|
data/Gemfile.lock
CHANGED
@@ -54,6 +54,98 @@ module FiberedMysql2
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
+
def reset_transaction #:nodoc:
|
58
|
+
@transaction_manager = ::FiberedMysql2::FiberedMysql2Adapter_7_0::TransactionManager.new(self)
|
59
|
+
end
|
60
|
+
|
61
|
+
class TransactionManager < ::ActiveRecord::ConnectionAdapters::TransactionManager
|
62
|
+
def initialize(...)
|
63
|
+
super
|
64
|
+
@stack = Hash.new { |h, k| h[k] = [] }
|
65
|
+
end
|
66
|
+
|
67
|
+
def current_transaction #:nodoc:
|
68
|
+
_current_stack.last || ::ActiveRecord::ConnectionAdapters::TransactionManager::NULL_TRANSACTION
|
69
|
+
end
|
70
|
+
|
71
|
+
def open_transactions
|
72
|
+
_current_stack.size
|
73
|
+
end
|
74
|
+
|
75
|
+
def begin_transaction(isolation: nil, joinable: true, _lazy: true)
|
76
|
+
@connection.lock.synchronize do
|
77
|
+
run_commit_callbacks = !current_transaction.joinable?
|
78
|
+
transaction =
|
79
|
+
if _current_stack.empty?
|
80
|
+
::ActiveRecord::ConnectionAdapters::RealTransaction.new(@connection, isolation:, joinable:, run_commit_callbacks: run_commit_callbacks)
|
81
|
+
else
|
82
|
+
::ActiveRecord::ConnectionAdapters::SavepointTransaction.new(@connection, "active_record_#{Fiber.current.object_id}_#{open_transactions}", _current_stack.last, isolation:, joinable:, run_commit_callbacks: run_commit_callbacks)
|
83
|
+
end
|
84
|
+
|
85
|
+
if @connection.supports_lazy_transactions? && lazy_transactions_enabled? && _lazy
|
86
|
+
@has_unmaterialized_transactions = true
|
87
|
+
else
|
88
|
+
transaction.materialize!
|
89
|
+
end
|
90
|
+
_current_stack.push(transaction)
|
91
|
+
transaction
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# Overriding the ActiveRecord::TransactionManager#materialize_transactions method to use
|
96
|
+
# fiber safe the _current_stack instead of the @stack instance variable. when marterializing
|
97
|
+
# transactions.
|
98
|
+
def materialize_transactions
|
99
|
+
return if @materializing_transactions
|
100
|
+
return unless @has_unmaterialized_transactions
|
101
|
+
|
102
|
+
@connection.lock.synchronize do
|
103
|
+
begin
|
104
|
+
@materializing_transactions = true
|
105
|
+
_current_stack.each { |t| t.materialize! unless t.materialized? }
|
106
|
+
ensure
|
107
|
+
@materializing_transactions = false
|
108
|
+
end
|
109
|
+
@has_unmaterialized_transactions = false
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# Overriding the ActiveRecord::TransactionManager#commit_transaction method to use
|
114
|
+
# fiber safe the _current_stack instead of the @stack instance variable. when marterializing
|
115
|
+
# transactions.
|
116
|
+
def commit_transaction
|
117
|
+
@connection.lock.synchronize do
|
118
|
+
transaction = _current_stack.last
|
119
|
+
|
120
|
+
begin
|
121
|
+
transaction.before_commit_records
|
122
|
+
ensure
|
123
|
+
_current_stack.pop
|
124
|
+
end
|
125
|
+
|
126
|
+
transaction.commit
|
127
|
+
transaction.commit_records
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
# Overriding the ActiveRecord::TransactionManager#rollback_transaction method to use
|
132
|
+
# fiber safe the _current_stack instead of the @stack instance variable. when marterializing
|
133
|
+
# transactions.
|
134
|
+
def rollback_transaction(transaction = nil)
|
135
|
+
@connection.lock.synchronize do
|
136
|
+
transaction ||= _current_stack.pop
|
137
|
+
transaction.rollback
|
138
|
+
transaction.rollback_records
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
private
|
143
|
+
|
144
|
+
def _current_stack
|
145
|
+
@stack[Fiber.current.object_id]
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
57
149
|
private
|
58
150
|
|
59
151
|
def owner_fiber
|