Open ajinkyapisal opened 6 years ago
After looking into the code, we saw that if we use mysql2_adapter
then we did not see any connection pool issue. As we are using JRuby, so had a look at the JDBC Mysql adapter code and saw that it differs from the mysql2 adapter (it has the schema based adapter). We copied Mysql2SchemaAdapter
to JDBCMysqlSchemaAdapter
and after that, it worked.
I have created a branch for it.
https://github.com/ajinkyapisal/apartment/commit/ee9fad934494c08f20e7712a6d88be413046b17b
@mikecmpbll can you please check above fix and let us know if what we did is correct fix or not? Thanks
Update1: It works well when using the application but when creating new tenant. Apartment creates the database with no scehma_migrations
table. I found out that it looks for default database schema_migrations when doing that hence it never runs any migration on a new tenant.
It looks my copy-pasting of Mysql2SchemaAdapter
to JDBCMysqlSchemaAdapter
was incorrect.
Final Update: Fixed main issue and above issue with migration using below code
require "apartment/adapters/abstract_jdbc_adapter"
module Apartment
module Tenant
def self.jdbc_mysql_adapter(config)
adapter = Adapters::JDBCMysqlAdapter.new(config)
adapter.process_excluded_models
adapter
end
end
module Adapters
class JDBCMysqlAdapter < AbstractJDBCAdapter
def initialize(config)
super
Apartment.connection_handler = ActiveRecord::ConnectionAdapters::ConnectionHandler.new
reset
end
def reset_on_connection_exception?
true
end
end
end
end
for some reason, I had to call adapter.process_excluded_models
even though it's already called in Apartment::Tenant. If I dont' do that then it looks for Customer
(excluded model) in current database instead of default database
Summary: This fix did not work : https://github.com/ajinkyapisal/apartment/commit/ee9fad934494c08f20e7712a6d88be413046b17b This fix did work : https://github.com/ajinkyapisal/apartment/commit/91c892538cb0d1ba1bcee7aeee41455fcdfa7f19
hi @ajinkyapisal , before I take a look at your code can you tell me what apartment configuration you're using?
edit: whups, didn't spot the sample app, perfect thx ;)
Steps to reproduce
testapp_1
rails runner sample.rb
Expected behavior
All messages are processed successfully by Sidekiq
Actual behavior
Messages are not processed as apartment gives TenantNotFound, Connection Pool errors Error log: https://github.com/ajinkyapisal/testapp/blob/master/sidekiq_error.log
System configuration
Database: (Tell us what database and its version you use.) mysql Ver 14.14 Distrib 5.7.20, for osx10.13 (x86_64) using EditLine wrapper
Apartment version: 2.0.0
Apartment config (in
config/initializers/apartment.rb
or so): config.excluded_models = %w{ Tenant } config.tenant_names = lambda { Tenant.pluck :db_name }use_schemas
: (true
orfalse
) trueRails (or ActiveRecord) version: Rails 4.2.10
Ruby version: jruby 9.1.14.0 (2.3.3) 2017-11-08 2176f24 OpenJDK 64-Bit Server VM 24.151-b01 on 1.7.0_151-b01 [linux-x86_64]