fibered_mysql2 0.1.0.pre.2 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 20d3f46c3c9b81ecdce87f118026e95bfe623322dc69deddd6beec758d550350
4
- data.tar.gz: 4193bb8362385556eeb6b966814ec5809d0e1a68c9a09ebd5e235165b298db5c
3
+ metadata.gz: 48308ffbe571baaa919c2f198d761657f9f77b95a87f67c3ef7493433a3e4a6a
4
+ data.tar.gz: c5893a679a730bfd7e1a088a06f86b82d65c95da9b9171fcb419f27298ca268c
5
5
  SHA512:
6
- metadata.gz: 8ff1891831752d602a3a56dec657d7b8b6111d7257e3c890c33acddd95a4b0651a5309d44aae7ac21184b0b614e58f4c70fe40f58f3eb62eaab8fcd66e52e14a
7
- data.tar.gz: c3cf276f8e0eaf7a99626c6aa5e0d34993d9763fd382782c7fb73605fa5211a45508324f442e6eb57f7a25896db2e44bf1102e0e99f6a0007b5dd02b6910a23c
6
+ metadata.gz: af9979eb4a038db1fcbec58dc5a88d617a71271c1588ff0717a4792f5442b3c59d82e9bc8d76b59821179099c87c8387a72bbbcdb096d10991320e7001c4bda8
7
+ data.tar.gz: 05a912e4b5504aebfb6a0ad5e8a29e72cb8e739066279982ead7aa89ca97b9308f2144ed6142833cba84ad7939c8ee0d364e71065606221ebe52cf4ee35ce0e1
data/.rspec CHANGED
@@ -1,3 +1,3 @@
1
- --format documentation
1
+ --format progress
2
2
  --color
3
3
  --require spec_helper
data/Appraisals CHANGED
@@ -9,5 +9,5 @@ appraise 'rails-5' do
9
9
  end
10
10
 
11
11
  appraise 'rails-6' do
12
- gem 'rails', '~> 6.0'
12
+ gem 'rails', '~> 6.0.0'
13
13
  end
data/CHANGELOG.md CHANGED
@@ -4,11 +4,20 @@ 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.0] - Unreleased
7
+ ## [0.1.1] - 2021-02-12
8
+ ### Fixed
9
+ - 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)
10
+
11
+ ### Changed
12
+ - 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
13
+
14
+
15
+ ## [0.1.0] - 2020-10-23
8
16
  ### Added
9
- - An adapter for Rails 4, 5, and 6.
10
- - Appraisals for Rails 4, 5, and 6.
11
- - TravisCI unit test pipeline.
12
- - Coverage reports via Coveralls.
17
+ - Added an adapter for Rails 4, 5, and 6.
18
+ - Added appraisals for Rails 4, 5, and 6.
19
+ - Added TravisCI unit test pipeline.
20
+ - Added coverage reports via Coveralls.
13
21
 
14
- [0.1.0]: https://github.com/Invoca/fibered_mysql2/tree/v0.1.0
22
+ [0.1.1]: https://github.com/Invoca/fibered_mysql2/compare/v0.1.0..v0.1.1
23
+ [0.1.0]: https://github.com/Invoca/fibered_mysql2/tree/v0.1.0
data/Gemfile.lock CHANGED
@@ -1,63 +1,63 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fibered_mysql2 (0.1.0.pre.2)
4
+ fibered_mysql2 (0.1.1)
5
5
  em-synchrony (~> 1.0)
6
6
  rails (>= 4.2, < 7)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- actioncable (6.0.3.3)
12
- actionpack (= 6.0.3.3)
11
+ actioncable (6.0.3.4)
12
+ actionpack (= 6.0.3.4)
13
13
  nio4r (~> 2.0)
14
14
  websocket-driver (>= 0.6.1)
15
- actionmailbox (6.0.3.3)
16
- actionpack (= 6.0.3.3)
17
- activejob (= 6.0.3.3)
18
- activerecord (= 6.0.3.3)
19
- activestorage (= 6.0.3.3)
20
- activesupport (= 6.0.3.3)
15
+ actionmailbox (6.0.3.4)
16
+ actionpack (= 6.0.3.4)
17
+ activejob (= 6.0.3.4)
18
+ activerecord (= 6.0.3.4)
19
+ activestorage (= 6.0.3.4)
20
+ activesupport (= 6.0.3.4)
21
21
  mail (>= 2.7.1)
