Eliminate unnecessary query for current version#4797
Open
quaff wants to merge 1 commit into
Open
Conversation
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 <zhouyanming@gmail.com>
Contributor
|
Thank you for the PR. I think we still need to check for the version in the database before throwing the OLFE. In fact, that's what this kind of guards are for, not necessarily for troubleshooting. Similarly to what was added in 549c1ef, I think an additional check is missing as well: public void deleteJobInstance(JobInstance jobInstance) {
int count = getJdbcTemplate().update(getQuery(DELETE_JOB_INSTANCE), jobInstance.getId(),
jobInstance.getVersion());
if (count == 0) {
// At this point, what if another thread is/was trying to update the instance (ie has changed the version)
// in the database while we are trying to delete it? So I think we need to query for the version here
// before throwing an exception.
throw new OptimisticLockingFailureException("Attempt to delete job instance id="
+ jobInstance.getId() + " with wrong version (" + jobInstance.getVersion() + ")");
}
}I understand that this is unlikely and I might be missing something, but I think this is what all this optimistic locking strategy is there for. Do you agree? |
Contributor
Author
|
This commit doesn't break optimistic locking, just removing useless current version from OptimisticLockingFailureException message to eliminate one db query. |
Contributor
Author
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.