Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion src/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def is_creating_backup(self) -> bool:
for member in r.json()["members"]
)

def is_replication_healthy(self) -> bool:
def is_replication_healthy(self, raft_encryption: bool = False) -> bool:
"""Return whether the replication is healthy."""
try:
for attempt in Retrying(stop=stop_after_delay(60), wait=wait_fixed(3)):
Expand All @@ -477,6 +477,12 @@ def is_replication_healthy(self) -> bool:
auth=self._patroni_auth,
timeout=PATRONI_TIMEOUT,
)
# If raft is getting encrypted some of the calls will fail
if member_status.status_code == 503 and raft_encryption:
logger.warning(
f"Failed replication check for {members_ip} during raft encryption"
)
continue
if member_status.status_code != 200:
logger.debug(
f"Failed replication check for {members_ip} with code {member_status.status_code}"
Expand Down
10 changes: 9 additions & 1 deletion src/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ def _on_upgrade_granted(self, event: UpgradeGrantedEvent) -> None:
self.set_unit_failed()
return

raft_encryption = (
int(
json.loads(self.peer_relation.data[self.charm.app].get("dependencies", "{}"))
.get("charm", {})
.get("version", 0)
)
< 3
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We bumped to 3 with the RAFT password.

)
self.charm._setup_exporter()
self.charm.backup.start_stop_pgbackrest_service()

Expand All @@ -178,7 +186,7 @@ def _on_upgrade_granted(self, event: UpgradeGrantedEvent) -> None:
not self.charm._patroni.member_started
or self.charm.unit.name.replace("/", "-")
not in self.charm._patroni.cluster_members
or not self.charm._patroni.is_replication_healthy()
or not self.charm._patroni.is_replication_healthy(raft_encryption)
):
logger.debug(
"Instance not yet back in the cluster."
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@ def test_is_replication_healthy(peers_ips, patroni):
]
assert not patroni.is_replication_healthy()

# Test ignoring errors in case of raft encryption.
_get.side_effect = None
_get.return_value.status_code = 503
assert patroni.is_replication_healthy(True)


def test_is_member_isolated(peers_ips, patroni):
with (
Expand Down
Loading