Skip to content

feat(cluster): retry transient wal-restore failures before promotion - #10552

Closed
armru wants to merge 6 commits into
mainfrom
dev/transient-errors
Closed

armru wants to merge 6 commits into
mainfrom
dev/transient-errors

Conversation

@armru

@armru armru commented Apr 24, 2026

Copy link
Copy Markdown
Member

Add spec.walRestoreRetryTimeout and a retry loop inside manager wal-restore so that transient failures during WAL replay — network blips, flaky object stores, plugin glitches — do not cause a replica to promote on an incomplete archive and lose already-archived transactions.

The command now classifies each attempt's outcome:

  • barman-cloud exit 0 or gRPC Ok -> success (exit 0)
  • barman-cloud exit 1 or gRPC NotFound -> WAL not found (exit 1,
    unchanged; PostgreSQL can transition to streaming as before)
  • anything else -> transient, retry with exponential backoff up to
    retryBackoffCap (30s), within the user-configurable budget

If the budget is exhausted the command exits with code 255, which tells PostgreSQL to stop log-shipping replication rather than promote on a partial archive. The budget defaults to 5 minutes; the new spec.walRestoreRetryTimeout field (*metav1.Duration) lets operators tune it, and the admission webhook rejects zero or negative values so there is no silent opt-out of the protection.

@armru
armru requested a review from jsilvela as a code owner April 24, 2026 15:33
@armru
armru requested a review from a team April 24, 2026 15:33
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Apr 24, 2026
@armru armru added no-issue do not backport This PR must not be backported - it will be in the next minor release and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Apr 24, 2026
@armru

armru commented Apr 24, 2026

Copy link
Copy Markdown
Member Author

/test

@github-actions

Copy link
Copy Markdown
Contributor

@dosubot dosubot Bot added the enhancement 🪄 New feature or request label Apr 24, 2026
@cnpg-bot cnpg-bot added backport-requested ◀️ This pull request should be backported to all supported releases release-1.25 release-1.28 labels Apr 24, 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

@armru
armru force-pushed the dev/transient-errors branch from 359f3df to 1e97eb7 Compare April 24, 2026 15:39
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Apr 24, 2026
@armru
armru force-pushed the dev/transient-errors branch 2 times, most recently from 4510248 to a4a7600 Compare April 27, 2026 11:38
@armru

armru commented Apr 27, 2026

Copy link
Copy Markdown
Member Author

/test

@github-actions

Copy link
Copy Markdown
Contributor

@cnpg-bot cnpg-bot added the ok to merge 👌 This PR can be merged label Apr 27, 2026
@leonardoce
leonardoce force-pushed the dev/transient-errors branch from a4a7600 to 70c5353 Compare May 13, 2026 09:52
@dosubot dosubot Bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels May 13, 2026
@leonardoce
leonardoce force-pushed the dev/transient-errors branch 3 times, most recently from 38d415b to 8499979 Compare May 28, 2026 11:13
@leonardoce

Copy link
Copy Markdown
Contributor

/test

@cnpg-bot cnpg-bot added the ok to merge 👌 This PR can be merged label May 29, 2026
@leonardoce
leonardoce force-pushed the dev/transient-errors branch from b9a501b to 653d38a Compare May 29, 2026 15:10
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jun 3, 2026
@jbattiato
jbattiato force-pushed the dev/transient-errors branch 2 times, most recently from e6a0486 to 11f2b32 Compare June 10, 2026 13:33
@jbattiato
jbattiato force-pushed the dev/transient-errors branch from 11f2b32 to 7383275 Compare June 15, 2026 12:44
@leonardoce
leonardoce force-pushed the dev/transient-errors branch 3 times, most recently from 7edc6a5 to 3b653bb Compare June 16, 2026 11:32
@gbartolini

Copy link
Copy Markdown
Contributor

Is this related to EnterpriseDB/barman@4f43dc5?

@mnencia
mnencia force-pushed the dev/transient-errors branch from 2c92ab4 to 5337349 Compare November 2, 2026 19:33
@mnencia
mnencia requested a review from a team as a code owner November 2, 2026 19:33
@mnencia
mnencia force-pushed the dev/transient-errors branch from 5337349 to c30c179 Compare November 2, 2026 19:37
@mnencia

