Skip to content

Commit

Permalink
Bail out early from NextId.__current_id getter
Browse files Browse the repository at this point in the history
  • Loading branch information
brainix committed Dec 7, 2020
1 parent e116df0 commit 7882d95
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions pottery/nextid.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ def __repr__(self) -> str:

@property
def __current_id(self) -> int:
with concurrent.futures.ThreadPoolExecutor() as executor:
quorum = False

with BailOutExecutor() as executor:
futures = set()
for master in self.masters:
futures.add(executor.submit(master.get, self.key))
Expand All @@ -144,12 +146,16 @@ def __current_id(self) -> int:
current_ids.append(int(future.result()))
except RedisError as error:
_logger.error(error, exc_info=True)
else:
num_masters_gotten = len(current_ids)
quorum = num_masters_gotten >= len(self.masters) // 2 + 1
if quorum: # pragma: no cover
break

num_masters_gotten = len(current_ids)
if num_masters_gotten < len(self.masters) // 2 + 1:
raise QuorumNotAchieved(self.masters, self.key)
else:
if quorum:
return max(current_ids)
else:
raise QuorumNotAchieved(self.masters, self.key)

@__current_id.setter
def __current_id(self, value: int) -> None:
Expand Down

0 comments on commit 7882d95

Please sign in to comment.