简体   繁体   English

Spring批处理:传播在分区步骤中遇到的异常(停止作业执行)

[英]Spring batch : Propagate exception encountered in partitioned step (Stop job execution)

Background背景

I currently have a spring-batch job that reads a flat file.我目前有一个读取平面文件的 spring-batch 作业。 The job uses a MultiResourcePartitioner to read physical partitions of a file that has been split into N number of smaller files.该作业使用MultiResourcePartitioner读取已拆分为 N 个较小文件的文件的物理分区。 This means that each physical partition of the file will result in a new slave step being executed that reads the partition.这意味着文件的每个物理分区都会导致执行一个新的从属步骤来读取分区。

The problem问题

If there is any issue reading any physical partition, the execution of that slave step will fail and the exception will be logged by spring batch.如果读取任何物理分区有任何问题,则该从属步骤的执行将失败,并且 spring 批处理将记录异常。 This does not impact the execution of the remaining slave steps that are reading different physical partitions of the file;这不会影响正在读取文件的不同物理分区的其余从步骤的执行; however, this is not the desired behavior.然而,这不是理想的行为。 What I want is that if there is an issue reading a particular physical partition (Example : not being able to parse a particular column), the exception should be propagated to the location where the Job was launched so that I can halt any further processing.我想要的是,如果读取特定物理分区时出现问题(例如:无法解析特定列),则应将异常传播到启动Job的位置,以便我可以停止任何进一步的处理。

The current implementation of the execute method in AbstractStep catches Throwable and suppresses the exception by logging it. AbstractStep execute方法的当前实现捕获Throwable并通过记录异常来抑制异常。 As a result, the exception is not propagated to the location where the Job was launched and there is no way to halt the execution of the remaining slave steps.因此,异常不会传播到Job启动的位置,并且无法停止其余从属步骤的执行。

How can I make spring-batch propagate any exception that occurs in a slave step all the way to the location where the Job was launched?如何让 spring-batch 将在从属步骤中发生的任何异常一直传播到Job启动的位置? I want to do this so that I can halt any further processing if there is an issue processing any of the partitioned files.我想这样做,以便在处理任何分区文件时出现问题时可以停止任何进一步的处理。

If there is any issue reading any physical partition, the execution of that slave step will fail and the exception will be logged by spring batch.如果读取任何物理分区有任何问题,则该从属步骤的执行将失败,并且 spring 批处理将记录异常。 This does not impact the execution of the remaining slave steps that are reading different physical partitions of the file;这不会影响正在读取文件的不同物理分区的其余从步骤的执行; however, this is not the desired behavior.然而,这不是理想的行为。

I would argue that the fact that "This does not impact the execution of the remaining slave steps" is the desired behaviour.我认为“这不会影响其余从属步骤的执行”这一事实理想的行为。 Usually, the idea behind partitioning a big chunk of work into smaller tasks which are executed in parallel is that tasks should be independent from each others and one failure should not impact others.通常情况下,后面的分割工作的一大块成并行执行的更小的任务的想法是,任务应独立于彼此和一个故障不会影响到其他人。 If there is a logic that requires the failure of one task to stop other tasks, it means that tasks are not well defined to be independent and executing them in a local/remote partitioned step is not the appropriate choice in the first place.如果有一个逻辑要求一个任务失败来停止其他任务,这意味着任务没有很好地定义为独立的,并且在本地/远程分区步骤中执行它们首先不是合适的选择。

What I want is that if there is an issue reading a particular physical partition (Example : not being able to parse a particular column), the exception should be propagated to the location where the Job was launched so that I can halt any further processing.我想要的是,如果读取特定物理分区时出现问题(例如:无法解析特定列),则应将异常传播到启动作业的位置,以便我可以停止任何进一步的处理。

You need a custom PartitionHandler for that.为此,您需要一个自定义PartitionHandler This is the piece that coordinates worker steps.这是协调工人步骤的部分。 The default behaviour is to wait for all workers steps to finish and aggregate the results before reporting to the main job.默认行为是在向主作业报告之前等待所有工作人员步骤完成并汇总结果。 Your custom implementation should detect the failure of any worker step and inform others to stop.您的自定义实现应该检测任何工作步骤的失败并通知其他人停止。

Moreover, this design of stopping/failing all workers if one of them fails is not appropriate for job restart.此外,如果其中一个工作失败,则停止/使所有工作人员失败的这种设计不适合重新启动作业。 This means that restarting a job would restart all partitions, which is not the goal of a partitioned job in the first place where only failed partitions should be restarted.这意味着重新启动作业将重新启动所有分区,这不是分区作业首先应重新启动失败分区的目标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Batch分区,如何在任何分区步骤引发异常后停止作业 - Spring Batch Partitioning, how to stop a Job once any of the partitioned step throws exception Spring Batch 3.0:StepExecutionListener 用于分区 Step 并将执行上下文值级联到分区作业 - Spring Batch 3.0 : StepExecutionListener for a partitioned Step and cascading of execution context values to the partitioned job 分区作业完成后不能自行停止? 春批 - Partitioned Job can't stop by itself after finishing? Spring Batch spring 批量提供作业执行状态和步骤信息 - spring batch provide status of job execution and step information Spring-batch 分区步骤重复处理 - Spring-batch partitioned step duplicated processing Spring Batch从外部类停止作业执行 - Spring Batch stop job execution from external class 运行 spring 批处理作业时无法反序列化执行上下文异常 - Unable to deserialize the execution context exception when running spring batch job 如何获得Spring Batch作业的下一步中上一步执行的ID? - How do I get the ID of the previous step execution in the next step of a spring batch job? Spring Batch多个作业执行 - Spring Batch Multiple Job execution 如何从 Spring Batch Step 访问执行上下文? 错误:没有可用于作业范围的上下文持有者 - How to access execution context from a Spring Batch Step? Error: No context holder available for job scope
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM