spring-projects / spring-projects/spring-batch

MultiResourceItemWriter - Job restart failing (File is not writable) if last file first chunk failed [BATCH-2759]

Open
#845 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

in: core status: waiting-for-triage type: bug
Dominant language
Java
Stars
3k
Forks
2.5k
Avg merge
6d 53m
Merged PRs (30d)
3

Description

Aitor Perez opened BATCH-2759 and commented

Hi,

I'm developing an Spring Batch application that writes database rows in CSV files. The database is huge so I need to generate multiple output CSV files partitioned (outputfile.csv.1, outputfile.csv.2, outputfile.csv.3 .....)

I'm testing all data cases and I have found a problem when I restart the failed job in this situation. When the execution failed in the first chunk of a new partitioned file, this new file is not created (I tried shouldDeleteIfEmpty = false but the file is not created).

When I try the restart, it seems that is expecting this last missing partitioned failed file.

Example:
ChunkSize = 50
ItemCountLimitPerResource = 100
Force Exception at item 325

The execution fails an I can see in the ouput the generated files (outputfile.csv.1, outputfile.csv.2, outputfile.csv.3) with the 300 first rows (6 chunks and 3 completed files).

When I restart the job, I'm getting the exception:

org.springframework.batch.item.ItemStreamException: File is not writable: [XXXX...\outputfile.csv.4]

It seems that expects this file, but was not created due to the error in the first chunk (I tried shouldDeleteIfEmpty = false but the file is not created)

Reviewing the database repository I can check the execution, and the value of the resource index is 4

{"map":[{"entry":[{"string":"FlatFileItemWriter.current.count","long":700},{"string":"JdbcCursorItemReader.read.count","int":300},{"string":"MultiResourceItemWriter.resource.index","int":4},{"string":"FlatFileItemWriter.written","long":50},{"string":["batch.taskletType","org.springframework.batch.core.step.item.ChunkOrientedTasklet"]},{"string":"MultiResourceItemWriter.resource.item.count","int":0},{"string":["batch.stepType","org.springframework.batch.core.step.tasklet.TaskletStep"]}]}]}

I tried configuring the FlatFileItemWriter flags with different values (AppendAllowed, ShouldDeleteIfEmpty, ShouldDeleteIfExists) but the same issue is thrown

Thanks


Affects: 4.0.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with MultiResourceItemWriter restart handling and reproduce the reported case using a chunk size of 50, an item limit of 100 per resource, and a failure at item 325. Inspect the persisted resource index and writer state described in the report; done means restarting no longer fails on the missing fourth output file and the partitioned CSV output resumes correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend, data-engineering
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.