Skip to content

fix(backup): start a Backup only once - #11617

Merged
litaocdl merged 10 commits into
mainfrom
dev/11616
Oct 14, 2026
Merged

litaocdl merged 10 commits into
mainfrom
dev/11616

Conversation

@mnencia

@mnencia mnencia commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

A second reconciliation working from a stale cached Backup could ask the instance manager to run it again, start a volume snapshot backup again, or move a started backup back to pending. Make the status patches that mark the backup as started or pending conditional on the resourceVersion that was read, and requeue on conflict. The major version is now persisted by the start patches, and the Starting event is emitted only once that patch succeeds.

Closes #11616

@mnencia
mnencia requested a review from a team as a code owner October 6, 2026 12:42
@cnpg-bot cnpg-bot added backport-requested ◀️ This pull request should be backported to all supported releases release-1.28 release-1.30 labels Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026

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

@mnencia
mnencia force-pushed the dev/11616 branch 3 times, most recently from cc2ffc1 to 60c22ac Compare October 7, 2026 16:10
@mnencia

mnencia commented Oct 7, 2026

Copy link
Copy Markdown
Member Author

/test

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

@cnpg-bot cnpg-bot added the ok to merge 👌 This PR can be merged label Oct 7, 2026
@mnencia

mnencia commented Oct 8, 2026

Copy link
Copy Markdown
Member Author

/test

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

@mnencia

mnencia commented Oct 8, 2026

Copy link
Copy Markdown
Member Author

/test

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

mnencia and others added 10 commits October 13, 2026 17:47
A second reconciliation working from a stale cached Backup could ask
the instance manager to run it again. Make the status patch that marks
the backup as started conditional on the resourceVersion that was read,
and requeue on conflict. The major version is now persisted by that
same patch.

Closes #11616

Signed-off-by: Marco Nenciarini <[email protected]>
The comment claimed that patching the major version would refresh the
Backup. It does not: the extra write only bumps the resourceVersion, so
the start patch, locked on the version read by this reconciliation,
would conflict with our own write.

Signed-off-by: Armando Ruocco <[email protected]>
The test seam for running the backup command was a package variable
swapped by the tests. Make it a field of the reconciler, set by
NewBackupReconciler, as the instance status client already is, so a
test configures it on the reconciler it builds.

Signed-off-by: Armando Ruocco <[email protected]>
The Starting log line and event were emitted before the patch that
marks the backup as started. A reconciliation that lost the race on a
stale read, or whose patch failed, still announced a start, so the
event count kept looking like a double start. Emit them after the
patch succeeds, and log the conflict at debug level instead.

Signed-off-by: Armando Ruocco <[email protected]>
Three paths patch a backup back to pending: the target Pod missing or
not reporting its status, the target not ready, and another backup of
the cluster in progress. The patch took no lock, so a reconciliation
working from a stale cached Backup could overwrite the started phase
written by the one that ran it, or a completed phase written by the
instance manager once the cache caught up before listing the cluster
backups. Lock that patch on the resourceVersion that was read, as the
start patch already is, and requeue on conflict.

Signed-off-by: Armando Ruocco <[email protected]>
A reconciliation that loses the optimistic lock no longer reports a
backup that is already running as waiting for its target pod. The
callers handle the conflict and log it at debug level.

Signed-off-by: Marco Nenciarini <[email protected]>
Remove the control spec and the fixtures no spec needs, and put back the
GetStatus call, the patchErr name and the blank line that the earlier
commits changed without need.

Signed-off-by: Marco Nenciarini <[email protected]>
A stale read could start a volume snapshot backup again, or move a
started one back to pending. Lock the start patch and the remaining
pending patches on the version that was read. Both start patches now
store the major version, so reconcileMajorVersion is removed.

Signed-off-by: Marco Nenciarini <[email protected]>
The ReStarting events were emitted while checking whether the running
backup was still valid, before the start patch. A reconciliation working
from a stale cached Backup announced a restart that then lost the
optimistic lock and never ran, and a volume snapshot backup, which is
never restarted, got the event as well. Emit ReStarting from the
instance manager start, once the patch succeeds and only when the backup
had already been started on a pod, and log the reason of the restart
where it is detected.

The volume snapshot spec now also checks that a stale reconciliation
stops before taking the snapshot, not only that it requeues.

Signed-off-by: Armando Ruocco <[email protected]>
@litaocdl
litaocdl merged commit 88137ac into main Oct 14, 2026
@litaocdl
litaocdl deleted the dev/11616 branch October 14, 2026 03:24
cnpg-bot pushed a commit that referenced this pull request Oct 14, 2026
A second reconciliation working from a stale cached Backup could ask the
instance manager to run it again, start a volume snapshot backup again,
or move a started backup back to pending. Make the status patches that
mark the backup as started or pending conditional on the resourceVersion
that was read, and requeue on conflict. The major version is now
persisted by the start patches, and the Starting event is emitted only
once that patch succeeds.

Closes #11616

---------

Signed-off-by: Marco Nenciarini <[email protected]>
Signed-off-by: Armando Ruocco <[email protected]>
Co-authored-by: Armando Ruocco <[email protected]>
(cherry picked from commit 88137ac)
mnencia added a commit that referenced this pull request Oct 14, 2026
A second reconciliation working from a stale cached Backup could ask the
instance manager to run it again, start a volume snapshot backup again,
or move a started backup back to pending. Make the status patches that
mark the backup as started or pending conditional on the resourceVersion
that was read, and requeue on conflict. The major version is now
persisted by the start patches, and the Starting event is emitted only
once that patch succeeds.

Closes #11616

---------

Signed-off-by: Marco Nenciarini <[email protected]>
Signed-off-by: Armando Ruocco <[email protected]>
Co-authored-by: Armando Ruocco <[email protected]>
(cherry picked from commit 88137ac)
Signed-off-by: Marco Nenciarini <[email protected]>
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 ok to merge 👌 This PR can be merged release-1.28 release-1.30

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Backup controller can start the same Backup twice

4 participants