Skip to content

Commit

Permalink
[DPE-5581] Timeline Management (#716)
Browse files Browse the repository at this point in the history
* Timelines

* Temporarily disable failing unit tests.

* Temporarily disable failing unit tests.

* Remove redundant comment.

* Fix get current timeline connectivity error. Fix PITR integration test.

* Format.

* Improve PITR integration test stability. Fix test_restore_on_new_cluster integration test.

* Improve _was_restore_successful timeline check.

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

* Disable failing unit tests.

* Fix docs.

* Revert "Disable failing unit tests."

This reverts commit b5e7666.

* Revert "Temporarily disable failing unit tests."

This reverts commit 3217814.

* Revert "Temporarily disable failing unit tests."

This reverts commit b463961.

* Parameter validation improvement.

* Unit tests.
  • Loading branch information
Zvirovyi authored Oct 15, 2024
1 parent c0ca3c3 commit 30af27d
Show file tree
Hide file tree
Showing 10 changed files with 662 additions and 267 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 30af27d

Please sign in to comment.