Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ jobs:
ruby: [3.1, 3.2, 3.3]
gemfile:
- Gemfile
- gemfiles/rails_6_0.gemfile
- gemfiles/rails_6_1.gemfile
- gemfiles/rails_7_0.gemfile
env:
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

require "appraisal/matrix"

appraisal_matrix(rails: "~> 6.0")
appraisal_matrix(rails: [">= 6.1", "< 7.1"])
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@ Inspired by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

Note: this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.3.0] - 2024-10-23
### Added
- Support for Rails 7.0.

### Removed
- Removed support for Rails 6.0 and Rails 5.

### Changed
- Clean up FiberedMysql2ConnectionFactory#fibered_mysql2_connection to better match Mysql2Adapter behavior.
- Change FiberedMysql2::FiberedDatabaseConnectionPool#initialize to match ActiveRecord::ConnectionAdapters::ConnectionPool#initialize arguments.

## [0.2.1] - 2024-08-19
### Fixed
- Fixed bugs in Rails 6.1.
- Fixed bugs in Rails 6.1

## [0.2.0] - 2023-01-12
### Added
Expand Down
139 changes: 69 additions & 70 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,72 +1,78 @@
PATH
remote: .
specs:
fibered_mysql2 (0.2.1)
fibered_mysql2 (0.3.0)
em-synchrony (~> 1.0)
rails (>= 5.2, < 7)
rails (>= 6.1, < 7.1)

