Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify Redlock.locked() #391

Merged
merged 1 commit into from
May 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions pottery/redlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,21 +387,22 @@ def locked(self) -> int:
ttls, quorum = [], False
for future in concurrent.futures.as_completed(futures):
try:
ttls.append(future.result())
ttl = future.result()
except RedisError as error: # pragma: no cover
_logger.exception(
'%s.locked() caught %s',
self.__class__.__name__,
error.__class__.__name__,
)
else:
num_masters_acquired = sum(ttl > 0 for ttl in ttls)
quorum = num_masters_acquired > len(self.masters) // 2
if quorum:
break
if ttl > 0:
ttls.append(ttl)
quorum = len(ttls) > len(self.masters) // 2
if quorum: # pragma: no cover
break

if quorum:
validity_time = min(ttl for ttl in ttls if ttl > 0)
validity_time = min(ttls)
validity_time -= round(timer.elapsed() + self.__drift())
return max(validity_time, 0)

Expand Down