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

Quorum based failover #2668

Open
wants to merge 73 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
2223553
Introduce quorum field in the /sync key
CyberDem0n May 11, 2023
ea019ba
Adapt SyncHandler interfaces for quorum commit
CyberDem0n May 11, 2023
f5f0adb
Compatibility with future synchronous_mode=quorum
CyberDem0n May 11, 2023
e97d2f0
Implement synchronous_mode=quorum
CyberDem0n May 11, 2023
d799be9
update REST API
CyberDem0n May 11, 2023
7284416
Behave tests
CyberDem0n May 11, 2023
dbfe844
Update documentation
CyberDem0n May 11, 2023
f298921
Merge branch 'master' of github.com:zalando/patroni into feature/quor…
CyberDem0n May 23, 2023
8f60b18
Delay _process_quorum_replication by loop_wait seconds after promote
CyberDem0n May 23, 2023
a5e1c53
Fix citus tests. Metadata sync could be slow after coordinator switch
CyberDem0n May 23, 2023
db8061a
Merge branch 'master' of github.com:zalando/patroni into feature/quor…
CyberDem0n May 30, 2023
2dafb37
Merge branch 'master' of github.com:zalando/patroni into feature/quor…
CyberDem0n Jul 7, 2023
b0d8b21
Merge branch 'master' of github.com:zalando/patroni into feature/quor…
CyberDem0n Jul 13, 2023
e6d251b
Limit time spent in _process_quorum_replication by loop_wait seconds
CyberDem0n Jul 18, 2023
300740c
Please codacy
CyberDem0n Jul 18, 2023
ad4bea7
Apply suggestions from code review
CyberDem0n Jul 20, 2023
666a483
Merge branch 'master' of github.com:zalando/patroni into feature/quor…
CyberDem0n Jul 20, 2023
893e460
Address review feedback
CyberDem0n Jul 20, 2023
2e9b6b2
Apply suggestions from code review
CyberDem0n Jul 21, 2023
0ef094f
Merge branch 'master' of github.com:zalando/patroni into feature/quor…
CyberDem0n Jul 21, 2023
7114a07
remove unrelated change
CyberDem0n Jul 21, 2023
7d11d9d
Merge branch 'feature/quorum-commit' of github.com:zalando/patroni in…
CyberDem0n Jul 21, 2023
768c9eb
Merge branch 'master' of github.com:zalando/patroni into feature/quor…
CyberDem0n Jul 25, 2023
5dfe5e0
Revert unwanted change
CyberDem0n Jul 25, 2023
bf7f076
Merge branch 'master' of github.com:zalando/patroni into feature/quor…
CyberDem0n Jul 25, 2023
3ee0238
Add more examples of sync and quorum modes
CyberDem0n Jul 25, 2023
aa0c321
Merge branch 'master' of github.com:zalando/patroni into feature/quor…
CyberDem0n Jul 26, 2023
bea97d1
Apply suggestions from code review
CyberDem0n Jul 26, 2023
7aca74e
Merge branch 'feature/quorum-commit' of github.com:zalando/patroni in…
CyberDem0n Jul 26, 2023
3bf7095
Address review feedback
CyberDem0n Jul 26, 2023
a48ef03
Please pyright
CyberDem0n Jul 26, 2023
e2805fd
Apply suggestions from code review
CyberDem0n Jul 31, 2023
538d621
Address review feedback
CyberDem0n Jul 31, 2023
1a0549d
Merge branch 'master' of github.com:zalando/patroni into feature/quor…
CyberDem0n Jul 31, 2023
d6e3f25
Merge branch 'master' of github.com:zalando/patroni into feature/quor…
CyberDem0n Aug 8, 2023
74b89d7
Merge branch 'master' of github.com:zalando/patroni into feature/quor…
CyberDem0n Aug 8, 2023
f5cb888
Merge branch 'master' of github.com:zalando/patroni into feature/quor…
CyberDem0n Aug 14, 2023
c7fbd35
Apply suggestions from code review
CyberDem0n Aug 17, 2023
735a9ee
Merge branch 'master' of github.com:zalando/patroni into feature/quor…
CyberDem0n Aug 17, 2023
ef8aa21
Address code review feedback
CyberDem0n Aug 17, 2023
8f3c6d2
Merge branch 'master' of github.com:zalando/patroni into feature/quor…
CyberDem0n Aug 17, 2023
ce7fce3
Please sphinx
CyberDem0n Aug 17, 2023
f51309d
Merge branch 'master' of github.com:zalando/patroni into feature/quor…
CyberDem0n Aug 18, 2023
8e24d72
Merge branch 'master' of github.com:zalando/patroni into feature/quor…
CyberDem0n Aug 22, 2023
4d26435
Address review feedback
CyberDem0n Aug 23, 2023
79b4098
Apply suggestions from code review
CyberDem0n Aug 24, 2023
3a602f0
Address review feedback
CyberDem0n Aug 24, 2023
1ea5d6b
Merge branch 'master' of github.com:zalando/patroni into feature/quor…
CyberDem0n Sep 11, 2023
5f65b56
more f-strings
CyberDem0n Sep 11, 2023
a95d59c
Merge branch 'master' of github.com:zalando/patroni into feature/quor…
CyberDem0n Sep 11, 2023
61c3d7c
Fix citus.rst
CyberDem0n Sep 11, 2023
67612f5
Merge branch 'master' of github.com:zalando/patroni into feature/quor…
CyberDem0n Sep 12, 2023
d1dff78
Rename methods in unit tests to match names of methods we are testing
CyberDem0n Sep 12, 2023
9fccc05
Merge branch 'master' of github.com:zalando/patroni into feature/quor…
CyberDem0n Sep 14, 2023
73a5c9a
Apply suggestions from code review
CyberDem0n Sep 14, 2023
0f6e069
Address feedback
CyberDem0n Sep 15, 2023
8612d55
Merge branch 'feature/quorum-commit' of github.com:zalando/patroni in…
CyberDem0n Sep 15, 2023
b4c783d
Merge branch 'master' of github.com:zalando/patroni into feature/quor…
CyberDem0n Sep 25, 2023
2f6678e
Merge branch 'master' of github.com:zalando/patroni into feature/quor…
CyberDem0n Sep 26, 2023
5c6b34a
Merge branch 'master' of github.com:zalando/patroni into feature/quor…
CyberDem0n Oct 10, 2023
f329891
Merge branch 'master' of github.com:zalando/patroni into feature/quor…
CyberDem0n Oct 23, 2023
7794f9c
Apply suggestions from code review
CyberDem0n Oct 24, 2023
a9e1d67
Update sync.py
CyberDem0n Oct 24, 2023
94e128c
Merge branch 'master' of github.com:zalando/patroni into feature/quor…
CyberDem0n Oct 25, 2023
ebdc197
Apply suggestions from code review
CyberDem0n Oct 25, 2023
13cc86f
Merge branch 'master' of github.com:zalando/patroni into feature/quor…
CyberDem0n Nov 24, 2023
193f5f1
Merge branch 'feature/quorum-commit' of github.com:zalando/patroni in…
CyberDem0n Nov 24, 2023
91a6059
Merge branch 'master' of github.com:zalando/patroni into feature/quor…
CyberDem0n Nov 29, 2023
3b367d6
Revert unexpected change
CyberDem0n Nov 29, 2023
59ecfb1
Merge branch 'master' of github.com:zalando/patroni into feature/quor…
CyberDem0n Jan 5, 2024
bda07fa
Merge branch 'master' of github.com:zalando/patroni into feature/quor…
CyberDem0n Apr 2, 2024
0da448b
Merge branch 'master' of github.com:zalando/patroni into feature/quor…
CyberDem0n Apr 3, 2024
4055d66
Merge branch 'master' of github.com:zalando/patroni into feature/quor…
CyberDem0n Jun 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
106 changes: 54 additions & 52 deletions docs/citus.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ There are only a few simple rules you need to follow:

