dogpile.cache icon indicating copy to clipboard operation
dogpile.cache copied to clipboard

unable to detect when memcached isn't running

Open sqlalchemy-bot opened this issue 10 years ago • 8 comments

Migrated issue, originally created by David Kavanagh ()

I've configured dogpile.cache to use memcached and the python-memcached package. I need to be able to detect when there is a failure to communicate to the memcached server. In python-memcached'd memcached.py file, the _set(..) method around line 814, a 0 is returned if the server is down. The set method returns a non-zero value on success. In the dogpile.cache.backends.memcached.py file around line 159, the set(..) method does nothing with the return value, as does the dogpile.cache.region.py file in the set(..) method. That makes it impossible to know and deal with a memcached set failure. I'd be happy to submit a patch, but wanted some feedback first. Perhaps raising a DogpileCacheException from the backend would be better.

sqlalchemy-bot avatar Jul 01 '14 21:07 sqlalchemy-bot

David Kavanagh () wrote:

I've forked the projected and setup a BackendCacheException(DogpileCacheException) class. I raise that in the backends.memcached.py for set and delete when a zero is returned. This works well for the case I had in mind. I find that it also causes the @cache_on_arguments() decorator to throw an exception if the cache isn't there, so it isn't as hands-off as before. I'm toying with having the decorator swallow the exception so that it is less intrusive. However, it could be nice to have a way to tell if the cache isn't functioning... open to ideas.

sqlalchemy-bot avatar Jul 02 '14 13:07 sqlalchemy-bot

David Kavanagh () wrote:

https://bitbucket.org/dkavanagh_/dogpile.cache/branch/error-handling

sqlalchemy-bot avatar Jul 02 '14 13:07 sqlalchemy-bot

Michael Bayer (zzzeek) wrote:

pylibmc should be raising an error for any cache not available case, so this wouldn't change much. I'm not understanding why @cache_on_arguments throwing an exception is a bad thing, assuming we mean when the decorated function is actually called. for seamless transition I'd support the python-memcached backend raising if a config flag is set.

sqlalchemy-bot avatar Jul 02 '14 14:07 sqlalchemy-bot

Michael Bayer (zzzeek) wrote:

pylibmc raises errors for all failures

sqlalchemy-bot avatar Jul 02 '14 14:07 sqlalchemy-bot

David Kavanagh () wrote:

Thanks, Mike. I'll do some testing with pylibmc and may simply use that instead.

sqlalchemy-bot avatar Jul 02 '14 14:07 sqlalchemy-bot

David Kavanagh () wrote:

wow, pylibmc might be a real PITA to use in production since we distribute our app as an RPM.

sqlalchemy-bot avatar Jul 03 '14 02:07 sqlalchemy-bot

David Kavanagh () wrote:

got back to looking at this. Build pylibmc and get the ConnectionError when memcached is stopped. It looks like the decorated create method fails fast (probably when checking for the key in the cache), so if I re-structure my code a little, I can fall-back to simply calling the create method and returning the value. I'll have to have the decorated method call another method.. layers and layers!

sqlalchemy-bot avatar Jul 08 '14 17:07 sqlalchemy-bot

Changes by Michael Bayer (zzzeek):

  • removed labels: high priority
  • added labels: low priority

sqlalchemy-bot avatar Nov 15 '14 04:11 sqlalchemy-bot