django-balancer icon indicating copy to clipboard operation
django-balancer copied to clipboard

Take DB downtime into account

Open bkonkle opened this issue 14 years ago • 3 comments

When a database in the pool is down, temporarily remove it from the pool but periodically re-check the connection. If it comes back up, add the database back to the pool.

bkonkle avatar Oct 25 '10 21:10 bkonkle

It appears that psycopg2.OperationalError (the exception raised when the database cannot be connected to) is not caught by the try...except block inside django.core.handlers.base.BaseHandler.get_response, so I'm not able to use django.core.signals.got_request_exception to take that database out of the pool. I'm trying to find another way, but it looks like I may be going down the wrong path. I'm open to suggestions on other ways to handle this.

bkonkle avatar Nov 19 '10 18:11 bkonkle

I could probably create a new database backend that subclasses DatabaseWrapper and wraps ._cursor() in a try...except block. I'd have to make a new backend for every existing backend, though, and that would be messy. I want something more elegant. Back to the drawing board...

bkonkle avatar Nov 19 '10 19:11 bkonkle

Wrapping the cursor (or even ... you could monkeypatch it) is probably the easiest way.

I have looked at this issue a couple of months ago when writing django-statsd (http://pypi.python.org/pypi/django-statsd/) and it seemed that monkeypatching is the best way to go here.

But if you know any good way to do it, please let me know.

wolph avatar Dec 01 '11 01:12 wolph