[FLINK-40114][runtime] Don't erase leader information while a confirmation is pending#28748
Open
prashantbh wants to merge 1 commit into
Open
[FLINK-40114][runtime] Don't erase leader information while a confirmation is pending#28748prashantbh wants to merge 1 commit into
prashantbh wants to merge 1 commit into
Conversation
Collaborator
…ation is pending Generated-by: Claude Code (Claude Opus 4.8)
prashantbh
force-pushed
the
flink-40114-leaderelection-race
branch
from
July 15, 2026 14:28
d9a556c to
93d9e1e
Compare
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.
What is the purpose of the change
Fixes a regression from FLINK-36451 that can permanently erase a component's leader information from the HA backend after a leadership loss and re-acquisition.
Mechanism: leadership is granted once per process (a single
issuedLeaderSessionID), but each component (restserver, dispatcher, jobmanager, resourcemanager) confirms its own leader information asynchronously onleadershipOperationExecutor, while leader-information change events are handled synchronously innotifyLeaderInformationChangeInternal. After re-acquiring leadership a component is granted but not yet confirmed, so itsconfirmedLeaderInformationis empty. A change event in that window takes theconfirmedLeaderInformation.isEmpty()branch and publishes empty, which on Kubernetes removes the component's key. The self-correcting rewrite only runs once a confirmation exists, so the erased entry is not restored until a subsequent confirmation succeeds, and remains erased if none does.The change event is typically self-inflicted: all components share one ConfigMap, so when one component confirms (e.g. the dispatcher), that write fires a watch event evaluated against every other component, including one whose confirmation hasn't landed yet and whose stale prior-session entry is then reset to empty.
Impact: the JobManager keeps running as a healthy leader while its external entry is gone. The REST endpoint cannot be resolved (restserver), or job submission and TaskManager registration fail (dispatcher/jobmanager), with no self-recovery.
Brief change log
DefaultLeaderElectionService#notifyLeaderInformationChangeInternal: theconfirmedLeaderInformation.isEmpty()branch now returns instead of publishing empty. That branch reset the external value on the assumption thatconfirmed == emptymeans "not leader", which only held under synchronous confirmation; with async confirmation it also means "leader, but not yet confirmed", so deleting acts on a transient state and destroys still-valid information. Returning is safe: if we hold the lock a pending (session-fenced) confirmation overwrites any stale value, and if we do not, the write would no-op anyway. Intentional cleanup is unchanged (remove->deleteLeaderInformation).Verifying this change
Added tests that use
ManuallyTriggeredScheduledExecutorServiceto hold a confirmation while a change event is injected; they fail without the fix and pass with it:testLeaderInformationChangeDoesNotEraseComponentWithInflightConfirmation: a change event during an outstanding confirmation must not erase the entry; it self-heals once the confirmation runs.testLeaderInformationChangeDoesNotEraseComponentAfterReacquisition: loss and re-acquisition with a new session; the prior session's entry must not be erased and self-heals to the new session.testGrantDoesNotBlockNotifyLeaderInformationChangeand...AllKnownLeaderInformationto assert non-erasure for bothonLeaderInformationChangeoverloads.LeaderChangeClusterComponentsTest) and theflink-kubernetesHA unit tests.Does this pull request potentially affect one of the following parts:
@Public(Evolving): noDocumentation
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Claude Opus 4.8)