Skip to content

[FLINK-40475][runtime] Fix watermark loss and stall in StatusWatermarkValve when subpartitions realign after idleness - #29024

Merged
MartijnVisser merged 2 commits into
apache:masterfrom
MartijnVisser:FLINK-40475
Aug 28, 2026
Merged

[FLINK-40475][runtime] Fix watermark loss and stall in StatusWatermarkValve when subpartitions realign after idleness#29024
MartijnVisser merged 2 commits into
apache:masterfrom
MartijnVisser:FLINK-40475

Conversation

@MartijnVisser

Copy link
Copy Markdown
Contributor

What is the purpose of the change

When a subpartition of StatusWatermarkValve reactivates after idleness and rejoins the aligned set, the min watermark across aligned subpartitions is not re-derived. This breaks the invariant that the aligned min equals the last output watermark, which two guards (subpartitionStatus.watermark == lastOutputWatermark) silently rely on, with two symptoms:

  1. The all-idle flush-to-max from FLINK-7728 is skipped when the last subpartition to become idle is unaligned (went idle, resumed, only partially caught up), making the final watermark dependent on the order in which inputs became idle — the exact defect FLINK-7728 was created to fix. This also diverges from CombinedWatermarkStatus, which flushes unconditionally since FLINK-38454.
  2. A subpartition that reactivates as the only aligned subpartition has its watermark stalled indefinitely, until an even larger watermark arrives on that subpartition — no all-idle transition involved.

Brief change log

  • Re-derive (and possibly emit) the min watermark at the end of the idle→active branch, after the ACTIVE status is emitted so downstream inputs do not drop the watermark while they still consider the input idle
  • Flush the max watermark unconditionally when all subpartitions become idle (the flush helper already only emits when the max advances past the last output watermark, so monotonicity is unaffected)
  • Drop the equivalent guard on the partial-idle min re-derivation for the same reason
  • Document the invariants of the aligned-subpartition set on alignedSubpartitionStatuses

Verifying this change

This change added tests and can be verified as follows:

  • Added testMultipleInputFlushMaxWatermarkOnceAllInputsBecomeIdleWithUnalignedLastChannel, reproducing the order-dependent all-idle flush (fails on master: emits only WatermarkStatus(IDLE) instead of Watermark(100))
  • Added testWatermarkAdvancesWhenReactivatedChannelBecomesOnlyAlignedChannel and testRealignmentAfterResumeActiveEmitsNewMinWatermark, reproducing the stalled watermark on realignment (fail on master: no watermark emitted)
  • All pre-existing tests in StatusWatermarkValveTest are unaffected; also verified green: OneInputStreamTaskTest, TwoInputStreamTaskTest, WatermarkOutputMultiplexerTest, SourceOperatorSplitWatermarkAlignmentTest
  • Each commit passes the valve test suite individually (red-green verified per commit)

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): no
  • The public API, i.e., is any changed class annotated with @Public(Evolving): no
  • The serializers: no
  • The runtime per-record code paths (performance sensitive): no (only watermark-status transition paths; the added re-derivation is O(1), the unconditional flush is O(#subpartitions) once per all-idle transition, next to an existing O(#subpartitions) scan on the same path)
  • Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
  • The S3 file system connector: no

Documentation

  • Does this pull request introduce a new feature? no
  • If yes, how is the feature documented? not applicable

Note on behavior: jobs that previously ended with a lower watermark depending on idle-arrival order will now deterministically receive the flushed max watermark (timers/windows in that range fire); a release note is proposed on the JIRA ticket.


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: Claude Code (claude-fable-5)

…StatusWatermarkValve become idle

Previously the flush introduced by FLINK-7728 was skipped unless the last
subpartition to become idle held the current min watermark. When the last
subpartition to become idle was unaligned - it went idle, resumed being
active, and only partially caught up to the last output watermark - the
flush was skipped and the final watermark depended on the order in which
the inputs became idle: the exact defect FLINK-7728 was created to fix.

The guard was not a valid optimization, because the assumption behind it
(the min watermark was already advanced as subpartitions individually
became idle) does not hold when unaligned subpartitions are involved.
Removing it cannot regress the output watermark, since
findAndOutputMaxWatermarkAcrossAllSubpartitions only emits when the max
advances past the last output watermark. This also makes the valve
consistent with CombinedWatermarkStatus, which flushes unconditionally
since FLINK-38454.

Generated-by: Claude Code (claude-fable-5)
…aligns after idleness

The emission logic of StatusWatermarkValve relies on the invariant that,
whenever the set of watermark-aligned subpartitions is non-empty, its min
watermark equals the last output watermark. The idle->active branch broke
this invariant: it re-added a caught-up subpartition to the aligned set
without re-deriving the min. When no other aligned subpartition remained,
the realigned subpartition's watermark was stalled indefinitely - it was
only emitted once an even larger watermark arrived on that subpartition.

Re-derive (and possibly emit) the min watermark after the reactivation,
after the ACTIVE status was emitted so that downstream inputs do not drop
the watermark while they still consider the input idle. Also drop the
equivalent guard on the partial-idle path, which silently depended on the
unbroken invariant, and document the invariants on the aligned set.

Generated-by: Claude Code (claude-fable-5)
@flinkbot

flinkbot commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

CI report:

Bot commands The @flinkbot bot supports the following commands:
  • @flinkbot run azure re-run the last Azure build

@rkhachatryan rkhachatryan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the fix!

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.

4 participants