Skip to content

Regression due to the fix of BATCH-2442 [BATCH-2840] #775

Closed
@spring-projects-issues

Description

@spring-projects-issues

Conosci opened BATCH-2840 and commented

I have a scenario where I believe this fix is causing another dangerous bug, some items don't end properly their lifecycle and are silenty ignored. The scenario is the following:

  • Job with 1 Step With Chunk Processing (ChunkSize=10)
  • Reader, Processor, Writer, all with faultTolerant() and skipPolicy(..) (Always Skip) and skipListener(..) to listen to 'onSkipInWrite' and 'onSkipInProcess'
  • Source Data with 3 Records: the first is a good record, the second is giving Processing Error and the third is giving Write Error (duplicate primary key against the first record)

At runtime, after the BATCH-2442 fix, the result is the following:

  1. Reader reads the 3 records chunk

  2. Processor start processing and meet Processing Error in the second record

  3. The System will skip (according to the configured policy) the second record and will invoke the SkipListener (onSkipInProcess) giving to the user the possibility to manage the issue

  4. The System will take the remaining 2 records (the first and the third), will process again them and will try to write them in chunk (same transaction)

  5. During the write the database will return exception (duplicate primary key)

  6. The System will go in 'recovery' mode and will start processing the two items one by one

  7. Now during the scan the following code will execute:

    1. //BATCH-2442 : do not scan skipped items
      if (!inputs.getSkips().isEmpty()) {
        if (outputIterator.hasNext()) {    outputIterator.remove();    return;   }
      }
  8. The condition is then verified, there is a skip (the first Processor error for the second record) and one record from the remaining two (first and third) is then removed without any reason!

  9. At this point only 1 record is then available in outputIterator (the first record), and it will be written successfully.

  10. The job then ends with a non consistent state (there is a writeSkipCount element missing, the totals are wrong):

    1. readCount = 3
    2. processSkipCount = 1
    3. writeCount = 1
    4. writeSkipCount = 0
    5. rollbackCount = 2
    6. commitCount = 2
  11. Basically what happened is that removing the wrong element from the outputIterator, the system didn't catch the Write Exception and didn't execute the proper lifecycle (doOnWriteError/shouldSkip/onSkipInWrite) givinig no change to the user to know about the skipped element in the skipListener

 

The same scenario is working well before the fix version, using Spring Batch version 4.0.1.RELEASE all the listeners are correctly invoked and the ending counts are correct.


Affects: 4.2.0, 4.0.3, 4.1.2

Reference URL: https://jira.spring.io/browse/BATCH-2442

Attachments:

Backported to: 4.3.0.M1, 4.2.1, 4.1.3, 4.0.4

4 votes, 6 watchers

Metadata

Metadata

Assignees

No one assigned

    Labels

    has: backportsLegacy label from JIRA. Superseded by "for: backport-to-x.x.x"in: coretype: bug

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions