Skip to content

Improve update sql for optimistic locking #4792

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -74,6 +74,7 @@
* @author Dimitrios Liapis
* @author Philippe Marschall
* @author Jinwoo Bae
* @author Yanming Zhou
*/
public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements JobExecutionDao, InitializingBean {

@@ -98,7 +99,7 @@ SELECT COUNT(*)

private static final String UPDATE_JOB_EXECUTION = """
UPDATE %PREFIX%JOB_EXECUTION
SET START_TIME = ?, END_TIME = ?, STATUS = ?, EXIT_CODE = ?, EXIT_MESSAGE = ?, VERSION = ?, CREATE_TIME = ?, LAST_UPDATED = ?
SET START_TIME = ?, END_TIME = ?, STATUS = ?, EXIT_CODE = ?, EXIT_MESSAGE = ?, VERSION = VERSION + 1, CREATE_TIME = ?, LAST_UPDATED = ?
WHERE JOB_EXECUTION_ID = ? AND VERSION = ?
""";

@@ -284,7 +285,6 @@ public void updateJobExecution(JobExecution jobExecution) {

this.lock.lock();
try {
Integer version = jobExecution.getVersion() + 1;

String exitDescription = jobExecution.getExitStatus().getExitDescription();
if (exitDescription != null && exitDescription.length() > exitMessageLength) {
@@ -301,7 +301,7 @@ public void updateJobExecution(JobExecution jobExecution) {
Timestamp lastUpdated = jobExecution.getLastUpdated() == null ? null
: Timestamp.valueOf(jobExecution.getLastUpdated());
Object[] parameters = new Object[] { startTime, endTime, jobExecution.getStatus().toString(),
jobExecution.getExitStatus().getExitCode(), exitDescription, version, createTime, lastUpdated,
jobExecution.getExitStatus().getExitCode(), exitDescription, createTime, lastUpdated,
jobExecution.getId(), jobExecution.getVersion() };

// Check if given JobExecution's Id already exists, if none is found
@@ -315,7 +315,7 @@ public void updateJobExecution(JobExecution jobExecution) {

int count = getJdbcTemplate().update(getQuery(UPDATE_JOB_EXECUTION), parameters,
new int[] { Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
Types.INTEGER, Types.TIMESTAMP, Types.TIMESTAMP, Types.BIGINT, Types.INTEGER });
Types.TIMESTAMP, Types.TIMESTAMP, Types.BIGINT, Types.INTEGER });

// Avoid concurrent modifications...
if (count == 0) {
Original file line number Diff line number Diff line change
@@ -66,6 +66,7 @@
* @author Mahmoud Ben Hassine
* @author Baris Cubukcuoglu
* @author Minsoo Kim
* @author Yanming Zhou
* @see StepExecutionDao
*/
public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implements StepExecutionDao, InitializingBean {
@@ -79,7 +80,7 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement

private static final String UPDATE_STEP_EXECUTION = """
UPDATE %PREFIX%STEP_EXECUTION
SET START_TIME = ?, END_TIME = ?, STATUS = ?, COMMIT_COUNT = ?, READ_COUNT = ?, FILTER_COUNT = ?, WRITE_COUNT = ?, EXIT_CODE = ?, EXIT_MESSAGE = ?, VERSION = ?, READ_SKIP_COUNT = ?, PROCESS_SKIP_COUNT = ?, WRITE_SKIP_COUNT = ?, ROLLBACK_COUNT = ?, LAST_UPDATED = ?
SET START_TIME = ?, END_TIME = ?, STATUS = ?, COMMIT_COUNT = ?, READ_COUNT = ?, FILTER_COUNT = ?, WRITE_COUNT = ?, EXIT_CODE = ?, EXIT_MESSAGE = ?, VERSION = VERSION + 1, READ_SKIP_COUNT = ?, PROCESS_SKIP_COUNT = ?, WRITE_SKIP_COUNT = ?, ROLLBACK_COUNT = ?, LAST_UPDATED = ?
WHERE STEP_EXECUTION_ID = ? AND VERSION = ?
""";

@@ -267,7 +268,6 @@ public void updateStepExecution(StepExecution stepExecution) {
this.lock.lock();
try {

Integer version = stepExecution.getVersion() + 1;
Timestamp startTime = stepExecution.getStartTime() == null ? null
: Timestamp.valueOf(stepExecution.getStartTime());
Timestamp endTime = stepExecution.getEndTime() == null ? null
@@ -277,13 +277,13 @@ public void updateStepExecution(StepExecution stepExecution) {
Object[] parameters = new Object[] { startTime, endTime, stepExecution.getStatus().toString(),
stepExecution.getCommitCount(), stepExecution.getReadCount(), stepExecution.getFilterCount(),
stepExecution.getWriteCount(), stepExecution.getExitStatus().getExitCode(), exitDescription,
version, stepExecution.getReadSkipCount(), stepExecution.getProcessSkipCount(),
stepExecution.getReadSkipCount(), stepExecution.getProcessSkipCount(),
stepExecution.getWriteSkipCount(), stepExecution.getRollbackCount(), lastUpdated,
stepExecution.getId(), stepExecution.getVersion() };
int count = getJdbcTemplate().update(getQuery(UPDATE_STEP_EXECUTION), parameters,
new int[] { Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.BIGINT, Types.BIGINT,
Types.BIGINT, Types.BIGINT, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.BIGINT,
Types.BIGINT, Types.BIGINT, Types.BIGINT, Types.TIMESTAMP, Types.BIGINT, Types.INTEGER });
Types.BIGINT, Types.BIGINT, Types.VARCHAR, Types.VARCHAR, Types.BIGINT, Types.BIGINT,
Types.BIGINT, Types.BIGINT, Types.TIMESTAMP, Types.BIGINT, Types.INTEGER });

// Avoid concurrent modifications...
if (count == 0) {