[Refactor] Rename _is_leader to _leader_expiry (#2807)

This commit is contained in:
Mark Pekala
2023-08-11 10:30:20 +02:00
committed by GitHub
parent 9209a5a133
commit b83f1c0f44
+14 -6
View File
@@ -147,8 +147,8 @@ class Ha(object):
self.cluster = Cluster.empty()
self.global_config = self.patroni.config.get_global_config(None)
self.old_cluster = Cluster.empty()
self._is_leader = False
self._is_leader_lock = RLock()
self._leader_expiry = 0
self._leader_expiry_lock = RLock()
self._failsafe = Failsafe(patroni.dcs)
self._was_paused = False
self._leader_timeline = None
@@ -193,12 +193,20 @@ class Ha(object):
return self.global_config.is_standby_cluster
def is_leader(self) -> bool:
with self._is_leader_lock:
return self._is_leader > time.time()
""":returns: `True` if the current node is the leader, based on expiration set when it last held the key."""
with self._leader_expiry_lock:
return self._leader_expiry > time.time()
def set_is_leader(self, value: bool) -> None:
with self._is_leader_lock:
self._is_leader = time.time() + self.dcs.ttl if value else 0
"""Update the current node's view of it's own leadership status.
Will update the expiry timestamp to match the dcs ttl if setting leadership to true,
otherwise will set the expiry to the past to immediately invalidate.
:param value: is the current node the leader.
"""
with self._leader_expiry_lock:
self._leader_expiry = time.time() + self.dcs.ttl if value else 0
def sync_mode_is_active(self) -> bool:
"""Check whether synchronous replication is requested and already active.