-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Add (JOB_INSTANCE_ID) unique constraint to JobExecution table #1475
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
Comments
Michael Minella commented This isn't quite that simple. The issue really stems from the fact that many databases don't support millisecond precision (MySql being one of those). Adding this constraint would prevent you from launching them any faster than once per second which is would probably not be good enough in some environments. |
Erwin Vervaet commented I agree that this doesn't really solve the problem. However, it prevents bad data (i.e. violating Spring Batch's assumption that the combination of job_instance_id and create_time uniquely identifies a JobExecution) from ending up in the database. Is there a clean way of recovering from a situation like this? As far as I know the only way out is directly manipulating the data in the database, something that I would like to avoid. In my opinion having the limitation that you can only launch one JobExecution for a particuler JobInstance per minimum time fragment supported by your database, is better than allowing normal framework usage from corrupting the frameworks internal data, forcing manual intervention. |
That said, I think the unique constraint should be added for |
I seem to have overlooked the failure scenario in my previous comment. Adding a unique constraint on |
Erwin Vervaet opened BATCH-2120 and commented
As originally hinted at by BATCH-1852, very quick jobs are poorly identified.
JdbcJobExecutionDao.getLastJobExecution() assumes that the combination of the JOB_INSTANCE_ID and CREATE_TIME uniquely identifies a JobExecution instance:
However, this is not enforced by a constraint in the database. This can give problems in certain situations, i.e. with fast running jobs on MySQL which does not have a millisecond data type (see http://forum.spring.io/forum/spring-projects/batch/78846-conflict-when-starting-3rd-times-a-job).
I would suggest to add such a constraint to the SQL scripts. For MySQL this could be:
No further details from BATCH-2120
The text was updated successfully, but these errors were encountered: