Comments (10)
We use Unicorn and a failure standard configuration I think, which I shared below. I am sure it is just a MonkeyPatch I am missing or something.
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: *****
password: *****
host: 127.0.0.1
port: 3306
development:
<<: *default
database: chewy_development
development_slave:
<<: *default
database: chewy_development_secondary
What is the downside of doing something like this instead?
class ReportObject < ApplicationRecord
self.table_name = 'some_table'
establish_connection(:development_slave)
end
ReportObject.connection.exec('SELECT COUNT(*) FROM some_table')
or
def on_slave(&block)
databases = YAML.load(File.read('config/database.yml'))
connection = ActiveRecord::Base.establish_connection(databases["#{Rails.env}_slave"])
result = yield
connection.disconnect!
result
end
from standby.
cc @asanghi any insights? I haven't gotten around to upgrading yet.
from standby.
It might also be be good to have documentation around using raw SQL if it doesn't work like this:
result = Slavery.on_slave{ ActiveRecord::Base.connection.execute('SELECT * FROM users') }
from standby.
We have this in production and see no problems. I can investigate though. @caseyprovost can you post your database.yml? Your original example is pretty standard and should work.
from standby.
The only case I can think of is that you are running a slave query from multiple threads at the same time, creating a race condition initializing Slavery.slave_connections
.
Do you have something related? (e.g. config/initializers
, before|after_fork
in config/puma.rb
, etc.)
from standby.
What is the downside of doing something like this instead?
You can do whatever you want, but this is an issue for the Slavery gem and don't treat us like your free consultant.
If necessary, reopen with answer to my questions please.
from standby.
@kenn I did answer the things asked for including posting my database.yml and sharing we are using unicorn and not Puma. I also cannot find any other evidence of forking.
I was also not attempting to be unfair or abuse your time, as an OS contributor myself I try to be aware and protective of that. My question was more accurately what is the advantage of Slavery to the approaches I mentioned? I am honestly curious.
Hopefully this was helpful.
from standby.
You said
I am sure it is just a MonkeyPatch I am missing or something.
but didn't post that.
The other question is unrelated to the original problem and should go to a separate issue. To me the former looks ok but the latter is horrible - too much overhead. And by removing the overhead you'll basically end up creating the same thing as this gem. Remember, what this gem does is VERY MINIMAL.
from standby.
For the record the problem is the ActiveUUID gem. This library and that result in an infinite recursive loop.
from standby.
I just installed activeuuid but it doesn't happen. Would appreciate if you can make a repro with a fresh new Rails setup.
from standby.
Related Issues (13)
- Query on slave returning wrong results in test HOT 16
- Why Slavery is not reading from the slave db. HOT 4
- Is there a way to connect to multiple slaves? HOT 2
- Active Record 4.0.0 error raised when calling to establish_connection: Anonymous class is not allowed HOT 2
- Consider changes to master/slave terminology and project name HOT 23
- How disable Slavery for single model? HOT 3
- Best way to handle fallback HOT 1
- ActiveRecord relation inverse_of broken HOT 1
- `Standby#on_standby` can block unnecessarily
- ActiveRecord::Base.configurations error after rails 7 upgrade HOT 5
- QUERY Cache HOT 1
- Specs Broken? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from standby.