Spring Batch FlowStep in Partitioner restart issue

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-25 13:16:43

问题


Here is what I'm trying to achieve in a Spring Batch job:

  • A partitioner launches a FlowStep
  • The FlowStep consists of n step(s)
  • In case of failure, I want a consistent restart of the inner steps

I encounter the following issue during a restart: Suppose I have 2 partitions, for the sake of simplicity I have a syncTaskExecutor. The first partition (partition0) runs well, we run now the second partition (partition1).

The first problem is that the sub-steps of the FlowStep are detected as duplicates. This is because the names of the sub-steps are not suffixed with the partition index. But the steps run ultimately.

The consequence of this happens if one sub-step fails. In that case, during a restart, since all sub-steps of the partition0 execution exit successfuly, the remaining steps of partition1 won't be executed.

The main problem here is that the sub-steps of a partitioner are not indexed and therefor detected as equivalent but they are not.

Additionally I don't want to set the sub-steps as restartable because I just want the missing steps to be executed and not all of them.

Am I missing something at this point? Do you have an alternative for what I want to do?

I know I could also launch a real job from the partitioner (using a JobStep) but this is not as powerful as FlowStep because we are really limited by the parameters we can provide to a job (no existing ExecutionContext). The guy here had the same issue I guess ( Spring batch Partitioning with multiple steps in parallel?)

Thank you for your help


回答1:


After digging in the Spring Batch arcanes, I think I can answer my own question and maybe help some other people.

The key here is to provide our own StepHandler instead of the default SimpleStepHandler. In this handler, we can use the provided ExecutionContext to look after a predefined key that will contain the current partition id. We just need to use this id to build a unique step name in the form step.getName() + ":" + id.

In order to insert this custom StepHandler, we override the default FlowStep implementation.

A complete example can be found here https://github.com/miremond/spring-boot-sample-batch.



来源:https://stackoverflow.com/questions/33121176/spring-batch-flowstep-in-partitioner-restart-issue

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!