java Spring Batch - 提交间隔和跳过限制

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14010234/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 14:43:30  来源:igfitidea点击:

Spring Batch - Commit Interval and Skip Limit

javaspringtransactionsspring-batchcommit

提问by Anand Kumar

Solution for this scenario - commit interval is 10, skip limit is 10, Total Input Record is 20, First 9 records valid, remaining invalid.

此场景的解决方案 - 提交间隔为 10,跳过限制为 10,总输入记录为 20,前 9 条记录有效,其余无效。

When 9 records are already read, the 10th one is invalid. The chunk size is 10 and skip limit is 10, so will Spring batch write those 9 records in output file? If not, if it goes on reading remaining records, when it reads 20th record, count of the error record will be 11 and skip limit defined is 10. So the process will stop immediately. What about the fate of valid records read first.

当已读取 9 条记录时,第 10 条无效。块大小为 10,跳过限制为 10,那么 Spring 会批量将这 9 条记录写入输出文件吗?如果不是,继续读取剩余的记录,当它读取第20条记录时,错误记录的计数将为11,定义的跳过限制为10。因此该过程将立即停止。首先读取的有效记录的命运如何。

Will the first 9 records be written in output file or not.

前 9 条记录是否写入输出文件。

Please let me know, if any solution available. Thanks!

如果有任何可用的解决方案,请告诉我。谢谢!

回答by Cygnusx1

There is more than one possible outcome. You have to be specific about the invalid records.

可能的结果不止一种。您必须具体说明无效记录。

Are they invalid reads:in this case, SB will just call the ItemReader next value (no rollback). so you will end up with an Skip limit exception since 11 records were found invalid.

它们是否无效读取:在这种情况下,SB 将只调用 ItemReader 下一个值(无回滚)。因此,由于发现 11 条记录无效,因此您最终会遇到跳过限制异常。

Are they invalid writes :In this case, SB will redo the first chunk on a commit--interval of 1 until it find the bad record. In this case, you should find the first 9 records in the database.

它们是否无效写入:在这种情况下,SB 将在提交时重做第一个块——间隔为 1,直到找到坏记录。在这种情况下,您应该找到数据库中的前 9 条记录。

Regards

问候

回答by Dipali Mehndiratta

For this scenario - commit interval is 10, skip limit is 10, Total Input Record is 20, First 9 records valid, remaining invalid.

对于这种情况 - 提交间隔为 10,跳过限制为 10,总输入记录为 20,前 9 条记录有效,其余无效。

When 9 records are already read, the 10th one is invalid. The chunk size is 10 and skip limit is 10, so will Spring batch write those 9 records in output file.

当已读取 9 条记录时,第 10 条无效。块大小为 10,跳过限制为 10,因此 Spring 会将这 9 条记录批量写入输出文件。

Answer - SB will skip 10th invalid record and read 11th record and then will got writer to write correct 10th record and as only one record was invalid skip count will be 1 .

答案 - SB 将跳过第 10 条无效记录并读取第 11 条记录,然后让作者写入正确的第 10 条记录,因为只有一条记录无效,因此跳过计数将为 1。

sample config -

示例配置 -