22
- actionmailer (6.0.3.3)
23
- actionpack (= 6.0.3.3)
24
- actionview (= 6.0.3.3)
25
- activejob (= 6.0.3.3)
22
+ actionmailer (6.0.3.4)
23
+ actionpack (= 6.0.3.4)
24
+ actionview (= 6.0.3.4)
25
+ activejob (= 6.0.3.4)
26
26
  mail (~> 2.5, >= 2.5.4)
27
27
  rails-dom-testing (~> 2.0)
28
- actionpack (6.0.3.3)
29
- actionview (= 6.0.3.3)
30
- activesupport (= 6.0.3.3)
28
+ actionpack (6.0.3.4)
29
+ actionview (= 6.0.3.4)
30
+ activesupport (= 6.0.3.4)
31
31
  rack (~> 2.0, >= 2.0.8)
32
32
  rack-test (>= 0.6.3)
33
33
  rails-dom-testing (~> 2.0)
34
34
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
35
- actiontext (6.0.3.3)
36
- actionpack (= 6.0.3.3)
37
- activerecord (= 6.0.3.3)
38
- activestorage (= 6.0.3.3)
39
- activesupport (= 6.0.3.3)
35
+ actiontext (6.0.3.4)
36
+ actionpack (= 6.0.3.4)
37
+ activerecord (= 6.0.3.4)
38
+ activestorage (= 6.0.3.4)
39
+ activesupport (= 6.0.3.4)
40
40
  nokogiri (>= 1.8.5)
41
- actionview (6.0.3.3)
42
- activesupport (= 6.0.3.3)
41
+ actionview (6.0.3.4)
42
+ activesupport (= 6.0.3.4)
43
43
  builder (~> 3.1)
44
44
  erubi (~> 1.4)
45
45
  rails-dom-testing (~> 2.0)
46
46
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
47
- activejob (6.0.3.3)
48
- activesupport (= 6.0.3.3)
47
+ activejob (6.0.3.4)
48
+ activesupport (= 6.0.3.4)
49
49
  globalid (>= 0.3.6)
50
- activemodel (6.0.3.3)
51
- activesupport (= 6.0.3.3)
52
- activerecord (6.0.3.3)
53
- activemodel (= 6.0.3.3)
54
- activesupport (= 6.0.3.3)
55
- activestorage (6.0.3.3)
56
- actionpack (= 6.0.3.3)
57
- activejob (= 6.0.3.3)
58
- activerecord (= 6.0.3.3)
50
+ activemodel (6.0.3.4)
51
+ activesupport (= 6.0.3.4)
52
+ activerecord (6.0.3.4)
53
+ activemodel (= 6.0.3.4)
54
+ activesupport (= 6.0.3.4)
55
+ activestorage (6.0.3.4)
56
+ actionpack (= 6.0.3.4)
57
+ activejob (= 6.0.3.4)
58
+ activerecord (= 6.0.3.4)
59
59
  marcel (~> 0.3.1)
60
- activesupport (6.0.3.3)
60
+ activesupport (6.0.3.4)
61
61
  concurrent-ruby (~> 1.0, >= 1.0.2)
62
62
  i18n (>= 0.7, < 2)
63
63
  minitest (~> 5.1)
@@ -114,29 +114,29 @@ GEM
114
114
  rack (2.2.3)
115
115
  rack-test (1.1.0)
116
116
  rack (>= 1.0, < 3)
117
- rails (6.0.3.3)
118
- actioncable (= 6.0.3.3)
119
- actionmailbox (= 6.0.3.3)
120
- actionmailer (= 6.0.3.3)
121
- actionpack (= 6.0.3.3)
122
- actiontext (= 6.0.3.3)
123
- actionview (= 6.0.3.3)
124
- activejob (= 6.0.3.3)
125
- activemodel (= 6.0.3.3)
126
- activerecord (= 6.0.3.3)
127
- activestorage (= 6.0.3.3)
128
- activesupport (= 6.0.3.3)
117
+ rails (6.0.3.4)
118
+ actioncable (= 6.0.3.4)
119
+ actionmailbox (= 6.0.3.4)
120
+ actionmailer (= 6.0.3.4)
121
+ actionpack (= 6.0.3.4)
122
+ actiontext (= 6.0.3.4)
123
+ actionview (= 6.0.3.4)
124
+ activejob (= 6.0.3.4)
125
+ activemodel (= 6.0.3.4)
126
+ activerecord (= 6.0.3.4)
127
+ activestorage (= 6.0.3.4)
128
+ activesupport (= 6.0.3.4)
129
129
  bundler (>= 1.3.0)
