Skip to content

fix(walrestore): serve pg_rewind without prefetching and flag machinery#1007

Open
armru wants to merge 2 commits into
mainfrom
dev/rewind-restore-mode
Open

fix(walrestore): serve pg_rewind without prefetching and flag machinery#1007
armru wants to merge 2 commits into
mainfrom
dev/rewind-restore-mode

Conversation

@armru

@armru armru commented Jul 15, 2026

Copy link
Copy Markdown
Member

When a demoted primary rejoins the cluster after a failover, the instance manager runs pg_rewind --restore-target-wal, and the resulting restore_command invocations are served by this sidecar exactly as if an instance in recovery were asking. pg_rewind walks the timeline backwards, fetches every WAL file it needs exactly once, and treats any restore failure as fatal, so two optimizations meant for recovery break it: prefetching the following segments is wasted work that, past the end of the timeline, is guaranteed to end in an archive miss, and the end-of-wal-stream flag recorded by that miss makes a later invocation fail without contacting the object store, on a segment the archive actually has, aborting the whole rewind.

The restore request now carries the context it is made in (cloudnative-pg/cnpg-i#351). When it says MODE_REWIND, the sidecar restores exactly the requested file: no prefetching, no end-of-wal-stream flag check, no flag recording. Requests from operators predating the field keep the current behavior.

This is the plugin-side counterpart of cloudnative-pg/cloudnative-pg#11204. The cnpg-i dependency points to a pseudo-version of the protocol pull request and will move to the next tagged release once it is available.

@armru
armru requested a review from a team as a code owner July 15, 2026 13:21
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working go Pull requests that update go code labels Jul 15, 2026
@mnencia
mnencia force-pushed the dev/rewind-restore-mode branch from 549588f to 272051d Compare July 17, 2026 08:43
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jul 17, 2026
armru and others added 2 commits July 17, 2026 12:10
The operator now tells WAL restore plugins when a restore request is
made on behalf of pg_rewind (cloudnative-pg/cnpg-i#351). pg_rewind walks
the timeline backwards, fetches every WAL file it needs exactly once,
and treats any restore failure as fatal, so both optimizations meant for
an instance in recovery must stay off: prefetching the following
segments is wasted work that ends in an archive miss, and the
end-of-wal-stream flag recorded by such a miss makes a later invocation
fail on a segment that is available in the archive, aborting the whole
rewind.

The cnpg-i dependency points to a pseudo-version of that pull request
and will be moved to the next tagged release once it is available.

Ref: cloudnative-pg/cloudnative-pg#11200
Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
…machinery

Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
@mnencia
mnencia force-pushed the dev/rewind-restore-mode branch from bf32c44 to 616a9a0 Compare July 17, 2026 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants