Skip to content

fix(restorer): scope end-of-WAL markers by WAL timeline#277

Open
ardentperf wants to merge 2 commits into
cloudnative-pg:mainfrom
ardentperf:pr-fix-end-of-wal
Open

fix(restorer): scope end-of-WAL markers by WAL timeline#277
ardentperf wants to merge 2 commits into
cloudnative-pg:mainfrom
ardentperf:pr-fix-end-of-wal

Conversation

@ardentperf

Copy link
Copy Markdown

Add timeline-aware end-of-WAL marker handling to pkg/restorer.WALRestorer. The previous global end-of-wal-stream marker could be set by a prefetch miss on one timeline and consumed by a later restore request on another timeline. In CNPG restore flows, that can make PostgreSQL skip a valid child-timeline WAL lookup and replay wrong parent-timeline bytes.

The legacy global APIs remain as compatibility shims, but new consumers should use the WAL/result-oriented APIs.

WALRestorer now owns the full policy:

  • only regular WAL segment misses set end-of-WAL markers
  • markers are scoped by timeline
  • non-WAL names do not create or consume markers
  • legacy global marker files are removed during consume, but are not trusted

Tests included. In addition to local tests, I also verified with a full E2E test https://github.com/ardentperf/bug-repro-wal-restore

Fixes #276

@ardentperf ardentperf requested a review from a team as a code owner July 6, 2026 15:45
Add timeline-aware end-of-WAL marker handling to
`pkg/restorer.WALRestorer`. The previous global `end-of-wal-stream`
marker could be set by a prefetch miss on one timeline and consumed by a
later restore request on another timeline. In CNPG restore flows, that
can make PostgreSQL skip a valid child-timeline WAL lookup and replay
wrong parent-timeline bytes.

Signed-off-by: Jeremy Schneider <schneider@ardentperf.com>
@ardentperf ardentperf force-pushed the pr-fix-end-of-wal branch from 56471f8 to 1953fc7 Compare July 6, 2026 15:53
ardentperf added a commit to ardentperf/cloudnative-pg that referenced this pull request Jul 6, 2026
Update in-tree `wal-restore` to use the new `barman-cloud` restorer
APIs, resolving a bug that can cause replicas to enter a broken state
that CNPG cant recover from. Local marker naming, WAL timeline parsing,
and restore-result filtering policy now lives in
`github.com/cloudnative-pg/barman-cloud/pkg/restorer`. depends on
cloudnative-pg/barman-cloud#277

Signed-off-by: Jeremy Schneider <schneider@ardentperf.com>
Route the legacy marker cleanup in ConsumeEndOfWALStreamForWAL through
the private marker helpers instead of the deprecated exported methods,
so the deprecated API can later be removed without touching this path.

timelineFromWALName can only fail with ErrInvalidWALName, so collapse
the callers' two-step error handling into a single check and document
that contract on the function itself.

Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
armru added a commit to ardentperf/cloudnative-pg that referenced this pull request Jul 8, 2026
…e-pg#277

Point barman-cloud at the fork branch behind
cloudnative-pg/barman-cloud#277 so this PR builds and CI can run, and
allow the replace directive in the linter configuration. Both changes
must be reverted in favor of an upstream barman-cloud release when
merging.

Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
armru added a commit to ardentperf/plugin-barman-cloud that referenced this pull request Jul 8, 2026
…e-pg#277

Point barman-cloud at the fork branch behind
cloudnative-pg/barman-cloud#277 so this PR builds and CI can run, and
allow the replace directive in the linter configuration. Both changes
must be reverted in favor of an upstream barman-cloud release when
merging.

Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
armru pushed a commit to ardentperf/cloudnative-pg that referenced this pull request Jul 8, 2026
Update in-tree `wal-restore` to use the new `barman-cloud` restorer
APIs, resolving a bug that can cause replicas to enter a broken state
that CNPG cant recover from. Local marker naming, WAL timeline parsing,
and restore-result filtering policy now lives in
`github.com/cloudnative-pg/barman-cloud/pkg/restorer`. depends on
cloudnative-pg/barman-cloud#277

Signed-off-by: Jeremy Schneider <schneider@ardentperf.com>
armru added a commit to ardentperf/cloudnative-pg that referenced this pull request Jul 8, 2026
…e-pg#277

Point barman-cloud at the fork branch behind
cloudnative-pg/barman-cloud#277 so this PR builds and CI can run, and
allow the replace directive in the linter configuration. Both changes
must be reverted in favor of an upstream barman-cloud release when
merging.

Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Timeline-blind end-of-WAL marker can poison WAL restore after timeline switch

2 participants