Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for cascading replication #124

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
30 changes: 30 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,36 @@ PG database connection strings that the pglookout process should monitor.
Keys of the object should be names of the remotes and values must be valid
PostgreSQL connection strings or connection info objects.

``cascading_replication_primary`` (default ``null``)

Makes pglookout to consider matching instance as primary even though PG on
the node is in recovery mode. This allows setting cascading replication like
this::

Active cluster1 DR cluster 2
+---------------------+ +-------------------------+
| primary1 (writable) |<---------------| primary2 (non-writable) |
+---------------------+ +-------------------------+
^ ^ ^ ^
| | | |
+------------+ +------------+ +------------+ +------------+
| secondary1 | | secondary2 | | secondary3 | | secondary4 |
+------------+ +------------+ +------------+ +------------+

In a setup like this, the DR cluster 2 could replace the active cluster as
a whole in case the active cluster runs in a region that becomes unavailable.
The ``primary2``, which is not writable and not really a primary in that sense, but
may be promoted as an actual writable primary in case all nodes in the active
cluster 1 fail, is observing the state of ``primary1``, ``secondary1`` and ``secondary2``.

``secondary3`` and ``secondary4`` in the DR cluster 2 need to be configured to replicate
from ``primary2`` and need to monitor the availability of that so that they can
take over should it fail. However, as ``primary2`` is not writable it would not by
default be considered to be a master node and replication would not get
configured correctly nor would availability monitoring work as expected.
Setting ``cascading_replication_primary=primary2`` for ``secondary3`` and ``secondary4``
makes this configuration work as expected.

``primary_conninfo_template``

Connection string or connection info object template to use when setting a new
Expand Down
2 changes: 2 additions & 0 deletions pglookout/cluster_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ def _query_cluster_member_state(self, instance, db_conn):

if f_result:
result.update(self._parse_status_query_result(f_result))
if instance == self.config.get("cascading_replication_primary") and "pg_is_in_recovery" in result:
result["pg_is_in_recovery"] = False
return result

@staticmethod
Expand Down
Loading