Skip to content

fix(failover): publish the failover quorum only once replicas are aligned - #12023

Draft
leonardoce wants to merge 1 commit into
cloudnative-pg:mainfrom
leonardoce:failoverquorum-replica-align
Draft

leonardoce wants to merge 1 commit into
cloudnative-pg:mainfrom
leonardoce:failoverquorum-replica-align

Conversation

@leonardoce

Copy link
Copy Markdown
Contributor

With quorum-based failover enabled, the primary lists the synchronous standbys in the FailoverQuorum resource right after applying a new synchronous replication configuration. Those standbys were not necessarily up to date: for example, right after a promotion they may still be catching up with the new primary. The operator could then consider a failover safe while some transactions acknowledged under the previous configuration were not on enough of the listed standbys, and promoting a replica could lose them.

The primary now takes its current WAL position when it detects a change in the standby list, empties the FailoverQuorum resource, and publishes the new list only when at least as many listed standbys as the configured synchronous number are streaming and have flushed that position. Until then no failover is allowed, and the check is repeated every second without blocking the rest of the reconciliation.

If the configuration changes again while waiting, the position is taken again. If the instance manager restarts, a later position is taken, which can only make the check stricter.

Refs #8790

@cnpg-bot cnpg-bot added backport-requested ◀️ This pull request should be backported to all supported releases release-1.28 release-1.30 labels Nov 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

❗ By default, the pull request is configured to backport to all release branches.

  • To stop backporting this pr, remove the label: backport-requested ◀️ or add the label 'do not backport'
  • To stop backporting this pr to a certain release branch, remove the specific branch label: release-x.y

…gned

With quorum-based failover enabled, the primary lists the synchronous
standbys in the FailoverQuorum resource right after applying a new
synchronous replication configuration. Those standbys were not
necessarily up to date: for example, right after a promotion they may
still be catching up with the new primary. The operator could then
consider a failover safe while some transactions acknowledged under the
previous configuration were not on enough of the listed standbys, and
promoting a replica could lose them.

The primary now takes its current WAL position when it detects a change
in the standby list, empties the FailoverQuorum resource, and publishes
the new list only when at least as many listed standbys as the
configured synchronous number are streaming and have flushed that
position. Until then no failover is allowed, and the check is repeated
every second without blocking the rest of the reconciliation.

If the configuration changes again while waiting, the position is taken
again. If the instance manager restarts, a later position is taken,
which can only make the check stricter.

Signed-off-by: Leonardo Cecchi <[email protected]>
Assisted-by: Claude
@leonardoce
leonardoce force-pushed the failoverquorum-replica-align branch from bc2de22 to 3ffa690 Compare November 25, 2026 09:24
@korchak-aleksandr

Copy link
Copy Markdown

Thanks for picking this up. I think one gap remains: the captured LSN doesn't cover the delay
between a reload of synchronous_standby_names and the moment commits actually start waiting.
In PostgreSQL that switch is made by the checkpointer, which during a fast or behind-schedule
checkpoint applies the reload only after the checkpoint ends.

Example, 2 instances, preferred, standby B comes back: the list becomes ANY 1 ("B"), this PR
captures X, B flushes X and the quorum is published, while commits after X are still acknowledged
without B. Promoting B then loses them.

@GellertBabel's commit closes this by requesting a CHECKPOINT and waiting for one that started
after the request. Could the LSN be captured only after that point?

I've sent an updated PostgreSQL patch (based on Ants Aasma's) that applies the reload during fast
checkpoints too: https://commitfest.postgresql.org/patch/7710/. It won't land in a release any time
soon and doesn't cover the fsync phase, so the operator still needs its own check. We'll test this PR
on 2-instance clusters once it's out of draft.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-requested ◀️ This pull request should be backported to all supported releases release-1.28 release-1.30

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants