Skip to content

Commit 11db201

Browse files
committed
Eliminate unnecessary query for current version
The version from query result is nondeterministic, it's not definitely same to the moment update executed because it may be altered right after that moment, it's not definitely same to the latest version in database because it may be altered right after the query executed. Given that, the current version is not so useful for troubleshooting in practice. Signed-off-by: Yanming Zhou <[email protected]>
1 parent 43ac1f1 commit 11db201

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDao.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
* @author Dimitrios Liapis
7575
* @author Philippe Marschall
7676
* @author Jinwoo Bae
77+
* @author Yanming Zhou
7778
*/
7879
public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements JobExecutionDao, InitializingBean {
7980

@@ -319,11 +320,8 @@ public void updateJobExecution(JobExecution jobExecution) {
319320

320321
// Avoid concurrent modifications...
321322
if (count == 0) {
322-
int currentVersion = getJdbcTemplate().queryForObject(getQuery(CURRENT_VERSION_JOB_EXECUTION),
323-
Integer.class, new Object[] { jobExecution.getId() });
324-
throw new OptimisticLockingFailureException(
325-
"Attempt to update job execution id=" + jobExecution.getId() + " with wrong version ("
326-
+ jobExecution.getVersion() + "), where current version is " + currentVersion);
323+
throw new OptimisticLockingFailureException("Attempt to update job execution id=" + jobExecution.getId()
324+
+ " with wrong version (" + jobExecution.getVersion() + ")");
327325
}
328326

329327
jobExecution.incrementVersion();

spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java

+3-10
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
* @author Mahmoud Ben Hassine
6767
* @author Baris Cubukcuoglu
6868
* @author Minsoo Kim
69+
* @author Yanming Zhou
6970
* @see StepExecutionDao
7071
*/
7172
public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implements StepExecutionDao, InitializingBean {
@@ -100,11 +101,6 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement
100101
WHERE JE.JOB_INSTANCE_ID = ? AND SE.STEP_NAME = ?
101102
""";
102103

103-
private static final String CURRENT_VERSION_STEP_EXECUTION = """
104-
SELECT VERSION FROM %PREFIX%STEP_EXECUTION
105-
WHERE STEP_EXECUTION_ID=?
106-
""";
107-
108104
private static final String COUNT_STEP_EXECUTIONS = """
109105
SELECT COUNT(*)
110106
FROM %PREFIX%JOB_EXECUTION JE
@@ -287,11 +283,8 @@ public void updateStepExecution(StepExecution stepExecution) {
287283

288284
// Avoid concurrent modifications...
289285
if (count == 0) {
290-
int currentVersion = getJdbcTemplate().queryForObject(getQuery(CURRENT_VERSION_STEP_EXECUTION),
291-
Integer.class, stepExecution.getId());
292-
throw new OptimisticLockingFailureException(
293-
"Attempt to update step execution id=" + stepExecution.getId() + " with wrong version ("
294-
+ stepExecution.getVersion() + "), where current version is " + currentVersion);
286+
throw new OptimisticLockingFailureException("Attempt to update step execution id="
287+
+ stepExecution.getId() + " with wrong version (" + stepExecution.getVersion() + ")");
295288
}
296289

297290
stepExecution.incrementVersion();

0 commit comments

Comments
 (0)