After that you just need to start Patroni and it will handle the rest:

0. Patroni will set ``bootstrap.dcs.synchronous_mode`` to :ref:`quorum <quorum_mode>`
if it is not explicitly set to any other value.
1. ``citus`` extension will be automatically added to ``shared_preload_libraries``.
2. If ``max_prepared_transactions`` isn't explicitly set in the global
:ref:`dynamic configuration <dynamic_configuration>` Patroni will
Expand Down Expand Up @@ -77,36 +79,36 @@ It results in two major differences in :ref:`patronictl` behaviour when
An example of :ref:`patronictl_list` output for the Citus cluster::

postgres@coord1:~$ patronictl list demo
+ Citus cluster: demo ----------+--------------+---------+----+-----------+
| Group | Member | Host | Role | State | TL | Lag in MB |
+-------+---------+-------------+--------------+---------+----+-----------+
| 0 | coord1 | 172.27.0.10 | Replica | running | 1 | 0 |
| 0 | coord2 | 172.27.0.6 | Sync Standby | running | 1 | 0 |
| 0 | coord3 | 172.27.0.4 | Leader | running | 1 | |
| 1 | work1-1 | 172.27.0.8 | Sync Standby | running | 1 | 0 |
| 1 | work1-2 | 172.27.0.2 | Leader | running | 1 | |
| 2 | work2-1 | 172.27.0.5 | Sync Standby | running | 1 | 0 |
| 2 | work2-2 | 172.27.0.7 | Leader | running | 1 | |
+-------+---------+-------------+--------------+---------+----+-----------+
+ Citus cluster: demo ----------+----------------+---------+----+-----------+
| Group | Member | Host | Role | State | TL | Lag in MB |
+-------+---------+-------------+----------------+---------+----+-----------+
| 0 | coord1 | 172.27.0.10 | Replica | running | 1 | 0 |
| 0 | coord2 | 172.27.0.6 | Quorum Standby | running | 1 | 0 |
| 0 | coord3 | 172.27.0.4 | Leader | running | 1 | |
| 1 | work1-1 | 172.27.0.8 | Quorum Standby | running | 1 | 0 |
| 1 | work1-2 | 172.27.0.2 | Leader | running | 1 | |
| 2 | work2-1 | 172.27.0.5 | Quorum Standby | running | 1 | 0 |
| 2 | work2-2 | 172.27.0.7 | Leader | running | 1 | |
+-------+---------+-------------+----------------+---------+----+-----------+