mnencia commented Nov 2, 2026

Copy link
Copy Markdown
Member

/test

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

@mnencia
mnencia force-pushed the dev/transient-errors branch from c30c179 to f86ab03 Compare November 3, 2026 14:36
armru and others added 6 commits November 3, 2026 17:17
Add spec.walRestoreRetryTimeout and a retry loop inside
`manager wal-restore` so that transient failures during WAL replay —
network blips, flaky object stores, plugin glitches — do not cause a
replica to promote on an incomplete archive and lose already-archived
transactions.

The command now classifies each attempt's outcome:
  * barman-cloud exit 0 or gRPC Ok    -> success (exit 0)
  * barman-cloud exit 1 or gRPC NotFound -> WAL not found (exit 1,
    unchanged; PostgreSQL can transition to streaming as before)
  * anything else -> transient, retry with exponential backoff up to
    retryBackoffCap (30s), within the user-configurable budget

If the budget is exhausted the command exits with code 255, which tells
PostgreSQL to stop log-shipping replication rather than promote on a
partial archive. The budget defaults to 5 minutes; the new
spec.walRestoreRetryTimeout field (*metav1.Duration) lets operators
tune it, and the admission webhook rejects zero or negative values so
there is no silent opt-out of the protection.

Signed-off-by: Armando Ruocco <[email protected]>
Signed-off-by: Leonardo Cecchi <[email protected]>
Signed-off-by: Leonardo Cecchi <[email protected]>
The wal-restore retry loop exits with code 143 so PostgreSQL detects a
SIGTERM and shuts down cleanly instead of promoting on a partial archive.
The failover and replication pages still documented the earlier 255; align
them with the implementation.

Signed-off-by: Armando Ruocco <[email protected]>
The decision of whether to retry transient WAL-restore failures (bootstrap
or target-primary of a standard cluster, and never a replica cluster) lived
inline in runWalRestore with no direct test. Move it into a pure
shouldRetryRestore function and add a table test covering the matrix,
including the replica-cluster cases that must not retry because the first
pod bootstraps in standby mode.

Also correct the resolveMaxRetryTimeout comment: non-positive values are
rejected by the field's CRD validation rule (a CEL XValidation), not by the
admission webhook.

Signed-off-by: Armando Ruocco <[email protected]>
A standby being promoted cannot know which WAL it still has to reach, so
the retry budget was a guess that could delay a failover by minutes
without a guarantee of any gain. Limit the retry to the bootstrap of a
standard cluster, where recovery from a backup needs the whole WAL chain.

Move the documentation to the recovery page and drop the promotion
wording from the API field and the failover and replication pages.

Signed-off-by: Marco Nenciarini <[email protected]>
@mnencia
mnencia force-pushed the dev/transient-errors branch from fe6a141 to b3cfa51 Compare November 3, 2026 16:19
@mnencia

mnencia commented Nov 4, 2026

Copy link
Copy Markdown
Member

Closing this one. After discussing it with Leonardo, we think the retry covers a problem that needs to be solved at a different level. The instance manager can't tell a missing WAL from a failed restore by looking at barman exit codes or gRPC status codes, and plugins don't agree on what they return for a missing WAL. A retry budget on top of that is a guess. During a promotion it also delays the failover without knowing which WAL the instance still has to reach.

The better fix is to define the CNPG-I WAL interface more precisely, so a plugin can say whether the WAL is missing, the failure is retryable, or the restore failed, and drive the return code itself. That work starts in CNPG-I.

Thanks Armando and Leonardo for the work and the reviews.

@mnencia mnencia closed this Nov 4, 2026
@mnencia
mnencia deleted the dev/transient-errors branch November 4, 2026 10:20
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 do not backport This PR must not be backported - it will be in the next minor release enhancement 🪄 New feature or request lgtm This PR has been approved by a maintainer no-issue ok to merge 👌 This PR can be merged release-1.28 release-1.30 size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants