hertzbeat icon indicating copy to clipboard operation
hertzbeat copied to clipboard

[Refactor] optimize code structure about collector and job within Manager

Open Calvin979 opened this issue 5 months ago • 2 comments

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

  • [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

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

Calvin979 avatar Aug 18 '25 13:08 Calvin979

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

tomsun28 avatar Aug 19 '25 16:08 tomsun28

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

Sure, looking forward to your suggestions

Calvin979 avatar Aug 19 '25 16:08 Calvin979