memcached: use retrying rather than sleeping

That should allow better handling of retrying, sleep delays, etc.

Change-Id: I7658b4d5bacb0aef84a8c377a7e487327011b7ee
This commit is contained in:
Julien Danjou 2014-06-23 18:13:58 +02:00
parent 135a523a94
commit f438de0fdf
1 changed files with 11 additions and 13 deletions

View File

@ -17,7 +17,6 @@
# under the License.
import collections
import time
import msgpack
import pymemcache.client
@ -50,19 +49,18 @@ class MemcachedLock(locking.Lock):
self.name = self._LOCK_PREFIX + name
self.timeout = timeout
@retry
def acquire(self, blocking=True):
while True:
if self.coord.client.add(
self.name,
self.coord._member_id,
expire=self.timeout,
noreply=False):
self.coord._acquired_locks.append(self)
return True
if not blocking:
return False
# NOTE(jd) Configurable? :/
time.sleep(0.11)
if self.coord.client.add(
self.name,
self.coord._member_id,
expire=self.timeout,
noreply=False):
self.coord._acquired_locks.append(self)
return True
if not blocking:
return False
raise Retry
def release(self):
self.coord._acquired_locks.remove(self)