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
4 changes: 2 additions & 2 deletions refresh_versions.toml
Comment thread
dragomirp marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ name = "charmed-postgresql"

[snap.revisions]
# amd64
x86_64 = "289"
x86_64 = "332"
# arm64
aarch64 = "288"
aarch64 = "331"
2 changes: 1 addition & 1 deletion scripts/cluster_topology_observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ async def main():
)

# Wait some time before checking again for a cluster topology change.
sleep(30)
sleep(10)
Comment thread
dragomirp marked this conversation as resolved.


if __name__ == "__main__":
Expand Down
4 changes: 4 additions & 0 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ def _post_snap_refresh(self, refresh: charm_refresh.Machines):
self._setup_exporter()
self.backup.start_stop_pgbackrest_service()
self._setup_pgbackrest_exporter()
self.watcher_offer.update_unit_address()
Comment thread
dragomirp marked this conversation as resolved.

# Wait until the database initialise.
self.set_unit_status(WaitingStatus("waiting for database initialisation"), refresh=refresh)
Expand Down Expand Up @@ -1996,6 +1997,9 @@ def promote_primary_unit(self, event: ActionEvent) -> None:
try:
self._patroni.switchover(self._member_name)
self.unit_peer_data.update({"timestamp": str(datetime.now())})
if self.unit.is_leader():
self.postgresql_client_relation.update_endpoints()
self.async_replication.update_async_replication_data()
Comment thread
dragomirp marked this conversation as resolved.
except SwitchoverNotSyncError:
event.fail("Unit is not sync standby")
except SwitchoverFailedError:
Expand Down
13 changes: 4 additions & 9 deletions src/relations/watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,6 @@ def _update_relation_data(self, relation: Relation) -> None:
relation.data[self.charm.app].update({
"cluster-name": self.charm.cluster_name,
"raft-secret-id": secret_id,
"version": self.charm._patroni.get_postgresql_version(),
Comment thread
dragomirp marked this conversation as resolved.
"raft-partner-addrs": json.dumps(pg_endpoints),
"raft-port": str(RAFT_PORT),
"patroni-cas": self.charm.tls.get_peer_ca_bundle(),
Expand All @@ -439,27 +438,23 @@ def update_unit_address(self, relation: Relation | None = None) -> None:
if not relation:
return

unit_ip = self.charm._unit_ip
if unit_ip is None:
if not (unit_ip := self.charm._unit_ip):
return

changed = False
relation.data[self.charm.unit]["version"] = self.charm._patroni.get_postgresql_version()
if self.charm.refresh:
relation.data[self.charm.unit]["snap"] = self.charm.refresh.pinned_snap_revision
current_address = relation.data[self.charm.unit].get("unit-address")
if current_address != unit_ip:
logger.info(
f"Updating unit-address in watcher relation from {current_address} to {unit_ip}"
)
relation.data[self.charm.unit]["unit-address"] = unit_ip
changed = True

unit_az = os.environ.get("JUJU_AVAILABILITY_ZONE")
current_az = relation.data[self.charm.unit].get("unit-az")
if unit_az and current_az != unit_az:
relation.data[self.charm.unit]["unit-az"] = unit_az
changed = True

if changed:
logger.debug("Updated watcher relation unit data")
Comment thread
dragomirp marked this conversation as resolved.

def update_endpoints(self) -> None:
"""Update the watcher with current cluster endpoints.
Expand Down
Loading