Results 1 to 7 of 7

Thread: rollback mechanism for chunk oriented processing strategy of Spring Batch

  1. #1
    Join Date
    Jan 2011
    Posts
    13

    Default rollback mechanism for chunk oriented processing strategy of Spring Batch

    Hello,

    As we all know, spring batch uses chunk oriented processing since the version 2.0.

    Does it mean that, if an exception occurs in the item writer, the Data Source Transaction manager will roll back the whole chunk or only the related item?

    Actually, I gave it a try and saw that the framework rolls back the whole chunk. That's not what I need because I do not want, let's say, 499 items which have been processed successfully to be rolled back in a chunk consisting of 500 items when the last item causes an exception to be thrown.

    Maybe Spring Batch is not suitable for my problem domain. If so, please tell me so I won't be struggling with those kind of framework specific behaviour anymore.

    Any suggestions would be greatly appreciated.

  2. #2
    Join Date
    Sep 2008
    Location
    Chicagoland, IL
    Posts
    366

    Default

    Kivanc,

    I might be missing something. If you want to be able to roll back individual items, why is your chunk size 500 instead of 1? Granted, the job will be slower but you will get the granularity you are looking for.

  3. #3
    Join Date
    Jan 2011
    Posts
    13

    Default

    That's a very good question and I think you're right about reducing the chunk size to 1.

    However, what I want to achieve is to read chunks of data from the database while treating them individually in terms of rollback.

    Actually, after having posted this thread, I found something, but I am not sure if this is the right way.

    I added the following attribute to the tasklet and the job does exactly what I want it to do.
    Code:
    <batch:transaction-attributes propagation="NOT_SUPPORTED"/>
    I really need your opinions about that.

    Regards

  4. #4
    Join Date
    Dec 2005
    Location
    Lyon, France
    Posts
    311

    Default

    what about skipping the error? assuming the to-be-skipped exception is thrown in the writer, Spring Batch would then rollback the chunk and write each item of the chunk one-by-one (in separate transactions) to find the item that threw the exception.

  5. #5
    Join Date
    Jan 2011
    Posts
    13

    Default

    I tried adding <skippable-exception-classes> to the chunk but it didn't work like you expected it to be. It pretends like the exception has never been thrown and it does NOT rollback the chunk and write each item of the chunk one-by-one, unfortunately.

  6. #6
    Join Date
    Dec 2005
    Location
    Lyon, France
    Posts
    311

    Default

    silly question perhaps, but did you remove

    Code:
    <batch:transaction-attributes propagation="NOT_SUPPORTED"/>
    ?

  7. #7
    Join Date
    Jan 2011
    Posts
    13

    Default

    In my previous post, I had written "I added the following attribute to the tasklet and the job does exactly what I want it to do.". Then I realized that was not true, not at all After spending so much time about this problem, I guess I was feeling dizzy at that moment and thought that I found the solution

    Anyway, I definitely removed
    <CODE>
    <batch:transaction-attributes propagation="NOT_SUPPORTED"/>
    </CODE>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •