fibered_mysql2 0.1.0.pre.4 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -1
- data/Appraisals +1 -1
- data/CHANGELOG.md +25 -6
- data/Gemfile +2 -0
- data/Gemfile.lock +19 -11
- data/README.md +1 -1
- data/fibered_mysql2.gemspec +6 -4
- data/gemfiles/rails_6.gemfile +1 -1
- data/lib/active_record/connection_adapters/fibered_mysql2_adapter.rb +24 -4
- data/lib/fibered_mysql2/fibered_database_connection_pool.rb +34 -32
- data/lib/fibered_mysql2/version.rb +1 -1
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 225cf0ef6cb3df66126005bfc6a4371440ab608b29ea963844eb06e73cd7d246
|
4
|
+
data.tar.gz: b23527416fae27ac715336a587b91e34915b12458ff7847a5ddfd1e67dd583fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5dd796506d874c6cce296873e6f378d72d116a0491ef6d408cbd58366702573c11a525228ba7fe7801cae9808ea6a04dca1323f9eed1425222f9dcfb9ff0832d
|
7
|
+
data.tar.gz: 75edd0d65c74021b038c8668bce101e5b3baeecea48da3e237ff99e26d3a74dca7bb73337b909c22c43159669ed268252614c156a57b1ed77077f3fd8817f222
|
data/.rspec
CHANGED
data/Appraisals
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,11 +4,30 @@ 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.1.
|
7
|
+
## [0.1.3] - 2021-06-17
|
8
|
+
### Fixed
|
9
|
+
- When checking that @owner is a Fiber, allow nil.
|
10
|
+
|
11
|
+
## [0.1.2] - 2021-06-16
|
12
|
+
### Fixed
|
13
|
+
- Added checking to be certain that @owner is never overwritten with a non-Fiber by another mixin.
|
14
|
+
|
15
|
+
## [0.1.1] - 2021-02-12
|
16
|
+
### Fixed
|
17
|
+
- Fixed bug with Rails 5+ adapter where connections that have `steal!` called on them were not having their owner updated to the current Fiber, which would then cause an exception when trying to expire the connection (this showed up with the Rails 5 `ConnectionPool::Reaper` that reaps unused connections)
|
18
|
+
|
19
|
+
### Changed
|
20
|
+
- Updated Rails 6 dependency to 6.0.x for now as 6.1+ requires a newer version of the mysql gem (0.5+) that we do not yet support
|
21
|
+
|
22
|
+
|
23
|
+
## [0.1.0] - 2020-10-23
|
8
24
|
### Added
|
9
|
-
-
|
10
|
-
-
|
11
|
-
- TravisCI unit test pipeline.
|
12
|
-
-
|
25
|
+
- Added an adapter for Rails 4, 5, and 6.
|
26
|
+
- Added appraisals for Rails 4, 5, and 6.
|
27
|
+
- Added TravisCI unit test pipeline.
|
28
|
+
- Added coverage reports via Coveralls.
|
13
29
|
|
14
|
-
[0.1.
|
30
|
+
[0.1.3]: https://github.com/Invoca/fibered_mysql2/compare/v0.1.2..v0.1.3
|
31
|
+
[0.1.2]: https://github.com/Invoca/fibered_mysql2/compare/v0.1.1..v0.1.2
|
32
|
+
[0.1.1]: https://github.com/Invoca/fibered_mysql2/compare/v0.1.0..v0.1.1
|
33
|
+
[0.1.0]: https://github.com/Invoca/fibered_mysql2/tree/v0.1.0
|
data/Gemfile
CHANGED
@@ -8,8 +8,10 @@ gemspec
|
|
8
8
|
gem 'appraisal'
|
9
9
|
gem 'bundler', '~> 1.8'
|
10
10
|
gem 'coveralls', require: false
|
11
|
+
gem 'mimemagic', '~> 0.3', git: 'git@github.com:Invoca/mimemagic', ref: 'b084ce8d50c080f5a312156498be21a541fe72a2'
|
11
12
|
gem 'mysql2', '0.4.5'
|
12
13
|
gem 'pry', '~> 0.13'
|
13
14
|
gem 'pry-byebug', '~> 3.9'
|
15
|
+
gem 'rails', '< 6.1'
|
14
16
|
gem 'rake', '~> 10.0'
|
15
17
|
gem 'rspec', '~> 3.0'
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,14 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git@github.com:Invoca/mimemagic
|
3
|
+
revision: b084ce8d50c080f5a312156498be21a541fe72a2
|
4
|
+
ref: b084ce8d50c080f5a312156498be21a541fe72a2
|
5
|
+
specs:
|
6
|
+
mimemagic (0.3.5)
|
7
|
+
|
1
8
|
PATH
|
2
9
|
remote: .
|
3
10
|
specs:
|
4
|
-
fibered_mysql2 (0.1.
|
11
|
+
fibered_mysql2 (0.1.3)
|
5
12
|
em-synchrony (~> 1.0)
|
6
13
|
rails (>= 4.2, < 7)
|
7
14
|
|
@@ -63,14 +70,14 @@ GEM
|
|
63
70
|
minitest (~> 5.1)
|
64
71
|
tzinfo (~> 1.1)
|
65
72
|
zeitwerk (~> 2.2, >= 2.2.2)
|
66
|
-
appraisal (2.
|
73
|
+
appraisal (2.4.0)
|
67
74
|
bundler
|
68
75
|
rake
|
69
76
|
thor (>= 0.14.0)
|
70
77
|
builder (3.2.4)
|
71
78
|
byebug (11.1.3)
|
72
79
|
coderay (1.1.3)
|
73
|
-
concurrent-ruby (1.1.
|
80
|
+
concurrent-ruby (1.1.8)
|
74
81
|
coveralls (0.8.23)
|
75
82
|
json (>= 1.8, < 3)
|
76
83
|
simplecov (~> 0.16.1)
|
@@ -82,14 +89,14 @@ GEM
|
|
82
89
|
docile (1.3.2)
|
83
90
|
em-synchrony (1.0.6)
|
84
91
|
eventmachine (>= 1.0.0.beta.1)
|
85
|
-
erubi (1.
|
92
|
+
erubi (1.10.0)
|
86
93
|
eventmachine (1.2.7)
|
87
94
|
globalid (0.4.2)
|
88
95
|
activesupport (>= 4.2.0)
|
89
|
-
i18n (1.8.
|
96
|
+
i18n (1.8.7)
|
90
97
|
concurrent-ruby (~> 1.0)
|
91
98
|
json (2.3.1)
|
92
|
-
loofah (2.
|
99
|
+
loofah (2.8.0)
|
93
100
|
crass (~> 1.0.2)
|
94
101
|
nokogiri (>= 1.5.9)
|
95
102
|
mail (2.7.1)
|
@@ -97,10 +104,9 @@ GEM
|
|
97
104
|
marcel (0.3.3)
|
98
105
|
mimemagic (~> 0.3.2)
|
99
106
|
method_source (1.0.0)
|
100
|
-
mimemagic (0.3.5)
|
101
107
|
mini_mime (1.0.2)
|
102
108
|
mini_portile2 (2.4.0)
|
103
|
-
minitest (5.14.
|
109
|
+
minitest (5.14.3)
|
104
110
|
mysql2 (0.4.5)
|
105
111
|
nio4r (2.5.4)
|
106
112
|
nokogiri (1.10.10)
|
@@ -173,12 +179,12 @@ GEM
|
|
173
179
|
thread_safe (0.3.6)
|
174
180
|
tins (1.25.0)
|
175
181
|
sync
|
176
|
-
tzinfo (1.2.
|
182
|
+
tzinfo (1.2.9)
|
177
183
|
thread_safe (~> 0.1)
|
178
184
|
websocket-driver (0.7.3)
|
179
185
|
websocket-extensions (>= 0.1.0)
|
180
186
|
websocket-extensions (0.1.5)
|
181
|
-
zeitwerk (2.4.
|
187
|
+
zeitwerk (2.4.1)
|
182
188
|
|
183
189
|
PLATFORMS
|
184
190
|
ruby
|
@@ -188,11 +194,13 @@ DEPENDENCIES
|
|
188
194
|
bundler (~> 1.8)
|
189
195
|
coveralls
|
190
196
|
fibered_mysql2!
|
197
|
+
mimemagic (~> 0.3)!
|
191
198
|
mysql2 (= 0.4.5)
|
192
199
|
pry (~> 0.13)
|
193
200
|
pry-byebug (~> 3.9)
|
201
|
+
rails (< 6.1)
|
194
202
|
rake (~> 10.0)
|
195
203
|
rspec (~> 3.0)
|
196
204
|
|
197
205
|
BUNDLED WITH
|
198
|
-
1.17.
|
206
|
+
1.17.3
|
data/README.md
CHANGED
@@ -29,7 +29,7 @@ Behaves the same as `ActiveRecord::ConnectionAdapters::EMMysql2Adapter` but with
|
|
29
29
|
```ruby
|
30
30
|
connection = FiberedMysql2::FiberedMysql2Adapter.new(client, logger, options, config)
|
31
31
|
connection.lease
|
32
|
-
connection.expire
|
32
|
+
connection.expire # Rails 5+ only
|
33
33
|
```
|
34
34
|
|
35
35
|
## Development
|
data/fibered_mysql2.gemspec
CHANGED
@@ -7,16 +7,18 @@ require "fibered_mysql2/version"
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
8
|
spec.name = "fibered_mysql2"
|
9
9
|
spec.version = FiberedMysql2::VERSION
|
10
|
-
spec.authors = ["
|
11
|
-
spec.email = ["
|
10
|
+
spec.authors = ["Invoca Development"]
|
11
|
+
spec.email = ["development@invoca.com"]
|
12
12
|
|
13
13
|
spec.summary = "An adapter for fibered mysql2"
|
14
14
|
spec.homepage = "https://github.com/Invoca/fibered_mysql2"
|
15
15
|
|
16
16
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
17
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
-
spec.metadata
|
19
|
-
|
18
|
+
spec.metadata = {
|
19
|
+
"allowed_push_host" => "https://rubygems.org",
|
20
|
+
"homepage_uri" => spec.homepage
|
21
|
+
}
|
20
22
|
|
21
23
|
# Specify which files should be added to the gem when it is released.
|
22
24
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
data/gemfiles/rails_6.gemfile
CHANGED
@@ -20,10 +20,10 @@ module FiberedMysql2
|
|
20
20
|
def lease
|
21
21
|
if in_use?
|
22
22
|
msg = "Cannot lease connection, ".dup
|
23
|
-
if
|
23
|
+
if owner_fiber == Fiber.current
|
24
24
|
msg << "it is already leased by the current fiber."
|
25
25
|
else
|
26
|
-
msg << "it is already in use by a different fiber: #{
|
26
|
+
msg << "it is already in use by a different fiber: #{owner_fiber}. " \
|
27
27
|
"Current fiber: #{Fiber.current}."
|
28
28
|
end
|
29
29
|
raise ::ActiveRecord::ActiveRecordError, msg
|
@@ -37,9 +37,9 @@ module FiberedMysql2
|
|
37
37
|
# Because we are actively releasing connections from dead fibers, we only want
|
38
38
|
# to enforce that we're expiring the current fibers connection, iff the owner
|
39
39
|
# of the connection is still alive.
|
40
|
-
if
|
40
|
+
if owner_fiber.alive? && owner_fiber != Fiber.current
|
41
41
|
raise ::ActiveRecord::ActiveRecordError, "Cannot expire connection, " \
|
42
|
-
"it is owned by a different fiber: #{
|
42
|
+
"it is owned by a different fiber: #{owner_fiber}. " \
|
43
43
|
"Current fiber: #{Fiber.current}."
|
44
44
|
end
|
45
45
|
|
@@ -49,6 +49,26 @@ module FiberedMysql2
|
|
49
49
|
raise ::ActiveRecord::ActiveRecordError, "Cannot expire connection, it is not currently leased."
|
50
50
|
end
|
51
51
|
end
|
52
|
+
|
53
|
+
def steal!
|
54
|
+
if in_use?
|
55
|
+
if owner_fiber != Fiber.current
|
56
|
+
pool.send :remove_connection_from_thread_cache, self, owner_fiber
|
57
|
+
|
58
|
+
@owner = Fiber.current
|
59
|
+
end
|
60
|
+
else
|
61
|
+
raise ::ActiveRecord::ActiveRecordError, "Cannot steal connection, it is not currently leased."
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def owner_fiber
|
68
|
+
@owner.nil? || @owner.is_a?(Fiber) or
|
69
|
+
raise "@owner must be a Fiber! Found #{@owner.inspect}"
|
70
|
+
@owner
|
71
|
+
end
|
52
72
|
end
|
53
73
|
|
54
74
|
class FiberedMysql2Adapter < ::ActiveRecord::ConnectionAdapters::EMMysql2Adapter
|
@@ -124,12 +124,44 @@ module FiberedMysql2
|
|
124
124
|
def cached_connections
|
125
125
|
@reserved_connections
|
126
126
|
end
|
127
|
+
|
128
|
+
def current_connection_id
|
129
|
+
ActiveRecord::Base.connection_id ||= Fiber.current.object_id
|
130
|
+
end
|
131
|
+
|
132
|
+
def checkout
|
133
|
+
begin
|
134
|
+
reap_connections
|
135
|
+
rescue => ex
|
136
|
+
ActiveRecord::Base.logger.error("Exception occurred while executing reap_connections: #{ex}")
|
137
|
+
end
|
138
|
+
super
|
139
|
+
end
|
127
140
|
end
|
128
141
|
|
129
142
|
module Adapter_5_2
|
130
143
|
def cached_connections
|
131
144
|
@thread_cached_conns
|
132
145
|
end
|
146
|
+
|
147
|
+
def current_connection_id
|
148
|
+
connection_cache_key(current_thread)
|
149
|
+
end
|
150
|
+
|
151
|
+
def checkout(checkout_timeout = @checkout_timeout)
|
152
|
+
begin
|
153
|
+
reap_connections
|
154
|
+
rescue => ex
|
155
|
+
ActiveRecord::Base.logger.error("Exception occurred while executing reap_connections: #{ex}")
|
156
|
+
end
|
157
|
+
super
|
158
|
+
end
|
159
|
+
|
160
|
+
def release_connection(owner_thread = Fiber.current)
|
161
|
+
if (conn = @thread_cached_conns.delete(connection_cache_key(owner_thread)))
|
162
|
+
checkin(conn)
|
163
|
+
end
|
164
|
+
end
|
133
165
|
end
|
134
166
|
|
135
167
|
case Rails::VERSION::MAJOR
|
@@ -139,10 +171,10 @@ module FiberedMysql2
|
|
139
171
|
include Adapter_5_2
|
140
172
|
end
|
141
173
|
|
142
|
-
def initialize(connection_spec)
|
174
|
+
def initialize(connection_spec, *args, **keyword_args)
|
143
175
|
connection_spec.config[:reaping_frequency] and raise "reaping_frequency is not supported (the ActiveRecord Reaper is thread-based)"
|
144
176
|
|
145
|
-
super(connection_spec)
|
177
|
+
super(connection_spec, *args, **keyword_args)
|
146
178
|
|
147
179
|
@reaper = nil # no need to keep a reference to this since it does nothing in this sub-class
|
148
180
|
|
@@ -165,36 +197,6 @@ module FiberedMysql2
|
|
165
197
|
end
|
166
198
|
end
|
167
199
|
|
168
|
-
if Rails::VERSION::MAJOR > 4
|
169
|
-
def release_connection(owner_thread = Fiber.current)
|
170
|
-
if (conn = @thread_cached_conns.delete(connection_cache_key(owner_thread)))
|
171
|
-
checkin(conn)
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
def current_connection_id
|
177
|
-
case Rails::VERSION::MAJOR
|
178
|
-
when 4
|
179
|
-
ActiveRecord::Base.connection_id ||= Fiber.current.object_id
|
180
|
-
else
|
181
|
-
connection_cache_key(current_thread)
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
def checkout(checkout_timeout = @checkout_timeout)
|
186
|
-
begin
|
187
|
-
reap_connections
|
188
|
-
rescue => ex
|
189
|
-
ActiveRecord::Base.logger.error("Exception occurred while executing reap_connections: #{ex}")
|
190
|
-
end
|
191
|
-
if Rails::VERSION::MAJOR > 4
|
192
|
-
super
|
193
|
-
else
|
194
|
-
super()
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
200
|
def reap_connections
|
199
201
|
cached_connections.values.each do |connection|
|
200
202
|
unless connection.owner.alive?
|
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.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
autorequire:
|
7
|
+
- Invoca Development
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: em-synchrony
|
@@ -44,9 +44,9 @@ dependencies:
|
|
44
44
|
- - "<"
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '7'
|
47
|
-
description:
|
47
|
+
description:
|
48
48
|
email:
|
49
|
-
-
|
49
|
+
- development@invoca.com
|
50
50
|
executables: []
|
51
51
|
extensions: []
|
52
52
|
extra_rdoc_files: []
|
@@ -77,7 +77,7 @@ licenses: []
|
|
77
77
|
metadata:
|
78
78
|
allowed_push_host: https://rubygems.org
|
79
79
|
homepage_uri: https://github.com/Invoca/fibered_mysql2
|
80
|
-
post_install_message:
|
80
|
+
post_install_message:
|
81
81
|
rdoc_options: []
|
82
82
|
require_paths:
|
83
83
|
- lib
|
@@ -88,12 +88,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
88
88
|
version: '0'
|
89
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
90
|
requirements:
|
91
|
-
- - "
|
91
|
+
- - ">="
|
92
92
|
- !ruby/object:Gem::Version
|
93
|
-
version:
|
93
|
+
version: '0'
|
94
94
|
requirements: []
|
95
95
|
rubygems_version: 3.0.1
|
96
|
-
signing_key:
|
96
|
+
signing_key:
|
97
97
|
specification_version: 4
|
98
98
|
summary: An adapter for fibered mysql2
|
99
99
|
test_files: []
|