130
- railties (= 6.0.3.3)
130
+ railties (= 6.0.3.4)
131
131
  sprockets-rails (>= 2.0.0)
132
132
  rails-dom-testing (2.0.3)
133
133
  activesupport (>= 4.2.0)
134
134
  nokogiri (>= 1.6)
135
135
  rails-html-sanitizer (1.3.0)
136
136
  loofah (~> 2.3)
137
- railties (6.0.3.3)
138
- actionpack (= 6.0.3.3)
139
- activesupport (= 6.0.3.3)
137
+ railties (6.0.3.4)
138
+ actionpack (= 6.0.3.4)
139
+ activesupport (= 6.0.3.4)
140
140
  method_source
141
141
  rake (>= 0.8.7)
142
142
  thor (>= 0.20.3, < 2.0)
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 // Rails 5+ only
32
+ connection.expire # Rails 5+ only
33
33
  ```
34
34
 
35
35
  ## Development
@@ -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 = ["Octothorp"]
11
- spec.email = ["octothorp@invoca.com"]
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["allowed_push_host"] = "https://rubygems.org"
19
- spec.metadata["homepage_uri"] = spec.homepage
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.
@@ -10,6 +10,6 @@ gem "pry", "~> 0.13"
10
10
  gem "pry-byebug", "~> 3.9"
11
11
  gem "rake", "~> 10.0"
12
12
  gem "rspec", "~> 3.0"
13
- gem "rails", "~> 6.0"
13
+ gem "rails", "~> 6.0.0"
14
14
 
15
15
  gemspec path: "../"
@@ -49,6 +49,18 @@ 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.current
56
+ pool.send :remove_connection_from_thread_cache, self, @owner
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
52
64
  end
53
65
 
54
66
  class FiberedMysql2Adapter < ::ActiveRecord::ConnectionAdapters::EMMysql2Adapter
@@ -1,6 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "fibered_mysql2/version"
3
+ require 'fibered_mysql2/version'
4
+ require_relative '../lib/active_record/connection_adapters/fibered_mysql2_adapter'
5
+ require 'fibered_mysql2/fibered_database_connection_pool'
6
+ require 'fibered_mysql2/fibered_mutex_with_waiter_priority'
7
+ require 'fibered_mysql2/fibered_mysql2_connection_factory'
4
8
 
5
9
  module FiberedMysql2
6
10
  class Error < StandardError; end
@@ -0,0 +1,223 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This class behaves the same as ActiveRecord's ConnectionPool, but synchronizes with fibers rather than threads.
4
+
5
+ # Note - trace statements have been commented out. This is useful trace but we do not want it on by default.
6
+ # When we have configurable logging we can put this back and have it off by default.
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
+ module FiberedMysql2
15
+ class FiberedConditionVariable < MonitorMixin::ConditionVariable
16
+ def initialize(monitor)
17
+ @monitor = monitor
18
+ @cond = EM::Synchrony::Thread::ConditionVariable.new
19
+ end
20
+ end
21
+
22
+ # From Ruby's MonitorMixin, with all occurrences of Thread changed to Fiber
23
+ module FiberedMonitorMixin
24
+ def self.extend_object(obj)
25
+ super
26
+ obj.__send__(:mon_initialize)
27
+ end
28
+
29
+ #
30
+ # Attempts to enter exclusive section. Returns +false+ if lock fails.
31
+ #
32
+ def mon_try_enter
33
+ if @mon_owner != Fiber.current
34
+ @mon_mutex.try_lock or return false
35
+ @mon_owner = Fiber.current
36
+ @mon_count = 0
37
+ end
38
+ @mon_count += 1
39
+ true
40
+ end
41
+
42
+ #
43
+ # Enters exclusive section.
44
+ #
45
+ def mon_enter
46
+ if @mon_owner != Fiber.current
47
+ @mon_mutex.lock
48
+ @mon_owner = Fiber.current
49
+ @mon_count = 0
50
+ end
51
+ @mon_count += 1
52
+ end
53
+
54
+ #
55
+ # Leaves exclusive section.
56
+ #
57
+ def mon_exit
58
+ mon_check_owner
59
+ @mon_count -= 1
60
+ if @mon_count == 0
61
+ @mon_owner = nil
62
+ @mon_mutex.unlock
63
+ end
64
+ end
65
+
66
+ #
67
+ # Enters exclusive section and executes the block. Leaves the exclusive
68
+ # section automatically when the block exits. See example under
69
+ # +MonitorMixin+.
70
+ #
71
+ def mon_synchronize
72
+ mon_enter
73
+ begin
74
+ yield
75
+ ensure
76
+ begin
77
+ mon_exit
78
+ rescue => ex
79
+ ActiveRecord::Base.logger.error("Exception occurred while executing mon_exit: #{ex}")
80
+ end
81
+ end
82
+ end
83
+ alias synchronize mon_synchronize
84
+
85
+ #
86
+ # Creates a new FiberedConditionVariable associated with the
87
+ # receiver.
88
+ #
89
+ def new_cond
90
+ FiberedConditionVariable.new(self)
91
+ end
92
+
93
+ private
94
+
95
+ # Initializes the FiberedMonitorMixin after being included in a class
96
+ def mon_initialize
97
+ @mon_owner = nil
98
+ @mon_count = 0
99
+ @mon_mutex = EM::Synchrony::Thread::Mutex.new
100
+ end
101
+
102
+ def mon_check_owner
103
+ @mon_owner == Fiber.current or raise FiberError, "current fiber not owner"
104
+ end
105
+
106
+ def mon_enter_for_cond(count)
107
+ @mon_owner = Fiber.current
108
+ @mon_count = count
109
+ end
110
+
111
+ # returns the old mon_count
112
+ def mon_exit_for_cond
113
+ count = @mon_count
114
+ @mon_owner = nil
115
+ @mon_count = 0
116
+ count
117
+ end
118
+ end
119
+
120
+ module FiberedDatabaseConnectionPool
121
+ include FiberedMonitorMixin
122
+
123
+ module Adapter_4_2
124
+ def cached_connections
125
+ @reserved_connections
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
140
+ end
141
+
142
+ module Adapter_5_2
143
+ def cached_connections
144
+ @thread_cached_conns
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
165
+ end
166
+
167
+ case Rails::VERSION::MAJOR
168
+ when 4
169
+ include Adapter_4_2
170
+ when 5, 6
171
+ include Adapter_5_2
172
+ end
173
+
174
+ def initialize(connection_spec, *args, **keyword_args)
175
+ connection_spec.config[:reaping_frequency] and raise "reaping_frequency is not supported (the ActiveRecord Reaper is thread-based)"
176
+
177
+ super(connection_spec, *args, **keyword_args)
178
+
179
+ @reaper = nil # no need to keep a reference to this since it does nothing in this sub-class
180
+
181
+ # note that @reserved_connections is a ThreadSafe::Cache which is overkill in a fibered world, but harmless
182
+ end
183
+
184
+ def connection
185
+ # this is correctly done double-checked locking
186
+ # (ThreadSafe::Cache's lookups have volatile semantics)
187
+ if (result = cached_connections[current_connection_id])
188
+ result
189
+ else
190
+ synchronize do
191
+ if (result = cached_connections[current_connection_id])
192
+ result
193
+ else
194
+ cached_connections[current_connection_id] = checkout
195
+ end
196
+ end
197
+ end
198
+ end
199
+
200
+ def reap_connections
201
+ cached_connections.values.each do |connection|
202
+ unless connection.owner.alive?
203
+ checkin(connection)
204
+ end
205
+ end
206
+ end
207
+
208
+ private
209
+
210
+ #--
211
+ # This hook-in method allows for easier monkey-patching fixes needed by
212
+ # JRuby users that use Fibers.
213
+ def connection_cache_key(fiber)
214
+ fiber
215
+ end
216
+
217
+ def current_thread
218
+ Fiber.current
219
+ end
220
+ end
221
+ end
222
+
223
+ ActiveRecord::ConnectionAdapters::ConnectionPool.prepend(FiberedMysql2::FiberedDatabaseConnectionPool)
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FiberedMysql2
4
+ module FiberedMutexWithWaiterPriority
5
+ # Note: @waiters is a bit confusing because the first waiter is actually the current fiber that has it locked;
6
+ # the _rest_ of @waiters are the actual waiters
7
+ def sleep(timeout = nil)
8
+ unlock
9
+ beg = Time.now
10
+ current = Fiber.current
11
+ @slept[current] = true
12
+ if timeout
13
+ timer = EM.add_timer(timeout) do
14
+ _wakeup(current)
15
+ end
16
+ Fiber.yield
17
+ EM.cancel_timer(timer) # if we resumed not via timer
18
+ else
19
+ Fiber.yield
20
+ end
21
+ @slept.delete(current)
22
+ yield if block_given?
23
+
24
+ # Invoca patch: inline lock that puts us at the front of the mutex @waiters queue instead of the back
25
+ # ==========================
26
+ @waiters.unshift(current)
27
+ Fiber.yield if @waiters.size > 1
28
+ # ==========================
29
+
30
+ Time.now - beg
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../active_record/connection_adapters/fibered_mysql2_adapter'
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
+ module FiberedMysql2
57
+ module FiberedMysql2ConnectionFactory
58
+ def fibered_mysql2_connection(raw_config)
59
+ config = raw_config.symbolize_keys
60
+
61
+ config[:username] = 'root' if config[:username].nil?
62
+ config[:flags] = Mysql2::Client::FOUND_ROWS if Mysql2::Client.const_defined?(:FOUND_ROWS)
63
+
64
+ client =
65
+ begin
66
+ Mysql2::EM::Client.new(config)
67
+ rescue Mysql2::Error => error
68
+ if error.message.include?("Unknown database")
69
+ raise ActiveRecord::NoDatabaseError.new(error.message, error)
70
+ else
71
+ raise
72
+ end
73
+ end
74
+
75
+ options = [config[:host], config[:username], config[:password], config[:database], config[:port], config[:socket], 0]
76
+ FiberedMysql2Adapter.new(client, logger, options, config)
77
+ end
78
+ end
79
+ end
80
+
81
+ ActiveRecord::Base.class.prepend(FiberedMysql2::FiberedMysql2ConnectionFactory)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FiberedMysql2
4
- VERSION = "0.1.0.pre.2"
4
+ VERSION = "0.1.1"
5
5
  end
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.0.pre.2
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
- - Octothorp
7
+ - Invoca Development
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-07 00:00:00.000000000 Z
11
+ date: 2021-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: em-synchrony
@@ -46,7 +46,7 @@ dependencies:
46
46
  version: '7'
47
47
  description:
48
48
  email:
49
- - octothorp@invoca.com
49
+ - development@invoca.com
50
50
  executables: []
51
51
  extensions: []
52
52
  extra_rdoc_files: []
@@ -66,8 +66,11 @@ files:
66
66
  - gemfiles/rails_4.gemfile
67
67
  - gemfiles/rails_5.gemfile
68
68
  - gemfiles/rails_6.gemfile
69
+ - lib/active_record/connection_adapters/fibered_mysql2_adapter.rb
69
70
  - lib/fibered_mysql2.rb
70
- - lib/fibered_mysql2/fibered_mysql2_adapter.rb
71
+ - lib/fibered_mysql2/fibered_database_connection_pool.rb
72
+ - lib/fibered_mysql2/fibered_mutex_with_waiter_priority.rb
73
+ - lib/fibered_mysql2/fibered_mysql2_connection_factory.rb
71
74
  - lib/fibered_mysql2/version.rb
72
75
  homepage: https://github.com/Invoca/fibered_mysql2
73
76
  licenses: []
@@ -85,9 +88,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
88
  version: '0'
86
89
  required_rubygems_version: !ruby/object:Gem::Requirement
87
90
  requirements:
88
- - - ">"
91
+ - - ">="
89
92
  - !ruby/object:Gem::Version
90
- version: 1.3.1
93
+ version: '0'
91
94
  requirements: []
92
95
  rubygems_version: 3.0.1
93
96
  signing_key: