schoefmann / multi_db Goto Github PK
View Code? Open in Web Editor NEWConnection proxy for ActiveRecord for single master / multiple slave database deployments
Home Page: http://github.com/schoefmax/multi_db
License: MIT License
Connection proxy for ActiveRecord for single master / multiple slave database deployments
Home Page: http://github.com/schoefmax/multi_db
License: MIT License
I have a multi-master setup with MariaDB Galera.
multi_db works great when I'm distributing reads to multiple masters when I just declare them as slaves.
Can multi-db support multiple masters so I can write on multi-master replicated cluster?
Just upgraded multi_db and started running into this infinite loop with our Observers when run via Passenger:
SystemStackError (stack level too deep):
multi_db (0.3.1) lib/multi_db/active_record_extensions.rb:48:in connection' multi_db (0.3.1) lib/multi_db/observer_extensions.rb:10:in
update_without_masterdb'
multi_db (0.3.1) lib/multi_db/observer_extensions.rb:11:in update_without_masterdb' multi_db (0.3.1) lib/multi_db/connection_proxy.rb:123:in
with_master'
multi_db (0.3.1) lib/multi_db/observer_extensions.rb:10:in update_without_masterdb' multi_db (0.3.1) lib/multi_db/observer_extensions.rb:11:in
update_without_masterdb'
multi_db (0.3.1) lib/multi_db/connection_proxy.rb:123:in with_master' multi_db (0.3.1) lib/multi_db/observer_extensions.rb:10:in
update_without_masterdb'
multi_db (0.3.1) lib/multi_db/observer_extensions.rb:11:in update_without_masterdb' multi_db (0.3.1) lib/multi_db/connection_proxy.rb:123:in
with_master'
...
lots of this
...
multi_db (0.3.1) lib/multi_db/observer_extensions.rb:11:in update_without_masterdb' multi_db (0.3.1) lib/multi_db/connection_proxy.rb:123:in
with_master'
multi_db (0.3.1) lib/multi_db/observer_extensions.rb:10:in update_without_masterdb' multi_db (0.3.1) lib/multi_db/observer_extensions.rb:11:in
update_without_masterdb'
multi_db (0.3.1) lib/multi_db/connection_proxy.rb:123:in with_master' multi_db (0.3.1) lib/multi_db/observer_extensions.rb:10:in
update_without_masterdb'
multi_db (0.3.1) lib/multi_db/observer_extensions.rb:11:in update' multi_db (0.3.1) lib/multi_db/connection_proxy.rb:123:in
with_master'
multi_db (0.3.1) lib/multi_db/observer_extensions.rb:10:in update' activerecord (3.2.6) lib/active_record/observer.rb:114:in
_notify_author_observer_for_after_save'
activesupport (3.2.6) lib/active_support/callbacks.rb:405:in _run__1711496803__save__4__callbacks' activesupport (3.2.6) lib/active_support/callbacks.rb:405:in
send'
If I take away the Passenger extension (which has been working fine for over a year now) the issue goes away, but then so does multi_db. Possibly relevant is that we're in the process of upgrading Rails from 3.0 to 3.2, so multi_db isn't the only new code in the mix.
Is there something special we need to be taking into account now when using Observers with Passenger?
I've recently installed the multi_db gem on my rails 2.3.10 app in order to use a MySql master/slave replication.
since installing the gem, every time I use transactions in my code , e.g.:
MyModel.connection.transaction do
...some code...
end
I get an exception: NoMethodError undefined method 'assert_valid_keys' for true:TrueClass
any ideas on how to use multi_db with transactions?
'reconnect_master!' called in a transaction if 'transaction' is called with '@REconnect' flag set.
'transaction' should check '@REconnect' flag before 'BEGIN' is issued.
Hello,
I found a conflict between multi_db and asf-soap-adapter which is a gem to use the SalesForce API.
The problem is that asf-soap-adapter use the db.yml file to setup an adapter, like this :
salesforce-default-realm:
adapter: activesalesforce
url: https://www.salesforce.com
username: XXX
password: XXX
api_version: 20.0
Then the usage is like that : Salesforce::Lead.new
But when using multi_db, it seems multi_db try to handle the connection and don't let let asf-soap-adapter do it...
If someone have an idea of how to fix this it would be appreciated.
Regards.
Now that gems are no longer built on github, would be nice to see this gem added to gemcutter.org
We've been using MultiDb for a long time with Ruby 1.8.6 and Rails 2.3.2. We're currently upgrading to Rails 2.3.11 and Ruby 1.9.2, and we're seeing some kind of horrible error out of the gem:
ArgumentError (wrong number of arguments (1 for 0)):
/usr/lib/ruby/gems/1.9.1/gems/schoefmax-tlattr_accessors-0.0.3/lib/tlattr_accessors.rb:55:in block in current=' app/models/user_setting.rb:2:in
class:UserSetting'
app/models/user_setting.rb:1:in `<top (required)>'
Has anyone else seen these errors? Or has anyone run successfully with ruby 1.9.2?
Hi,
I don't know how to make multi_db work with Heroku since Heroku doesn't use database.yml.
Do you have any plan to make it work with Heroku?
Thanks,
I try use this code below in my controller
around_filter(:only => [:create,:update]) { |c,a| ActiveRecord::Base.connection_proxy.with_master { a.call } }
and receive this error:
NoMethodError (undefined method `conection_proxy' for ActiveRecord::Base:Class):
I need change conection of 2 actions in my controller for read just at master. How I do?
I think commit 863e29b1ff7cdb7e283d Breaks rails 2.3 compatibility.
I'm using rails 2.3.8 and multidb 0.3.0 from rubygems.org
Here my application console init log :
```undefined methodcolumns' for class
MultiDb::ConnectionProxy'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/core_ext/module/aliasing.rb:33:in`alias_method'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/core_ext/module/aliasing.rb:33:in `alias_method_chain'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/connection_adapters/abstract/query_cache.rb:7:in`included'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/connection_adapters/abstract/query_cache.rb:6:in `class_eval'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/connection_adapters/abstract/query_cache.rb:6:in`included'
/home/sabre/.gem/ruby/1.8/gems/multi_db-0.3.0/lib/multi_db/connection_proxy.rb:5:in `include'
/home/sabre/.gem/ruby/1.8/gems/multi_db-0.3.0/lib/multi_db/connection_proxy.rb:5
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in`gem_original_require'
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:158:in`require'
/home/sabre/.gem/ruby/1.8/gems/multi_db-0.3.0/lib/multi_db.rb:6
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
Can multi_db support the following scenario?
In this example multi_db works just fine for the user model. However, multi_db either ignores or overrides the establish_connection call made in the Team model that is trying to use a connection to a different database. This results in a MySQL error similar to "Mysql::Error: Table 'production.teams' doesn't exist" because teams is not defined in the database named 'production' but rather in the database named 'third_party_db'.
# initiliazers/connection_proxy.rb
MultiDb::ConnectionProxy.setup!
# app/models/user.rb
class User < ActiveRecord::Base
# typical user model
end
# app/models/team.rb
class Team < ThirdPartyDataProvider
end
# app/models/third_party_data_provider.rb
class ThirdPartyDataProvider < ActiveRecord::Base
establish_connection "third_party_db"
end
# config/database.yml
production:
adapter: mysql
database: production
username: root
password:
host: 127.0.0.1
production_slave:
adapter: mysql
database: production
username: root
password:
host: 127.0.0.2
third_party_db:
adapter: mysql
database: third_party
username: root
password:
host: 127.0.0.1
I'm using MultiDB on a Master and 2 Slaves, and I still see quite a bit of "select" reads happening on the Master... ie: "select * from xxxxxx".
In the README, I see that this might not be the correct behaviour?
"It sends everything except "select โฆ" queries to the master, instead of sending only specific things to the master and anything "else" to the slave. "
If not, let me know and I'll definitely start looking at the issue. Thanks!
iv'e found something interesting, ever since i've installed multi_db
MyModel.connection.transaction do
test = 1+2
end
return the following exception (in most cases): NoMethodError undefined method 'assert_valid_keys' for true:TrueClass
but if i run:
MyModel.connection.transaction({}) do
test = 1+2
end
everything runs smoothly.
my gut filling tells me that multi_db (which is based on masochism gem) doesnt "play nice" with one of the other gems im using ( maybe: deadlock_retry or ar-extensions).
any ideas?
Hello,
is it possible to use multi_db with rails 2.3.8 and ruby 1.8.7, ive installed the gem and it installed new version of activemodel/activesupport which messed a few things in my app, any ideas?
I have an issue with a Rails 2.3.2 app in which I'm employing the ActiveRecord session store and multi_db seems to be letting it split anyways. I even tried explicitly excluding it with:
MultiDb::ConnectionProxy.master_models = ['CGI::Session::ActiveRecordStore::Session']
To no avail, sessions keep splitting and I get the somewhat expected erratic behavior.
Any suggestions as to how I might get a better view of what is happening?
im getting a lot of "DEPRECATION WARNING: Kernel#returning has been deprecated in favor of Object#tap." on my log after installing multi_db, any ideas?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.