[bugfix] Preserve millisecond precision for cyclic collect intervals (#2405) by xdn-code · Pull Request #4420 · apache/hertzbeat · GitHub
Skip to content

[bugfix] Preserve millisecond precision for cyclic collect intervals (#2405) - #4420

Open
xdn-code wants to merge 2 commits into
apache:masterfrom
xdn-code:fix-2405-collection-interval-drift
Open

xdn-code wants to merge 2 commits into
apache:masterfrom
xdn-code:fix-2405-collection-interval-drift

Conversation

@xdn-code

@xdn-code xdn-code commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Hi @MuAnswer and @orangeCatDeveloper, thank you for reporting this and for the clear root-cause analysis.

This change follows the suggested direction of scheduling in milliseconds:

  • Keep the remaining cyclic delay in milliseconds instead of truncating with intervalMs / 1000
  • Schedule cyclic jobs with TimeUnit.MILLISECONDS
  • Use a 100ms wheel tick so millisecond delays are not collapsed back to whole seconds
  • Honor the timeUnit argument in cyclicJob(...)

Test plan

  • TimerDispatcherTest
  • Added testIntervalDispatchPreservesMillisecondRemainder for the 30s / 300ms case

Please let me know if anything should be adjusted. Thanks again.

Fixes #2405

@zqr10159 zqr10159 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The milliseconds conversion is consistent across initial dispatch, cyclic rescheduling and cron fallback. Please add a scheduling-level regression that verifies the supplied timeUnit is honored and a fractional-second remainder reaches the timer. The new test checks the returned arithmetic, but would not catch scheduling it using the wrong unit. Please run the focused tests against current master before requesting re-review.

xdn-code and others added 2 commits October 12, 2026 22:02
…pache#2405)

Schedule remaining delays in milliseconds instead of truncating to whole
seconds, so short collections no longer drift the interval early.

Co-authored-by: Cursor <cursoragent@cursor.com>
…apache#2405)

Assert that cyclicJob passes the caller-supplied unit and millisecond remainder into Timer.newTimeout, which arithmetic-only tests would miss.

Co-authored-by: Cursor <cursoragent@cursor.com>
@xdn-code
xdn-code force-pushed the fix-2405-collection-interval-drift branch from b838f43 to fd1d181 Compare October 12, 2026 14:05
@xdn-code

xdn-code commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor Author

This branch has not been deployed

No deployments
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.

[Question] <The collection interval is not absolutely 30s>

2 participants