Skip to content

Commit

Permalink
[DPE-5561] Timeline Management (#629)
Browse files Browse the repository at this point in the history
* Timelines management.

* Disabled failing unit tests.

* Improvements from the K8s PR.

* Add automatic timeline selection with the single 'restore-to-time' parameter.

* Fix docs.

* Revert "Disabled failing unit tests."

This reverts commit e5cec66.

* Parameter validation improvement.

* Unit tests.
  • Loading branch information
Zvirovyi authored Oct 15, 2024
1 parent 55d4720 commit 95ad074
Show file tree
Hide file tree
Showing 10 changed files with 683 additions and 385 deletions.
16 changes: 15 additions & 1 deletion lib/charms/postgresql_k8s/v0/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 35
LIBPATCH = 36

INVALID_EXTRA_USER_ROLE_BLOCKING_MESSAGE = "invalid role(s) for extra user roles"

Expand Down Expand Up @@ -83,6 +83,10 @@ class PostgreSQLGetLastArchivedWALError(Exception):
"""Exception raised when retrieving last archived WAL fails."""


class PostgreSQLGetCurrentTimelineError(Exception):
"""Exception raised when retrieving current timeline id for the PostgreSQL unit fails."""


class PostgreSQLGetPostgreSQLVersionError(Exception):
"""Exception raised when retrieving PostgreSQL version fails."""

Expand Down Expand Up @@ -419,6 +423,16 @@ def get_last_archived_wal(self) -> str:
logger.error(f"Failed to get PostgreSQL last archived WAL: {e}")
raise PostgreSQLGetLastArchivedWALError()

def get_current_timeline(self) -> str:
"""Get the timeline id for the current PostgreSQL unit."""
try:
with self._connect_to_database() as connection, connection.cursor() as cursor:
cursor.execute("SELECT timeline_id FROM pg_control_checkpoint();")
return cursor.fetchone()[0]
except psycopg2.Error as e:
logger.error(f"Failed to get PostgreSQL current timeline id: {e}")
raise PostgreSQLGetCurrentTimelineError()

def get_postgresql_text_search_configs(self) -> Set[str]:
"""Returns the PostgreSQL available text search configs.
Expand Down
Loading

0 comments on commit 95ad074

Please sign in to comment.