Merge "Speed up memcache lock" into stable/juno

This commit is contained in:
Jenkins 2015-04-06 19:42:51 +00:00 committed by Gerrit Code Review
commit 579aad0c41
1 changed files with 4 additions and 8 deletions

View File

@ -57,20 +57,16 @@ class MemcachedLock(object):
def acquire(self, wait=True):
client = self.client_fn()
i = 0
while True:
for i in range(self.max_lock_attempts):
if client.add(self.key, 1, self.lock_timeout):
return True
elif not wait:
return False
else:
sleep_time = (((i + 1) * random.random()) + 2 ** i) / 2.5
sleep_time = random.random()
time.sleep(sleep_time)
if i <= self.max_lock_attempts:
i += 1
else:
raise exception.UnexpectedError(
_('Maximum lock attempts on %s occurred.') % self.key)
raise exception.UnexpectedError(
_('Maximum lock attempts on %s occurred.') % self.key)
def release(self):
client = self.client_fn()