memcached: use retrying rather than sleeping
That should allow better handling of retrying, sleep delays, etc. Change-Id: I7658b4d5bacb0aef84a8c377a7e487327011b7ee
This commit is contained in:
parent
135a523a94
commit
f438de0fdf
|
@ -17,7 +17,6 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
import time
|
|
||||||
|
|
||||||
import msgpack
|
import msgpack
|
||||||
import pymemcache.client
|
import pymemcache.client
|
||||||
|
@ -50,8 +49,8 @@ class MemcachedLock(locking.Lock):
|
||||||
self.name = self._LOCK_PREFIX + name
|
self.name = self._LOCK_PREFIX + name
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
|
|
||||||
|
@retry
|
||||||
def acquire(self, blocking=True):
|
def acquire(self, blocking=True):
|
||||||
while True:
|
|
||||||
if self.coord.client.add(
|
if self.coord.client.add(
|
||||||
self.name,
|
self.name,
|
||||||
self.coord._member_id,
|
self.coord._member_id,
|
||||||
|
@ -61,8 +60,7 @@ class MemcachedLock(locking.Lock):
|
||||||
return True
|
return True
|
||||||
if not blocking:
|
if not blocking:
|
||||||
return False
|
return False
|
||||||
# NOTE(jd) Configurable? :/
|
raise Retry
|
||||||
time.sleep(0.11)
|
|
||||||
|
|
||||||
def release(self):
|
def release(self):
|
||||||
self.coord._acquired_locks.remove(self)
|
self.coord._acquired_locks.remove(self)
|
||||||
|
|
Loading…
Reference in New Issue