Commit 644d7e6
Fix optimistic locking and add interruption check in ChunkOrientedStep
When JobOperator.stop() is called, the StepExecution version could become
out of sync between the stopping thread and the executing step thread,
causing OptimisticLockingFailureException.
This commit synchronizes the StepExecution version by fetching the latest
state from the batch metadata before update. If the recent StepExecution is in
STOPPED status, it upgrades the current StepExecution's status and version
to match the database state, preventing version conflicts.
Additionally, added JobRepository.update() call in ChunkOrientedStep after
each chunk to match TaskletStep behavior. This ensures both step
implementations properly check for job interruption signals by synchronizing
with the latest StepExecution status from the database.
Move stepExecution.update() outside chunk transaction to prevent
version mismatch when transaction rolls back.
Problem:
- Chunk transaction rollback reverts DB version but leaves
in-memory version incremented
- Next update() causes OptimisticLockingFailureException
Solution:
- Call getJobRepository().update(stepExecution) after transaction
completes, outside transactionTemplate.executeWithoutResult()
- On success: update() is called with synchronized versions
- On failure: update() is skipped, preventing version conflict
Fixes #5120
Fixes #5114
Signed-off-by: kill9-no-mercy <kill9.no.mercy@gmail.com>1 parent 98c10cd commit 644d7e6
File tree
4 files changed
+24
-18
lines changed- spring-batch-core/src/main/java/org/springframework/batch/core
- job
- repository/support
- step/item
4 files changed
+24
-18
lines changedLines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
216 | 224 | | |
217 | 225 | | |
218 | 226 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
328 | 328 | | |
329 | 329 | | |
330 | 330 | | |
331 | | - | |
| 331 | + | |
332 | 332 | | |
333 | 333 | | |
334 | 334 | | |
| |||
Lines changed: 13 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
161 | 174 | | |
162 | | - | |
163 | 175 | | |
164 | 176 | | |
165 | 177 | | |
| |||
180 | 192 | | |
181 | 193 | | |
182 | 194 | | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | 195 | | |
200 | 196 | | |
201 | 197 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
373 | 373 | | |
374 | 374 | | |
375 | 375 | | |
| 376 | + | |
| 377 | + | |
376 | 378 | | |
377 | 379 | | |
378 | 380 | | |
| |||
0 commit comments