If we add the ``--group`` option, the output will change to::

postgres@coord1:~$ patronictl list demo --group 0
+ Citus cluster: demo (group: 0, 7179854923829112860) -----------+
| Member | Host | Role | State | TL | Lag in MB |
+--------+-------------+--------------+---------+----+-----------+
| coord1 | 172.27.0.10 | Replica | running | 1 | 0 |
| coord2 | 172.27.0.6 | Sync Standby | running | 1 | 0 |
| coord3 | 172.27.0.4 | Leader | running | 1 | |
+--------+-------------+--------------+---------+----+-----------+
+ Citus cluster: demo (group: 0, 7179854923829112860) -+-----------+
| Member | Host | Role | State | TL | Lag in MB |
+--------+-------------+----------------+---------+----+-----------+
| coord1 | 172.27.0.10 | Replica | running | 1 | 0 |
| coord2 | 172.27.0.6 | Quorum Standby | running | 1 | 0 |
| coord3 | 172.27.0.4 | Leader | running | 1 | |
+--------+-------------+----------------+---------+----+-----------+

postgres@coord1:~$ patronictl list demo --group 1
+ Citus cluster: demo (group: 1, 7179854923881963547) -----------+
| Member | Host | Role | State | TL | Lag in MB |
+---------+------------+--------------+---------+----+-----------+
| work1-1 | 172.27.0.8 | Sync Standby | running | 1 | 0 |
| work1-2 | 172.27.0.2 | Leader | running | 1 | |
+---------+------------+--------------+---------+----+-----------+
+ Citus cluster: demo (group: 1, 7179854923881963547) -+-----------+
| Member | Host | Role | State | TL | Lag in MB |
+---------+------------+----------------+---------+----+-----------+
| work1-1 | 172.27.0.8 | Quorum Standby | running | 1 | 0 |
| work1-2 | 172.27.0.2 | Leader | running | 1 | |
+---------+------------+----------------+---------+----+-----------+

