-
Notifications
You must be signed in to change notification settings - Fork 13.8k
[FLINK-38932][runtime] Fix incorrect scheduled timestamp in ProcessingTimeCallback with scheduleWithFixedDelay #27429
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -141,7 +141,7 @@ public ScheduledFuture<?> scheduleWithFixedDelay( | |
| private ScheduledFuture<?> scheduleRepeatedly( | ||
| ProcessingTimeCallback callback, long initialDelay, long period, boolean fixedDelay) { | ||
| final long nextTimestamp = getCurrentProcessingTime() + initialDelay; | ||
| final Runnable task = wrapOnTimerCallback(callback, nextTimestamp, period); | ||
| final Runnable task = wrapOnTimerCallback(callback, nextTimestamp, period, fixedDelay); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am checking the logic on the first time - I would expect the initial delay to take effect, then subsequent time the fixed delay. As the code is written the first time we get the initial plus the fixed delay, can you confirm this is what you want?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The initial delay is accounted when calling scheduleRepeatedly, where nextTimestamp is initialized to getCurrentProcessingTime() + initialDelay
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi David, I've added UTs to check the timestamps for both scheduleAtFixedRate& scheduleWithFixedDelay. |
||
|
|
||
| // we directly try to register the timer and only react to the status on exception | ||
| // that way we save unnecessary volatile accesses for each timer | ||
|
|
@@ -281,12 +281,13 @@ interface ExceptionHandler { | |
| } | ||
|
|
||
| private Runnable wrapOnTimerCallback(ProcessingTimeCallback callback, long timestamp) { | ||
| return new ScheduledTask(status, exceptionHandler, callback, timestamp, 0); | ||
| return new ScheduledTask(status, exceptionHandler, callback, timestamp, 0, false); | ||
| } | ||
|
|
||
| private Runnable wrapOnTimerCallback( | ||
| ProcessingTimeCallback callback, long nextTimestamp, long period) { | ||
| return new ScheduledTask(status, exceptionHandler, callback, nextTimestamp, period); | ||
| ProcessingTimeCallback callback, long nextTimestamp, long period, boolean fixedDelay) { | ||
| return new ScheduledTask( | ||
| status, exceptionHandler, callback, nextTimestamp, period, fixedDelay); | ||
| } | ||
|
|
||
| private static final class ScheduledTask implements Runnable { | ||
|
|
@@ -296,18 +297,21 @@ private static final class ScheduledTask implements Runnable { | |
|
|
||
| private long nextTimestamp; | ||
| private final long period; | ||
| private final boolean fixedDelay; | ||
|
|
||
| ScheduledTask( | ||
| AtomicInteger serviceStatus, | ||
| ExceptionHandler exceptionHandler, | ||
| ProcessingTimeCallback callback, | ||
| long timestamp, | ||
| long period) { | ||
| long period, | ||
| boolean fixedDelay) { | ||
| this.serviceStatus = serviceStatus; | ||
| this.exceptionHandler = exceptionHandler; | ||
| this.callback = callback; | ||
| this.nextTimestamp = timestamp; | ||
| this.period = period; | ||
| this.fixedDelay = fixedDelay; | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -320,7 +324,8 @@ public void run() { | |
| } catch (Exception ex) { | ||
| exceptionHandler.handleException(ex); | ||
| } | ||
| nextTimestamp += period; | ||
| nextTimestamp = | ||
| fixedDelay ? System.currentTimeMillis() + period : nextTimestamp + period; | ||
| } | ||
| } | ||
| } | ||
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.
Please could you add a test for this change
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.
Sure