Skip to content

Commit b2f842c

Browse files
Workaround Patroni restart_pending flacking flag
1 parent 99ade1a commit b2f842c

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/cluster.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -446,18 +446,27 @@ def is_restart_pending(self) -> bool:
446446
# The current Patroni 3.2.2 has wired behaviour: it temporary flag pending_restart=True
447447
# on any changes to REST API, which is gone within a second but long enough to be
448448
# cougth by charm. Sleep 2 seconds as a protection here until Patroni 3.3.0 upgrade
449-
sleep(2)
449+
pending_restart = self._get_patroni_restart_pending()
450+
if pending_restart:
451+
# The current Patroni 3.2.2 has wired behaviour: it temporary flag pending_restart=True
452+
# on any changes to REST API, which is gone within a second but long enough to be
453+
# cougth by charm. Sleep 2 seconds as a protection here until Patroni 3.3.0 upgrade.
454+
# Repeat the request to make sure pending_restart flag is still here
455+
sleep(2)
456+
pending_restart = self._get_patroni_restart_pending()
457+
458+
return pending_restart
459+
460+
def _get_patroni_restart_pending(self) -> bool:
461+
"""Returns whether the Patroni flag pending_restart on REST API."""
450462
r = requests.get(
451463
f"{self._patroni_url}/patroni",
452464
verify=self.verify,
453465
timeout=API_REQUEST_TIMEOUT,
454466
auth=self._patroni_auth,
455467
)
456-
try:
457-
pending_restart = r.json()["pending_restart"]
458-
except KeyError:
459-
pending_restart = False
460-
pass
468+
469+
pending_restart = r.json().get("pending_restart", False)
461470
logger.debug(
462471
f"API is_restart_pending ({pending_restart}): %s (%s)",
463472
r,

0 commit comments

Comments
 (0)