-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved Postgresql compatibility and failover support #87
Conversation
Hey @Drakula2k, thanks for putting the time into this. Let's work on getting it green. I've done an initial review and I'm on board with the desired results. I'll do a more detailed review when it's ready to ship. |
Thanks, I'm working on build. |
…onnection errors, specs fixes
Done. |
Would it be helpful if I tested this in our staging/production systems? I'm hoping to continue our upgrade from very old Makara (we put the upgrade on hold a while ago due to time constraints), and it looks like we would want these fixes before pushing a new version to production. |
@sax I'm currently using it on production, but on a small microservice which is very simple and doesn't cover all of use cases. I'm planning to use it on a bigger project in future, so I'd appreciate any feedback. |
It would be beneficial. I just now queued up a story to apply it to our staging environment, and potentially a subset of our production environment as a test. I apologize for being so unresponsive. |
Awesome! I actually have time allocated this week for working on our woefully ignored infrastructure upgrades, so I hope to test this tomorrow. |
When I run rake db:create:all I get an error, I think related to the change of ConnectionWrapper away from being a SimpleDelegator. The first time it call This is in Rails 3.2.21.
|
In a pry session, I find the following:
Does it make any sense why this would be happening? You might not run into this problem in Rails 4, as all of the methods in the rake file were pushed into objects. |
Ok, I get what happens. In Rails 3, the methods defined in databases.rake get defined on Object. When ConnectionWrapper was a delegator, everything got passed down to the wrapped database adapter, so there were no problems. Relying entirely on method_missing means that the methods defined on Object get used in preference to the wrapped connection. I'll provide a gist to fix this for Rails 3, but don't think it's worth fixing in Makara. |
Here's a way of fixing this problem in a Rails 3 app. |
Thanks, I'll try to fix it on this week. |
I've done some quick testing of this in our staging infrastructure, and it appears to work well. I ran into some issues with |
The problems with |
I found a workaround, check this out. |
Not sure what's up with 1.9.2 builds, and 1.8.7 doesn't support .public_send. I think 1.8.7 support should be dropped, even the Ruby team doesn't support it (along with 1.9.2 and 1.9.3). |
I'm not sure if this will solve the root problem, but I also don't think you necessarily need to fix it. Rails 3 will only receive security updates from here on out, and this is not a problem in Rails 4. We're only running into it because we're trying to upgrade Makara in order to upgrade out app to Rails 4. |
I'm in favor of dropping < 2.0 support. |
SimpleDelegator prioritizes public methods too, so this fix is not only for this case. |
I integrated it to a bigger 4.2 project, works pretty well. |
@mnelson is this project still maintained? |
Hi @Drakula2k - I realize it's been quite a long time with this PR. I'm starting off the new year with a resolution of managing this project and adding a few things. What's the current state of this code? Are you using it in production? |
target.respond_to?(m, true) ? target.__send__(m, *args, &block) : super(m, *args, &block) | ||
ensure | ||
$@.delete_if {|t| %r"\A#{Regexp.quote(__FILE__)}:#{__LINE__-2}:"o =~ t} if $@ | ||
if _makara_connection.respond_to?(m) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels odd to me in this method to be using the _makara_connection
method instead of the @connection
variable. If i'm reading it right, you could get a different object back each time. think that's a problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm, i guess not. it's only doing it if it's non-nil.\
@bleonard we have been using code from this pull request in our production site since the end of Aug 2015. Apart from our issues described above (where we have to work around the Rails 3 |
Awesome. Thanks @sax |
I'm using it on production as well. The only issue I noticed: when already connected host is going down/non-reachable, postgres adapter gives very long timeout (30 or 60 sec) before raising a connection exception, which is not configurable and should be fixed somewhere inside adapter's C code. I already tried, but no luck yet, will try to fix it again later. |
yes, we've something like that, too. then it doesn't get blacklisted. i believe it's a problem if the timeout time there is greater than the unicorn timeout or something else upstream. it's one of the things i want to look into. my current hope it to figure out where to set it on the mysql adapter to not be so long. |
ok, i'm going to merge this and test it out on our staging / prod. |
Improved Postgresql compatibility and failover support
Following up with noted timeout issue here: #102 |
Fixes #27.
As far as I can see, it has been fixed in #35, but then these changes was removed in #52 because of #50 SystemStackError and other issues.
So this PR is doing almost same the same stuff as #35, but a bit more deeply and also includes few more bugfixes (including a fix for #50).
It allows the app to start and run with any set of working/down DB servers and raises errors only on write queries when master is down and on all queries when all servers are down.