Skip to content

Commit 7841e0b

Browse files
author
dsyer
committed
RESOLVED - issue BATCH-368: StepExecution attributes can overflow and cause spurious OptimisticLockingException
http://jira.springframework.org/browse/BATCH-368 Removed STATISTICS column from BATCH_STEP_EXECUTION.
1 parent 84073c0 commit 7841e0b

File tree

9 files changed

+7
-19
lines changed

9 files changed

+7
-19
lines changed

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.springframework.batch.io.exception.BatchCriticalException;
2020
import org.springframework.batch.item.ExecutionContext;
2121
import org.springframework.batch.repeat.ExitStatus;
22-
import org.springframework.batch.support.PropertiesConverter;
2322
import org.springframework.beans.factory.InitializingBean;
2423
import org.springframework.dao.DataAccessException;
2524
import org.springframework.dao.OptimisticLockingFailureException;
@@ -63,18 +62,18 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement
6362
+ " KEY_NAME, STRING_VAL, DOUBLE_VAL, LONG_VAL, OBJECT_VAL) values(?,?,?,?,?,?,?)";
6463

6564
private static final String SAVE_STEP_EXECUTION = "INSERT into %PREFIX%STEP_EXECUTION(STEP_EXECUTION_ID, VERSION, STEP_NAME, JOB_EXECUTION_ID, START_TIME, "
66-
+ "END_TIME, STATUS, COMMIT_COUNT, TASK_COUNT, TASK_STATISTICS, CONTINUABLE, EXIT_CODE, EXIT_MESSAGE) "
67-
+ "values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
65+
+ "END_TIME, STATUS, COMMIT_COUNT, TASK_COUNT, CONTINUABLE, EXIT_CODE, EXIT_MESSAGE) "
66+
+ "values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
6867

6968
private static final String UPDATE_STEP_EXECUTION_CONTEXT = "UPDATE %PREFIX%STEP_EXECUTION_CONTEXT set "
7069
+ "TYPE_CD = ?, STRING_VAL = ?, DOUBLE_VAL = ?, LONG_VAL = ?, OBJECT_VAL = ? where STEP_EXECUTION_ID = ? and KEY_NAME = ?";
7170

7271
private static final String UPDATE_STEP_EXECUTION = "UPDATE %PREFIX%STEP_EXECUTION set START_TIME = ?, END_TIME = ?, "
73-
+ "STATUS = ?, COMMIT_COUNT = ?, TASK_COUNT = ?, TASK_STATISTICS = ?, CONTINUABLE = ? , EXIT_CODE = ?, "
72+
+ "STATUS = ?, COMMIT_COUNT = ?, TASK_COUNT = ?, CONTINUABLE = ? , EXIT_CODE = ?, "
7473
+ "EXIT_MESSAGE = ?, VERSION = ? where STEP_EXECUTION_ID = ? and VERSION = ?";
7574

7675
private static final String GET_STEP_EXECUTION = "SELECT STEP_EXECUTION_ID, STEP_NAME, START_TIME, END_TIME, STATUS, COMMIT_COUNT,"
77-
+ " TASK_COUNT, TASK_STATISTICS, CONTINUABLE, EXIT_CODE, EXIT_MESSAGE from %PREFIX%STEP_EXECUTION where STEP_NAME = ? and JOB_EXECUTION_ID = ?";
76+
+ " TASK_COUNT, CONTINUABLE, EXIT_CODE, EXIT_MESSAGE from %PREFIX%STEP_EXECUTION where STEP_NAME = ? and JOB_EXECUTION_ID = ?";
7877

7978
private static final int EXIT_MESSAGE_LENGTH = 250;
8079

@@ -179,14 +178,13 @@ public void saveStepExecution(StepExecution stepExecution) {
179178
stepExecution.getStepName(), stepExecution.getJobExecutionId(), stepExecution.getStartTime(),
180179
stepExecution.getEndTime(), stepExecution.getStatus().toString(), stepExecution.getCommitCount(),
181180
stepExecution.getTaskCount(),
182-
PropertiesConverter.propertiesToString(stepExecution.getExecutionContext().getProperties()),
183181
stepExecution.getExitStatus().isContinuable() ? "Y" : "N", stepExecution.getExitStatus().getExitCode(),
184182
stepExecution.getExitStatus().getExitDescription() };
185183
getJdbcTemplate().update(
186184
getQuery(SAVE_STEP_EXECUTION),
187185
parameters,
188186
new int[] { Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.INTEGER, Types.TIMESTAMP,
189-
Types.TIMESTAMP, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.CHAR,
187+
Types.TIMESTAMP, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.CHAR,
190188
Types.VARCHAR, Types.VARCHAR });
191189
}
192190