Citus worker switchover
-----------------------
Expand All @@ -122,28 +124,28 @@ new primary worker node is ready to accept read-write queries.
An example of :ref:`patronictl_switchover` on the worker cluster::

postgres@coord1:~$ patronictl switchover demo
+ Citus cluster: demo ----------+--------------+---------+----+-----------+
| Group | Member | Host | Role | State | TL | Lag in MB |
+-------+---------+-------------+--------------+---------+----+-----------+
| 0 | coord1 | 172.27.0.10 | Replica | running | 1 | 0 |
| 0 | coord2 | 172.27.0.6 | Sync Standby | running | 1 | 0 |
| 0 | coord3 | 172.27.0.4 | Leader | running | 1 | |
| 1 | work1-1 | 172.27.0.8 | Leader | running | 1 | |
| 1 | work1-2 | 172.27.0.2 | Sync Standby | running | 1 | 0 |
| 2 | work2-1 | 172.27.0.5 | Sync Standby | running | 1 | 0 |
| 2 | work2-2 | 172.27.0.7 | Leader | running | 1 | |
+-------+---------+-------------+--------------+---------+----+-----------+
+ Citus cluster: demo ----------+----------------+---------+----+-----------+
| Group | Member | Host | Role | State | TL | Lag in MB |
+-------+---------+-------------+----------------+---------+----+-----------+
| 0 | coord1 | 172.27.0.10 | Replica | running | 1 | 0 |
| 0 | coord2 | 172.27.0.6 | Quorum Standby | running | 1 | 0 |
| 0 | coord3 | 172.27.0.4 | Leader | running | 1 | |
| 1 | work1-1 | 172.27.0.8 | Leader | running | 1 | |
| 1 | work1-2 | 172.27.0.2 | Quorum Standby | running | 1 | 0 |
| 2 | work2-1 | 172.27.0.5 | Quorum Standby | running | 1 | 0 |
| 2 | work2-2 | 172.27.0.7 | Leader | running | 1 | |
+-------+---------+-------------+----------------+---------+----+-----------+
Citus group: 2
Primary [work2-2]:
Candidate ['work2-1'] []:
When should the switchover take place (e.g. 2022-12-22T08:02 ) [now]:
Current cluster topology
+ Citus cluster: demo (group: 2, 7179854924063375386) -----------+
| Member | Host | Role | State | TL | Lag in MB |
+---------+------------+--------------+---------+----+-----------+
| work2-1 | 172.27.0.5 | Sync Standby | running | 1 | 0 |
| work2-2 | 172.27.0.7 | Leader | running | 1 | |
+---------+------------+--------------+---------+----+-----------+
+ Citus cluster: demo (group: 2, 7179854924063375386) -+-----------+
| Member | Host | Role | State | TL | Lag in MB |
+---------+------------+----------------+---------+----+-----------+
| work2-1 | 172.27.0.5 | Quorum Standby | running | 1 | 0 |
| work2-2 | 172.27.0.7 | Leader | running | 1 | |
+---------+------------+----------------+---------+----+-----------+
Are you sure you want to switchover cluster demo, demoting current primary work2-2? [y/N]: y
2022-12-22 07:02:40.33003 Successfully switched over to "work2-1"
+ Citus cluster: demo (group: 2, 7179854924063375386) ------+
Expand All @@ -154,17 +156,17 @@ An example of :ref:`patronictl_switchover` on the worker cluster::
+---------+------------+---------+---------+----+-----------+