GEM
remote: https://rubygems.org/
specs:
actioncable (6.1.7.8)
actionpack (= 6.1.7.8)
activesupport (= 6.1.7.8)
actioncable (7.0.8.5)
actionpack (= 7.0.8.5)
activesupport (= 7.0.8.5)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (6.1.7.8)
actionpack (= 6.1.7.8)
activejob (= 6.1.7.8)
activerecord (= 6.1.7.8)
activestorage (= 6.1.7.8)
activesupport (= 6.1.7.8)
actionmailbox (7.0.8.5)
actionpack (= 7.0.8.5)
activejob (= 7.0.8.5)
activerecord (= 7.0.8.5)
activestorage (= 7.0.8.5)
activesupport (= 7.0.8.5)
mail (>= 2.7.1)
actionmailer (6.1.7.8)
actionpack (= 6.1.7.8)
actionview (= 6.1.7.8)
activejob (= 6.1.7.8)
activesupport (= 6.1.7.8)
net-imap
net-pop
net-smtp
actionmailer (7.0.8.5)
actionpack (= 7.0.8.5)
actionview (= 7.0.8.5)
activejob (= 7.0.8.5)
activesupport (= 7.0.8.5)
mail (~> 2.5, >= 2.5.4)
net-imap
net-pop
net-smtp
rails-dom-testing (~> 2.0)
actionpack (6.1.7.8)
actionview (= 6.1.7.8)
activesupport (= 6.1.7.8)
rack (~> 2.0, >= 2.0.9)
actionpack (7.0.8.5)
actionview (= 7.0.8.5)
activesupport (= 7.0.8.5)
rack (~> 2.0, >= 2.2.4)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (6.1.7.8)
actionpack (= 6.1.7.8)
activerecord (= 6.1.7.8)
activestorage (= 6.1.7.8)
activesupport (= 6.1.7.8)
actiontext (7.0.8.5)
actionpack (= 7.0.8.5)
activerecord (= 7.0.8.5)
activestorage (= 7.0.8.5)
activesupport (= 7.0.8.5)
globalid (>= 0.6.0)
nokogiri (>= 1.8.5)
actionview (6.1.7.8)
activesupport (= 6.1.7.8)
actionview (7.0.8.5)
activesupport (= 7.0.8.5)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (6.1.7.8)
activesupport (= 6.1.7.8)
activejob (7.0.8.5)
activesupport (= 7.0.8.5)
globalid (>= 0.3.6)
activemodel (6.1.7.8)
activesupport (= 6.1.7.8)
activerecord (6.1.7.8)
activemodel (= 6.1.7.8)
activesupport (= 6.1.7.8)
activestorage (6.1.7.8)
actionpack (= 6.1.7.8)
activejob (= 6.1.7.8)
activerecord (= 6.1.7.8)
activesupport (= 6.1.7.8)
activemodel (7.0.8.5)
activesupport (= 7.0.8.5)
activerecord (7.0.8.5)
activemodel (= 7.0.8.5)
activesupport (= 7.0.8.5)
activestorage (7.0.8.5)
actionpack (= 7.0.8.5)
activejob (= 7.0.8.5)
activerecord (= 7.0.8.5)
activesupport (= 7.0.8.5)
marcel (~> 1.0)
mini_mime (>= 1.1.0)
activesupport (6.1.7.8)
activesupport (7.0.8.5)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
appraisal (2.5.0)
bundler
rake
Expand Down Expand Up @@ -94,7 +100,7 @@ GEM
eventmachine (1.2.7)
globalid (1.2.1)
activesupport (>= 6.1)
i18n (1.14.5)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
json (2.7.2)
loofah (2.22.0)
Expand All @@ -111,7 +117,7 @@ GEM
mini_portile2 (2.8.7)
minitest (5.25.1)
mysql2 (0.5.6)
net-imap (0.4.14)
net-imap (0.5.0)
date
net-protocol
net-pop (0.1.2)
Expand All @@ -131,37 +137,37 @@ GEM
byebug (~> 11.0)
pry (>= 0.13, < 0.15)
racc (1.8.1)
rack (2.2.9)
rack (2.2.10)
rack-test (2.1.0)
rack (>= 1.3)
rails (6.1.7.8)
actioncable (= 6.1.7.8)
actionmailbox (= 6.1.7.8)
actionmailer (= 6.1.7.8)
actionpack (= 6.1.7.8)
actiontext (= 6.1.7.8)
actionview (= 6.1.7.8)
activejob (= 6.1.7.8)
activemodel (= 6.1.7.8)
activerecord (= 6.1.7.8)
activestorage (= 6.1.7.8)
activesupport (= 6.1.7.8)
rails (7.0.8.5)
actioncable (= 7.0.8.5)
actionmailbox (= 7.0.8.5)
actionmailer (= 7.0.8.5)
actionpack (= 7.0.8.5)
actiontext (= 7.0.8.5)
actionview (= 7.0.8.5)
activejob (= 7.0.8.5)
activemodel (= 7.0.8.5)
activerecord (= 7.0.8.5)
activestorage (= 7.0.8.5)
activesupport (= 7.0.8.5)
bundler (>= 1.15.0)
railties (= 6.1.7.8)
sprockets-rails (>= 2.0.0)
railties (= 7.0.8.5)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
rails-html-sanitizer (1.6.0)
loofah (~> 2.21)
nokogiri (~> 1.14)
railties (6.1.7.8)
actionpack (= 6.1.7.8)
activesupport (= 6.1.7.8)
railties (7.0.8.5)
actionpack (= 7.0.8.5)
activesupport (= 7.0.8.5)
method_source
rake (>= 12.2)
thor (~> 1.0)
zeitwerk (~> 2.5)
rake (13.2.1)
rspec (3.13.0)
rspec-core (~> 3.13.0)
Expand All @@ -181,17 +187,10 @@ GEM
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
sprockets-rails (3.5.2)
actionpack (>= 6.1)
activesupport (>= 6.1)
sprockets (>= 3.0.0)
sync (0.5.0)
term-ansicolor (1.11.2)
tins (~> 1.0)
thor (1.3.1)
thor (1.3.2)
timeout (0.4.1)
tins (1.33.0)
bigdecimal
Expand All @@ -201,7 +200,7 @@ GEM
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
zeitwerk (2.6.17)
zeitwerk (2.6.18)

PLATFORMS
ruby
Expand Down
2 changes: 1 addition & 1 deletion fibered_mysql2.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

