Repository navigation
fix(instance-manager): stop renewing the primary lease when a replica stops being the target - #11677
Merged
Merged
Conversation
mnencia
force-pushed
the
dev/primary-lease-yield
branch
from
October 17, 2026 17:15
d4f08d8 to
18e65d9
Compare
Member
Author
|
/test |
Contributor
|
@mnencia, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/39053080740 |
Member
Author
mnencia
force-pushed
the
dev/primary-lease-yield
branch
from
October 18, 2026 20:41
18e65d9 to
a8457b5
Compare
Member
Author
|
/test |
Contributor
|
@mnencia, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/39164576801 |
Member
Author
mnencia
force-pushed
the
dev/primary-lease-yield
branch
2 times, most recently
from
October 19, 2026 15:22
4a7da3a to
406efb7
Compare
mnencia
marked this pull request as ready for review
October 19, 2026 15:24
Member
Author
|
/test |
Contributor
|
@mnencia, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/39277782536 |
mnencia
force-pushed
the
dev/primary-lease-yield
branch
from
October 19, 2026 15:54
406efb7 to
129d014
Compare
armru
force-pushed
the
dev/primary-lease-yield
branch
from
October 21, 2026 09:29
129d014 to
0c24df0
Compare
armru
approved these changes
Oct 21, 2026
mnencia
force-pushed
the
dev/primary-lease-yield
branch
2 times, most recently
from
October 21, 2026 15:53
9402a7c to
1e36f33
Compare
Contributor
|
Related to #11721 |
mnencia
force-pushed
the
dev/primary-lease-yield
branch
from
October 22, 2026 09:10
1e36f33 to
082d562
Compare
…arget A replica named target primary takes the primary lease and keeps renewing it even when the operator moves the target to another replica before it promotes. The new target sees a record that keeps changing, so its observation window never completes and the cluster has no primary until that replica restarts. The lease runnable never stops renewing a record that names this pod. The instance reconciler now asks the lease runnable to yield when this pod is not the target primary, PostgreSQL is in recovery and no promotion was requested in this process. This runs before the early returns for a fenced or down instance, in the same single-worker reconcile that promotes, so it never interleaves with a promotion. A promotion that failed leaves the pod unable to yield for the rest of the process, which is the safe side. Yield stops the renewal loop and the step-down monitor and writes nothing. The record keeps naming this pod and goes stale, so the new target takes it over after the normal observation window, not through the empty-holder fast path that stays reserved for a primary that stopped cleanly. A yielded pod that exits leaves the record as it is. A write already in flight can still land once, which restarts the window once. The next `Acquire`, which only the target primary makes, takes the lease back. A reconcile blocked in `Acquire` cannot yield until it returns. Assisted-by: Claude Signed-off-by: Marco Nenciarini <[email protected]>
Every replica that is not the target primary yields on each reconcile, so at exit Release found the yield flag set on almost every replica and logged at Info that it was leaving the record for a new target, even on pods that never held the lease. The yield already logs at Info when it gives up a lease this pod held, so the exit line moves to Debug. The comment on the yield in Reconcile said it ran before any early return, while the certificate, admission and plugin checks can return before it. It now names the returns it precedes. Signed-off-by: Armando Ruocco <[email protected]>
mnencia
force-pushed
the
dev/primary-lease-yield
branch
from
October 22, 2026 16:01
082d562 to
7bc9828
Compare
A yielded replica keeps polling the lease, and that is what keeps the liveness watchdog fed once the lease has been held. Nothing asserted it. Assisted-by: Claude Signed-off-by: Marco Nenciarini <[email protected]>
Signed-off-by: Leonardo Cecchi <[email protected]>
leonardoce
approved these changes
Oct 23, 2026
The model made a claim lead at once, so a replica that holds the lease without having promoted could not be expressed. A claim now only holds the lease, and leading needs a promotion request and a later completion. A holder that lost the target before asking to promote yields: it stops renewing and leaves the record to go stale for the new target. NoTwoLeaders still holds, and it fails without the promotion request guard on the yield. MaxRounds drops from 15 to 12 to keep the check within a few minutes. Assisted-by: Claude Signed-off-by: Marco Nenciarini <[email protected]>
leonardoce
approved these changes
Oct 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A replica named target primary takes the primary lease and keeps renewing it even when the operator moves the target to another replica before it promotes. The new target sees a record that keeps changing, so its observation window never completes and the cluster has no primary until that replica restarts. The lease runnable never stops renewing a record that names this pod.
The instance reconciler now asks the lease runnable to yield when this pod is not the target primary, PostgreSQL is in recovery and no promotion was requested in this process. This runs before the early returns for a fenced or down instance, in the same single-worker reconcile that promotes, so it never interleaves with a promotion. A promotion that failed leaves the pod unable to yield for the rest of the process, which is the safe side.
Yield stops the renewal loop and the step-down monitor and writes nothing. The record keeps naming this pod and goes stale, so the new target takes it over after the normal observation window, not through the empty-holder fast path that stays reserved for a primary that stopped cleanly. A yielded pod that exits leaves the record as it is. A write already in flight can still land once, which restarts the window once. The next
Acquire, which only the target primary makes, takes the lease back. A reconcile blocked inAcquirecannot yield until it returns.Closes #11736
Reviewer notes
No e2e covers this yet, because the scenario needs a replica held back before it promotes and a second target flip inside that window, which would be flaky; the unit specs cover the runnable (including a second runnable taking the lease over) and the reconciler decision. An earlier, larger version of the same fix was part of #11357 and was moved out to keep that PR smaller.