2

Say my commit interval is 1000.

And during writing I get a error at 990th record which is skippable as per skip policy.

So a rollback will occur and the writer will start again writing the same records from record 1.

However, this time, It is commiting on each record. It does not honour commit interval. This is making the job dead slow.

Why the behavior is like that ?? Am I missing something in my configuration ??

Thanks.

skaffman
  • 398,947
  • 96
  • 818
  • 769
Vicky
  • 16,679
  • 54
  • 139
  • 232

1 Answers1

3

that bevaviour is mandatory for spring batch to isolate the bad item(s), basically it rollbacks the chunk and processes/writes each item with commit-rate=1 to find the bad one (in either processor or writer)

see spring batch forum comment to similar problem

the relevant part

--> 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>
Michael Pralow
  • 6,560
  • 2
  • 30
  • 46
  • Hi Michael. Thanks for your reply. Ok. I got your point. The rollback will happen as soon as the writer hits the first exception. Say that exception occurs at Record 4 out of 1000 records. So the writer starts writing with commit interval 1 and finds the 4th item. Shouldn't it be wise enough to write the remaining 996 records again as a chunk ?? Is it possible ??? – Vicky Aug 11 '11 at 13:44
  • you could try it with a JIRA ticket, right now i could see some potential problems with your pragmatic approach, things like restartability, deterministic behaviour or complex chunk control in case of multiple errors, in the end you need a dynamic/adapting chunk concept...which sounds cool btw – Michael Pralow Aug 11 '11 at 15:10
  • Thanks for the reply!! I am a newbie so do not know how to open a JIRA ticket.. however will try to look into it in the weekends... Is my approach towards the problem is wrong ??? Scenario: Write batches of records in the database and in case of any bad item, skip the item (SO THAT I CAN LOG THE BAD ITEM) and continue... Except onSkipOnWrite method, is there any other way to log the bad item which overcomes above issue ?? – Vicky Aug 12 '11 at 03:16
  • for the jira ticket go to https://jira.springsource.org/browse/BATCH and create an account there, for your usecase - try different commit-rates to find the performance sweet spot and/or try to minimize the errors e.g. test the items in a processor – Michael Pralow Aug 12 '11 at 10:34