Skip to content

Conversation

@Calvin979
Copy link
Contributor

@Calvin979 Calvin979 commented Aug 18, 2025

What's changed?

After code iterations in these years, module Manager contain more and more functions. Yet there isn't a clear code structure, such as org.apache.hertzbeat.manager.scheduler.CollectorJobScheduler holds all operations about Collector status notifications, selecting collector, dispatching jobs and so on.
I think it is time to get refactored.

This PR is only for refactoring collector selections within CollectorJobScheduler

  1. Use ConfigConstants.PkgConstant.PKG instead of hardcode in Manager.java
  2. Remove unused methods
  3. Create folder properties in module Manager, used for those files that read yml properties only
  4. Integrate methods that shared the same name, such as org.apache.hertzbeat.manager.scheduler.CollectorJobScheduler#collectSyncJobData and org.apache.hertzbeat.manager.scheduler.CollectorJobScheduler#updateAsyncCollectJob
  5. Rename interface, org.apache.hertzbeat.manager.scheduler.CollectJobScheduling -> org.apache.hertzbeat.manager.scheduler.JobOperation
  6. Split interface in order to separate responsibility. org.apache.hertzbeat.manager.scheduler.CollectorScheduling -> org.apache.hertzbeat.manager.scheduler.CollectorOperation and org.apache.hertzbeat.manager.scheduler.CollectorOperationReceiver
  7. Add CollectorKeeper to take responsibility of collector selections only

After refactoring above, current code design of Manager will be like:
image
image

So far, we keep org.apache.hertzbeat.manager.scheduler.CollectorJobScheduler as the only one implementation class in order to avoid overturning.
image

What are the benefits?

  1. As for spliting interface org.apache.hertzbeat.manager.scheduler.CollectorScheduling -> Ensure the code hierarchy clearer to facilitate further code splitting.
  2. As for new class CollectorKeeper -> This is for collector selections only, which means we can support more select strategy by implementing this interface, such as Round Robin and so on.

Checklist

  • I have read the Contributing Guide
  • I have written the necessary doc or comment.
  • I have added the necessary unit tests and all cases have passed.

Add or update API

  • I have added the necessary e2e tests and all cases have passed.

@Calvin979 Calvin979 requested a review from tomsun28 August 18, 2025 13:54
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the code structure of the Manager module, specifically focusing on collector operations and job scheduling. The primary goal is to improve code organization and create a clearer separation of responsibilities within the CollectorJobScheduler component.

  • Split interfaces to separate collector operations from job operations
  • Introduced CollectorKeeper abstraction for collector selection strategies
  • Moved properties classes to a dedicated properties package
  • Consolidated duplicate methods and simplified the API surface

Reviewed Changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
CollectorJobScheduler.java Refactored to implement split interfaces and use CollectorKeeper abstraction
JobOperation.java New simplified interface replacing CollectJobScheduling
CollectorOperation.java New interface for direct collector operations
CollectorOperationReceiver.java New interface for receiving collector operations from remote collectors
ConsistentHashCollectorKeeper.java Renamed and refactored from ConsistentHash, implements CollectorKeeper
CollectorKeeper.java New interface abstraction for collector selection strategies
CollectorNode.java Extracted from inner class to standalone POJO
JobCache.java New utility class for job caching
properties/*.java Moved property classes to dedicated package
Comments suppressed due to low confidence (3)

hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/scheduler/ConsistentHashCollectorKeeper.java:302

  • Potential null pointer exception: The addJob method can return null when no collector is found, but the code immediately uses collectorNode.getIdentity() without null checking.
        Map.Entry<Integer, CollectorNode> ceilEntry = hashCircle.ceilingOrFirstEntry(dispatchHash);

hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/nativex/HertzbeatRuntimeHintsRegistrar.java:29

  • Unused import: org.springframework.aot.hint.ExecutableMode is imported but not used after the registerConstructor method was removed.
import org.apache.sshd.common.util.security.eddsa.EdDSASecurityProviderRegistrar;

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

…ojo/JobCache.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Calvin <zhengqiwei@apache.org>
@tomsun28 tomsun28 requested a review from Ceilzcx August 19, 2025 16:16
@tomsun28
Copy link
Member

hi, this need more time or others to review and test , maybe in this weekend.

@Calvin979
Copy link
Contributor Author

hi, this need more time or others to review and test , maybe in this weekend.

Sure, looking forward to your suggestions

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

Labels

Projects

Status: To do

Development

Successfully merging this pull request may close these issues.

2 participants