postgres@coord1:~$ patronictl list demo
+ Citus cluster: demo ----------+--------------+---------+----+-----------+
| Group | Member | Host | Role | State | TL | Lag in MB |
+-------+---------+-------------+--------------+---------+----+-----------+
| 0 | coord1 | 172.27.0.10 | Replica | running | 1 | 0 |
| 0 | coord2 | 172.27.0.6 | Sync Standby | running | 1 | 0 |
| 0 | coord3 | 172.27.0.4 | Leader | running | 1 | |
| 1 | work1-1 | 172.27.0.8 | Leader | running | 1 | |
| 1 | work1-2 | 172.27.0.2 | Sync Standby | running | 1 | 0 |
| 2 | work2-1 | 172.27.0.5 | Leader | running | 2 | |
| 2 | work2-2 | 172.27.0.7 | Sync Standby | running | 2 | 0 |
+-------+---------+-------------+--------------+---------+----+-----------+
+ Citus cluster: demo ----------+----------------+---------+----+-----------+
| Group | Member | Host | Role | State | TL | Lag in MB |
+-------+---------+-------------+----------------+---------+----+-----------+
| 0 | coord1 | 172.27.0.10 | Replica | running | 1 | 0 |
| 0 | coord2 | 172.27.0.6 | Quorum Standby | running | 1 | 0 |
| 0 | coord3 | 172.27.0.4 | Leader | running | 1 | |
| 1 | work1-1 | 172.27.0.8 | Leader | running | 1 | |
| 1 | work1-2 | 172.27.0.2 | Quorum Standby | running | 1 | 0 |
| 2 | work2-1 | 172.27.0.5 | Leader | running | 2 | |
| 2 | work2-2 | 172.27.0.7 | Quorum Standby | running | 2 | 0 |
+-------+---------+-------------+----------------+---------+----+-----------+

And this is how it looks on the coordinator side::

Expand Down
2 changes: 1 addition & 1 deletion docs/dynamic_configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ In order to change the dynamic configuration you can use either :ref:`patronictl
- **max\_timelines\_history**: maximum number of timeline history items kept in DCS. Default value: 0. When set to 0, it keeps the full history in DCS.
- **primary\_start\_timeout**: the amount of time a primary is allowed to recover from failures before failover is triggered (in seconds). Default is 300 seconds. When set to 0 failover is done immediately after a crash is detected if possible. When using asynchronous replication a failover can cause lost transactions. Worst case failover time for primary failure is: loop\_wait + primary\_start\_timeout + loop\_wait, unless primary\_start\_timeout is zero, in which case it's just loop\_wait. Set the value according to your durability/availability tradeoff.
- **primary\_stop\_timeout**: The number of seconds Patroni is allowed to wait when stopping Postgres and effective only when synchronous_mode is enabled. When set to > 0 and the synchronous_mode is enabled, Patroni sends SIGKILL to the postmaster if the stop operation is running for more than the value set by primary\_stop\_timeout. Set the value according to your durability/availability tradeoff. If the parameter is not set or set <= 0, primary\_stop\_timeout does not apply.
- **synchronous\_mode**: turns on synchronous replication mode. In this mode a replica will be chosen as synchronous and only the latest leader and synchronous replica are able to participate in leader election. Synchronous mode makes sure that successfully committed transactions will not be lost at failover, at the cost of losing availability for writes when Patroni cannot ensure transaction durability. See :ref:`replication modes documentation <replication_modes>` for details.
- **synchronous\_mode**: turns on synchronous replication mode. Possible values: ``off``, ``on``, ``quorum``. In this mode the leader takes care of management of ``synchronous_standby_names``, and only the last known leader, or one of synchronous replicas, are allowed to participate in leader race. Synchronous mode makes sure that successfully committed transactions will not be lost at failover, at the cost of losing availability for writes when Patroni cannot ensure transaction durability. See :ref:`replication modes documentation <replication_modes>` for details.
- **synchronous\_mode\_strict**: prevents disabling synchronous replication if no synchronous replicas are available, blocking all client writes to the primary. See :ref:`replication modes documentation <replication_modes>` for details.
- **failsafe\_mode**: Enables :ref:`DCS Failsafe Mode <dcs_failsafe_mode>`. Defaults to `false`.
- **postgresql**:
Expand Down