【问题标题】:Spring Batch: Commit-Interval not honored after roll back during writeSpring Batch:在写入期间回滚后不遵守提交间隔
【发布时间】:2011-08-11 12:04:35
【问题描述】:

假设我的提交间隔是 1000。

在编写过程中,我在第 990 条记录处收到错误,根据跳过策略可跳过。

因此会发生回滚,写入器将再次从记录 1 开始写入相同的记录。

但是,这一次,它正在提交每条记录。它不遵守提交间隔。这使工作变得缓慢。

为什么会有这样的行为??我的配置中是否缺少某些内容?

谢谢。

【问题讨论】:

    标签: rollback spring-batch


    【解决方案1】:

    这种行为对于 Spring Batch 隔离坏项目是强制性的,基本上它会回滚块并使用 commit-rate=1 处理/写入每个项目以找到坏项目(在处理器或写入器中)

    见spring batch forum comment to similar problem

    相关部分

    --> 5 items read, processing starts
    <processor called:15>
    <processor called:16>
    <processor called:17> will throw an error on write
    <processor called:18>
    <processor called:19>
    <before write:[15, 16, 17, 18, 19]>
    <on write error>
    --> error on item 17, but it was in the list, lets find it
    --> rollback
    <before chunk>
    --> spring batch goes through all items of the chunk again to find the bad item
    --> basically it runs now with commit-rate="1" (only for this chunk)
    <processor called:15>
    <after write:[15]>
    <after chunk>
    <before chunk>
    <processor called:16>
    <after write:[16]>
    <after chunk>
    <before chunk>
    <processor called:17> called again for the bad item, because it's still unknown to spring batch, that this is the bad one
    --> no write, because itemWriter.write() was called with the bad item only and did throw an exception (again)
    --> but now spring batch knows the bad item
    <before chunk>
    

    【讨论】:

    • 嗨,迈克尔。感谢您的回复。好的。我明白你的意思了。一旦作者遇到第一个异常,就会发生回滚。假设 1000 条记录中的第 4 条记录发生异常。所以作者以提交间隔 1 开始写入并找到第 4 项。将剩余的 996 条记录作为一个块再次写入是否足够明智?有可能吗???
    • 您可以使用 JIRA 票证进行尝试,现在我可以看到您的实用方法存在一些潜在问题,例如可重新启动性、确定性行为或在出现多个错误时的复杂块控制,最后您需要一个动态/适应块的概念...听起来很酷顺便说一句
    • 感谢您的回复!!我是新手,所以不知道如何打开 JIRA 票.. 但是会在周末尝试调查它......我对这个问题的处理方法是错误的吗???场景:在数据库中写入批量记录,如果有任何坏项目,跳过该项目(以便我可以记录坏项目)并继续...除了 onSkipOnWrite 方法,还有其他方法可以记录坏项目吗?克服了上述问题??
    • 对于 jira 票证,转到 jira.springsource.org/browse/BATCH 并在那里为您的用例创建一个帐户 - 尝试不同的提交率以找到性能最佳点和/或尽量减少错误,例如在处理器中测试项目
    猜你喜欢
    • 2016-10-18
    • 2015-12-10
    • 2011-10-11
    • 2019-09-26
    • 2015-10-15
    • 2015-09-14
    • 2012-07-10
    • 1970-01-01
    • 2014-08-13
    相关资源
    最近更新 更多