[BugFix] Fix task fail to schedule if fe restarts frequently #63966
+248
−34
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.
Why I'm doing:
if fe restarts frequently, use currentDateTime and taskStartTime can always generate a time of the future
which can cause the task never to be scheduled.
so use lastScheduleTime to check if the last schedule + period is before current time to avoid this.
What I'm doing:
This pull request introduces several improvements to the task scheduling system, focusing on more robust tracking and management of task scheduling times, better handling of long-running tasks, and enhanced thread safety. The changes also include improvements to the calculation of initial delay times for periodic tasks and add defensive coding to avoid null pointer issues.
Task scheduling and time tracking:
lastScheduleTime
andnextScheduleTime
to theTask
class, along with their getters, setters, and updates to thetoString()
method for better visibility and tracking of when tasks are scheduled and when they will run next. (Task.java
) [1] [2] [3]TaskManager
to set and update these time fields whenever a periodic task is scheduled or executed, ensuring accurate tracking across system restarts and executions. (TaskManager.java
) [1] [2]Periodic task scheduling logic:
TaskManager.java
,TaskManagerTest.java
) [1] [2] [3]Long-running task handling and thread safety:
TaskManager.java
,TaskRunManager.java
) [1] [2] [3] [4]Defensive coding and null checks:
TaskRunFIFOQueue
andTaskRunScheduler
to avoid null pointer exceptions when counting tasks or iterating over collections. (TaskRunFIFOQueue.java
,TaskRunScheduler.java
) [1] [2]Fixes #issue
What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist:
Bugfix cherry-pick branch check: