-
Notifications
You must be signed in to change notification settings - Fork 13.9k
[optimised][FLINK-34252][table] Fix lastRecordTime tracking in WatermarkAssignerOperator #24941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
1996fanrui
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @pnowojski for picking up this PR!
I left some minor comments, please take a look in your free time, thanks~
...ain/java/org/apache/flink/table/runtime/operators/wmassigners/WatermarkAssignerOperator.java
Show resolved
Hide resolved
| emitWatermarkStatus(WatermarkStatus.IDLE); | ||
| } | ||
| if (watermarkInterval > 0 | ||
| && lastWatermarkPeriodicEmitTime + watermarkInterval <= timestamp) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the comment said, timestamp and now may be different. I'm curious, why using timestamp instead of now here?
If the timer is triggered later, and lastWatermarkPeriodicEmitTime + watermarkInterval may be less than now, but greater than timestamp. For this case, we could advanceWatermark, right?
It means we can use now directly. For old code, it uses currentTime as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Goog point I think. I will try to switch to now and let's see if some tests will complain or not.
| if (processedElements != lastIdleCheckProcessedElements) { | ||
| idleSince = now; | ||
| } | ||
| lastIdleCheckProcessedElements = processedElements; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (processedElements != lastIdleCheckProcessedElements) { | |
| idleSince = now; | |
| } | |
| lastIdleCheckProcessedElements = processedElements; | |
| if (processedElements != lastIdleCheckProcessedElements) { | |
| idleSince = now; | |
| lastIdleCheckProcessedElements = processedElements; | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't matter, does it? But anyway 👍
...ain/java/org/apache/flink/table/runtime/operators/wmassigners/WatermarkAssignerOperator.java
Show resolved
Hide resolved
...ain/java/org/apache/flink/table/runtime/operators/wmassigners/WatermarkAssignerOperator.java
Outdated
Show resolved
Hide resolved
1996fanrui
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @pnowojski for the quick update!
LGTM assuming CI is green.
The 1.20 starts feature freeze, but this PR is a bugfix. So I think we can merge it. Also, it's better to backport this fix to 1.17, 1.18 and 1.19.
pnowojski
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ops, I forgot to publish responses.
...ain/java/org/apache/flink/table/runtime/operators/wmassigners/WatermarkAssignerOperator.java
Outdated
Show resolved
Hide resolved
| if (processedElements != lastIdleCheckProcessedElements) { | ||
| idleSince = now; | ||
| } | ||
| lastIdleCheckProcessedElements = processedElements; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't matter, does it? But anyway 👍
…Operator to prevent erroneous idle WatermarkStatus
…id calling System.currentTimeMillis per every record
This is an optimised version of #24211 that supersedes it. This newer version avoids having to check current time per each record, as syscalls are quite expensive.
What is the purpose of the change
In the current implementation, the lastRecordTime variable, which tracks the time of the last received data element, is updated only when the WatermarkStatus transitions from IDLE to ACTIVE. However, it is not updated when WatermarkStatus is ACTIVE, which means even under continuous data flow, the condition
(currentTime - lastRecordTime > idleTimeout)will eventually always become true, and the WatermarkStatus will erroneously be marked IDLE.I believe this bug technically causes incorrect outputs since downstream watermarks advance earlier than they otherwise would. The incorrect state doesn't last forever, though, since when the WatermarkStatus is in in the IDLE state, the next processElement will cause a WatermarkStatus.ACTIVE to be emitted.
The new unit test illustrates the flip-flop behavior before the fix:
Brief change log
Verifying this change
This change added tests and can be verified as follows:
Does this pull request potentially affect one of the following parts:
@Public(Evolving): (no)Documentation