hertzbeat
hertzbeat copied to clipboard
[bugfix] Fix duplicate collector job timeouts
What's changed?
Fixes #4153.
When the collector receives the same job id again, TimerDispatcher replaced the timeout stored in the task map but did not cancel the previous HashedWheelTimer timeout. The replaced timeout could stay active until it fired, so repeated job updates may accumulate unnecessary HashedWheelTimeout instances.
This change cancels the previous timeout when a cyclic or temporary job is replaced by a new timeout for the same job id. It keeps the latest timeout in the map and only cancels the old one.
Added regression coverage for both cyclic and temporary jobs to verify that:
- the timeout map is updated to the new timeout
- the old timeout is cancelled
- the new timeout remains active
Validation:
git diff --check -- hertzbeat-collector/hertzbeat-collector-common/src/main/java/org/apache/hertzbeat/collector/timer/TimerDispatcher.java hertzbeat-collector/hertzbeat-collector-common/src/test/java/org/apache/hertzbeat/collector/timer/TimerDispatcherTest.java./mvnw -pl hertzbeat-collector/hertzbeat-collector-common -am -Dsurefire.failIfNoSpecifiedTests=false test
Checklist
- [x] I have read the Contributing Guide
- [x] I have written the necessary doc or comment.
- [x] I have added the necessary unit tests and all cases have passed.
Add or update API
No API is added or updated in this PR.
- [ ] I have added the necessary e2e tests and all cases have passed.