Bug Description
This issue was originally raised in #5210. While #5210 focused on the duplicate data insertion problem, further testing revealed that
rollbackCount was also incorrect.
Problems Found
- Duplicate data insertion - Scan mode executes in the same transaction as failed write
- Incorrect rollbackCount - No rollback before scan →
rollbackCount is not incremented
Steps to Reproduce
See #5210 for example projects comparing Spring Batch 5 and 6 behavior.
Expected Behavior
- Scan mode should execute in a new transaction after rollback (same as
FaultTolerantChunkProcessor in Spring Batch 5)
rollbackCount should reflect actual transaction rollbacks
Actual Behavior
| Issue |
Description |
| Duplicate data |
Scan executes without rollback, causing items to be written twice |
| Incorrect rollbackCount |
No rollback before scan → rollbackCount stays 0 |
Solution
Before (Bug)
[TX 1] write(1,2,3) → fail → scan(1,2,3) → commit
↑
item "1" written twice (duplicate!)
After (Fixed)
[TX 1] write(1,2,3) → fail → save state → ROLLBACK
↓
[TX 2] scan(1,2,3) → write each item → commit
↑
item "1" written once (correct!)
Key Changes
- State management - Added
scanMode and pendingChunk to ChunkTracker
- Transaction separation - Re-throw exception to trigger rollback before scan
- New transaction for scan - Execute scan in next iteration with clean transaction
Related
Bug Description
This issue was originally raised in #5210. While #5210 focused on the duplicate data insertion problem, further testing revealed that
rollbackCountwas also incorrect.Problems Found
rollbackCountis not incrementedSteps to Reproduce
See #5210 for example projects comparing Spring Batch 5 and 6 behavior.
Expected Behavior
FaultTolerantChunkProcessorin Spring Batch 5)rollbackCountshould reflect actual transaction rollbacksActual Behavior
rollbackCountstays 0Solution
Before (Bug)
[TX 1] write(1,2,3) → fail → scan(1,2,3) → commit
↑
item "1" written twice (duplicate!)
After (Fixed)
[TX 1] write(1,2,3) → fail → save state → ROLLBACK
↓
[TX 2] scan(1,2,3) → write each item → commit
↑
item "1" written once (correct!)
Key Changes
scanModeandpendingChunktoChunkTrackerRelated