@@ -314,15 +312,14 @@ public void updateStepExecution(StepExecution stepExecution) {
314312
Integer version = new Integer(stepExecution.getVersion().intValue() + 1);
315313
Object[] parameters = new Object[] { stepExecution.getStartTime(), stepExecution.getEndTime(),
316314
stepExecution.getStatus().toString(), stepExecution.getCommitCount(), stepExecution.getTaskCount(),
317-
PropertiesConverter.propertiesToString(stepExecution.getExecutionContext().getProperties()),
318315
stepExecution.getExitStatus().isContinuable() ? "Y" : "N",
319316
stepExecution.getExitStatus().getExitCode(), exitDescription, version, stepExecution.getId(),
320317
stepExecution.getVersion() };
321318
int count = getJdbcTemplate().update(
322319
getQuery(UPDATE_STEP_EXECUTION),
323320
parameters,
324321
new int[] { Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.INTEGER, Types.INTEGER,
325-
Types.VARCHAR, Types.CHAR, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER,
322+
Types.CHAR, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER,
326323
Types.INTEGER });
327324

328325
// Avoid concurrent modifications...
@@ -356,7 +353,7 @@ public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
356353
stepExecution.setCommitCount(rs.getInt(6));
357354
stepExecution.setTaskCount(rs.getInt(7));
358355
stepExecution
359-
.setExitStatus(new ExitStatus("Y".equals(rs.getString(9)), rs.getString(10), rs.getString(11)));
356+
.setExitStatus(new ExitStatus("Y".equals(rs.getString(8)), rs.getString(9), rs.getString(10)));
360357
stepExecution.setExecutionContext(findExecutionContext(stepExecution));
361358
return stepExecution;
362359
}
@@ -408,7 +405,6 @@ public static AttributeType getType(String typeAsString) {
408405
return null;
409406
}
410407
}
411-
412408
public StepExecution getStepExecution(JobExecution jobExecution, Step step) {
413409
List executions = getJdbcTemplate().query(getQuery(GET_STEP_EXECUTION),
414410
new Object[] { step.getName(), jobExecution.getId() }, new StepExecutionRowMapper(jobExecution, step));

spring-batch-execution/src/main/resources/schema-db2.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ CREATE TABLE BATCH_STEP_EXECUTION (
4646
STATUS VARCHAR(10),
4747
COMMIT_COUNT BIGINT ,
4848
TASK_COUNT BIGINT ,
49-
TASK_STATISTICS VARCHAR(4000),
5049
CONTINUABLE CHAR(1),
5150
EXIT_CODE VARCHAR(20),
5251
EXIT_MESSAGE VARCHAR(2500));

spring-batch-execution/src/main/resources/schema-derby.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ CREATE TABLE BATCH_STEP_EXECUTION (
4646
STATUS VARCHAR(10),
4747
COMMIT_COUNT BIGINT ,
4848
TASK_COUNT BIGINT ,
49-
TASK_STATISTICS VARCHAR(4000),
5049
CONTINUABLE CHAR(1),
5150
EXIT_CODE VARCHAR(20),
5251
EXIT_MESSAGE VARCHAR(2500));

spring-batch-execution/src/main/resources/schema-hsqldb.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ CREATE TABLE BATCH_STEP_EXECUTION (
4646
STATUS VARCHAR(10),
4747
COMMIT_COUNT BIGINT ,
4848
TASK_COUNT BIGINT ,
49-
TASK_STATISTICS VARCHAR(4000),
5049
CONTINUABLE CHAR(1),
5150
EXIT_CODE VARCHAR(20),
5251
EXIT_MESSAGE VARCHAR(2500));

spring-batch-execution/src/main/resources/schema-mysql.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ CREATE TABLE BATCH_STEP_EXECUTION (
4646
STATUS VARCHAR(10),
4747
COMMIT_COUNT BIGINT ,
4848
TASK_COUNT BIGINT ,
49-
TASK_STATISTICS VARCHAR(4000),
5049
CONTINUABLE CHAR(1),
5150
EXIT_CODE VARCHAR(20),
5251
EXIT_MESSAGE VARCHAR(2500));

spring-batch-execution/src/main/resources/schema-oracle10g.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ CREATE TABLE BATCH_STEP_EXECUTION (
4646
STATUS VARCHAR(10),
4747
COMMIT_COUNT NUMBER(38) ,
4848
TASK_COUNT NUMBER(38) ,
49-
TASK_STATISTICS VARCHAR(4000),
5049
CONTINUABLE CHAR(1),
5150
EXIT_CODE VARCHAR(20),
5251
EXIT_MESSAGE VARCHAR(2500));

spring-batch-execution/src/main/resources/schema-postgresql.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ CREATE TABLE BATCH_STEP_EXECUTION (
4646
STATUS VARCHAR(10),
4747
COMMIT_COUNT BIGINT ,
4848
TASK_COUNT BIGINT ,
49-
TASK_STATISTICS VARCHAR(4000),
5049
CONTINUABLE CHAR(1),
5150
EXIT_CODE VARCHAR(20),
5251
EXIT_MESSAGE VARCHAR(2500));

spring-batch-execution/src/main/sql/init.sql.vpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ CREATE TABLE BATCH_STEP_EXECUTION (
3535
STATUS VARCHAR(10),
3636
COMMIT_COUNT ${BIGINT} ,
3737
TASK_COUNT ${BIGINT} ,
38-
TASK_STATISTICS VARCHAR(4000),
3938
CONTINUABLE CHAR(1),
4039
EXIT_CODE VARCHAR(20),
4140
EXIT_MESSAGE VARCHAR(2500));

spring-batch-execution/src/test/resources/org/springframework/batch/execution/repository/dao/init.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ CREATE TABLE BATCH_STEP_EXECUTION (
3535
STATUS VARCHAR(10),
3636
COMMIT_COUNT BIGINT ,
3737
TASK_COUNT BIGINT ,
38-
TASK_STATISTICS VARCHAR(4000),
3938
CONTINUABLE CHAR(1),
4039
EXIT_CODE VARCHAR(20),
4140
EXIT_MESSAGE VARCHAR(2500));

0 commit comments

Comments
 (0)