Description
Reason
Scaling module dependent on ElasticJob module to sharding and execute scaling job, there are some issues like:
- OneOff job can't do average sharding even if one-off job start in a short interval.
- Sharding item sometimes exexute in different server, which may cause some problems.
- OneOff job don't have a complete flag, which may cause job execute more than once.
Plan
So, we decide to refactor it with this plan:
- add static sharding strategy
- add completed flag
- split job create trigger API
Steps
-
Before refactor
- Optimize JobInstance
- add server field(value is current server ip), and replace it with split by jobInstanceId.
- add labels field which match JobConfiguration's label field(one to more).
- Optimize JobConfiguration
- add label field which match JobInstance's labels field.
- Optimize JobInstance
-
Add static sharding
-
Optimize JobConfiguration
- add boolean staticSharding field to mark current JobConfiguration is use static sharding strategy or not.
-
ShardingListenerManager and ReconcileService
- if staticSharding is true and have been done sharding before, do not create necessary flag again.
-
-
Add completed flag
-
for one-off job, if any item completed, create a completed flag in
sharding/item/completed
-
failover or reboot JobInstance do not do it again.
-
-
Register job instance
Add
JobInstanceRegistry.register(jobInstanceId, labels)
API to start a JobInstance and execute:-
listen
/jobs/*/config
and start all uncompleted jobuncompleted job check by
config.enable
= trueconfig.label
match JobInstance's labels- all schedule job
- one-off job which
sharding/item/completed
<config.shardingTotalCount
-
start job by old API
- new ScheduleJobBootstrap().schedule()
- new OneOffJobBootstrap().execute()
-
-
Add trigger API
add
JobOperateAPI.trigger(jobName, class, config)
API to create a job-
create
/jobs/jobName
node to persist job class. -
create
/jobs/jobName/config
to persist job config.
-
API changes
-
new API: split register and trigger
- register job instance
JobInstanceRegistry.register(jobInstanceId, labels)
- trigger job
JobOperateAPI.trigger(jobName, class, jobConfig)
-
old API: create and execute
- one-off job
new OneOffJobBootstrap(regCenter, elasticJob, jobConfig).execute()
- schedule job
new ScheduleJobBootstrap(regCenter, elasticJob, jobConfig).schedule()