spec.add_dependency 'em-synchrony', '~> 1.0'
spec.add_dependency 'rails', '>= 5.2', '< 7'
spec.add_dependency 'rails', '>= 6.1', '< 7.1'
end
2 changes: 1 addition & 1 deletion gemfiles/rails_6_0.gemfile → gemfiles/rails_7_0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ gem "pry"
gem "pry-byebug"
gem "rake"
gem "rspec"
gem "rails", "~> 6.0.0"
gem "rails", "~> 7.0.0"

gemspec path: "../"
32 changes: 17 additions & 15 deletions lib/active_record/connection_adapters/fibered_mysql2_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@
require 'active_record/connection_adapters/em_mysql2_adapter'

module FiberedMysql2
module FiberedMysql2Adapter_4_2
def lease
synchronize do
unless in_use?
@owner = Fiber.current
end
end
end
end

module FiberedMysql2Adapter_5_2
def lease
if in_use?
Expand Down Expand Up @@ -72,11 +62,23 @@ def owner_fiber
end

class FiberedMysql2Adapter < ::ActiveRecord::ConnectionAdapters::EMMysql2Adapter
case ::Rails::VERSION::MAJOR
when 4
include FiberedMysql2Adapter_4_2
when 5, 6
include FiberedMysql2Adapter_5_2
include FiberedMysql2Adapter_5_2

class << self
# Copied from Mysql2Adapter, except with the EM Mysql2 client
def new_client(config)
Mysql2::EM::Client.new(config)
rescue Mysql2::Error => error
if error.error_number == ConnectionAdapters::Mysql2Adapter::ER_BAD_DB_ERROR
raise ActiveRecord::NoDatabaseError.db_error(config[:database])
elsif error.error_number == ConnectionAdapters::Mysql2Adapter::ER_ACCESS_DENIED_ERROR
raise ActiveRecord::DatabaseConnectionError.username_error(config[:username])
elsif [ConnectionAdapters::Mysql2Adapter::ER_CONN_HOST_ERROR, ConnectionAdapters::Mysql2Adapter::ER_UNKNOWN_HOST_ERROR].include?(error.error_number)
raise ActiveRecord::DatabaseConnectionError.hostname_error(config[:host])
else
raise ActiveRecord::ConnectionNotEstablished, error.message
end
end
end

def initialize(*args)
Expand Down
40 changes: 5 additions & 35 deletions lib/fibered_mysql2/fibered_database_connection_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,25 +186,6 @@ def mon_exit_for_cond
module FiberedDatabaseConnectionPool
include FiberedMonitorMixin

module Adapter_4_2
def cached_connections
@reserved_connections
end

def current_connection_id
ActiveRecord::Base.connection_id ||= Fiber.current.object_id
end

def checkout
begin
reap_connections
rescue => ex
ActiveRecord::Base.logger.error("Exception occurred while executing reap_connections: #{ex}")
end
super
end
end

module Adapter_5_2
def cached_connections
@thread_cached_conns
Expand All @@ -229,27 +210,16 @@ def release_connection(owner_thread = Fiber.current)
end
end
end
include Adapter_5_2

case Rails::VERSION::MAJOR
when 4
include Adapter_4_2
when 5, 6
include Adapter_5_2
end

def initialize(connection_spec, *args, **keyword_args)
if ActiveRecord.gem_version < "6.1"
connection_spec.config[:reaping_frequency] and raise "reaping_frequency is not supported (the ActiveRecord Reaper is thread-based)"
connection_spec.config[:reaping_frequency] = nil # starting in Rails 5, this defaults to 60 if not explicitly set
elsif connection_spec.db_config.reaping_frequency
connection_spec.db_config.reaping_frequency > 0 and raise "reaping_frequency is not supported (the ActiveRecord Reaper is thread-based)"
def initialize(pool_config)
if pool_config.db_config.reaping_frequency
pool_config.db_config.reaping_frequency > 0 and raise "reaping_frequency is not supported (the ActiveRecord Reaper is thread-based)"
end

super(connection_spec, *args, **keyword_args)
super(pool_config)

@reaper = nil # no need to keep a reference to this since it does nothing in this sub-class

# note that @reserved_connections is a ThreadSafe::Cache which is overkill in a fibered world, but harmless
end

def connection
Expand Down
Loading
Loading