Skip to content

Conversation

LiShuMing
Copy link
Contributor

@LiShuMing LiShuMing commented Oct 13, 2025

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:

  • Added new fields lastScheduleTime and nextScheduleTime to the Task class, along with their getters, setters, and updates to the toString() method for better visibility and tracking of when tasks are scheduled and when they will run next. (Task.java) [1] [2] [3]
  • Updated the scheduling logic in 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:

  • Refactored the calculation of initial delay for periodic tasks to consider the last schedule time, improving reliability especially after frequent system restarts. The test cases were updated to reflect the new method signature. (TaskManager.java, TaskManagerTest.java) [1] [2] [3]

Long-running task handling and thread safety:

  • Improved management of long-running tasks by adding a mechanism to remove timeout task runs and making sure task cancellation methods are clearly marked as not thread-safe, with explicit locking and error handling to prevent resource waste. (TaskManager.java, TaskRunManager.java) [1] [2] [3] [4]

Defensive coding and null checks:

  • Added null checks and defensive coding in TaskRunFIFOQueue and TaskRunScheduler 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:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 4.0
    • 3.5
    • 3.4
    • 3.3

Copy link

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

[FE Incremental Coverage Report]

fail : 5 / 57 (08.77%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/scheduler/TaskManager.java 2 54 03.70% [295, 531, 533, 534, 535, 536, 537, 538, 539, 540, 543, 544, 545, 546, 549, 550, 551, 552, 553, 554, 559, 560, 561, 562, 563, 565, 566, 567, 568, 569, 570, 573, 574, 575, 577, 578, 580, 581, 582, 583, 585, 586, 587, 588, 589, 590, 593, 597, 598, 599, 600, 601]
🔵 com/starrocks/scheduler/Task.java 3 3 100.00% []

Copy link

[BE Incremental Coverage Report]

pass : 0 / 0 (0%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant