Skip to content

Commit

Permalink
[MISC] Rollback Patroni update (#456)
Browse files Browse the repository at this point in the history
* Wait for PG to be back up when restarting

* Update snaps
  • Loading branch information
dragomirp authored Apr 26, 2024
1 parent 0f2c8c2 commit 69e4db0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
8 changes: 8 additions & 0 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,14 @@ def _restart(self, event: RunWithLock) -> None:
self.unit.status = BlockedStatus(error_message)
return

try:
for attempt in Retrying(wait=wait_fixed(3), stop_after_delay=stop_after_delay(300)):
with attempt:
if not self._can_connect_to_postgresql:
assert False
except Exception:
logger.exception("Unable to reconnect to postgresql")

# Start or stop the pgBackRest TLS server service when TLS certificate change.
self.backup.start_stop_pgbackrest_service()

Expand Down
2 changes: 1 addition & 1 deletion src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
SNAP_PACKAGES = [
(
POSTGRESQL_SNAP_NAME,
{"revision": {"aarch64": "110", "x86_64": "111"}, "channel": "14/stable"},
{"revision": {"aarch64": "112", "x86_64": "113"}, "channel": "14/stable"},
)
]

Expand Down
19 changes: 11 additions & 8 deletions tests/integration/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,11 @@ async def test_postgresql_parameters_change(ops_test: OpsTest) -> None:
for unit_id in UNIT_IDS:
host = get_unit_address(ops_test, f"{DATABASE_APP_NAME}/{unit_id}")
logger.info("connecting to the database host: %s", host)
with db_connect(host, password) as connection:
settings_names = ["max_prepared_transactions", "shared_buffers", "lc_monetary"]
with connection.cursor() as cursor:
try:
with psycopg2.connect(
f"dbname='postgres' user='operator' host='{host}' password='{password}' connect_timeout=1"
) as connection, connection.cursor() as cursor:
settings_names = ["max_prepared_transactions", "shared_buffers", "lc_monetary"]
cursor.execute(
sql.SQL("SELECT name,setting FROM pg_settings WHERE name IN ({});").format(
sql.SQL(", ").join(sql.Placeholder() * len(settings_names))
Expand All @@ -193,12 +195,13 @@ async def test_postgresql_parameters_change(ops_test: OpsTest) -> None:
)
records = cursor.fetchall()
settings = convert_records_to_dict(records)
connection.close()

# Validate each configuration set by Patroni on PostgreSQL.
assert settings["max_prepared_transactions"] == "100"
assert settings["shared_buffers"] == "128"
assert settings["lc_monetary"] == "en_GB.utf8"
# Validate each configuration set by Patroni on PostgreSQL.
assert settings["max_prepared_transactions"] == "100"
assert settings["shared_buffers"] == "128"
assert settings["lc_monetary"] == "en_GB.utf8"
finally:
connection.close()


@pytest.mark.group(1)
Expand Down
1 change: 0 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ allowlist_externals =
charmcraft
charmcraftcache
mv
psycopg2-binary
commands_pre =
poetry export --only main,charm-libs --output requirements.txt
commands =
Expand Down

0 comments on commit 69e4db0

Please sign in to comment.