GH-5470: Avoid nested query in JdbcStepExecutionDao.getLastStepExecution - #5480
Open
arimu1 wants to merge 2 commits into
Open
GH-5470: Avoid nested query in JdbcStepExecutionDao.getLastStepExecution#5480arimu1 wants to merge 2 commits into
arimu1 wants to merge 2 commits into
Conversation
Read the last step execution id with a completed statement first, then load the full StepExecution. Nested queries while a row-limited ResultSet is open break databases that disallow multiple active portals (for example CockroachDB). Keep setMaxRows(1) for portability instead of SQL LIMIT. Signed-off-by: arimu1 <19286898+arimu1@users.noreply.github.com>
Drop setMaxRows(1) on the last-step id lookup so the portal reaches CommandComplete instead of PortalSuspended. Read only the first ordered row in Java, then call getStepExecution(long). Avoid SQL LIMIT for portability; document why default fetchSize keeps this safe. Signed-off-by: arimu1 <19286898+arimu1@users.noreply.github.com>
Author
|
Follow-up for the portal-completion case called out in #5470: Nesting alone was not enough. This push:
|
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.
Fixes #5470
JdbcStepExecutionDao.getLastStepExecutionpreviously calledjobExecutionDao.getJobParameters(a second JDBC statement) while aResultSetopened withsetMaxRows(1)was still active. On databasesthat refuse multiple simultaneously open portals (notably CockroachDB),
that nested prepare fails and restarts break whenever a prior
StepExecutionexists for the same job instance and step name.Changes
STEP_EXECUTION_IDfor the “last step execution” lookupstatement.setMaxRows(1)(no SQLLIMIT, which is notsupported by all databases Spring Batch targets)
JdbcTemplate, loadthe full
StepExecutionviagetStepExecution(long)This matches the sequential approach suggested in the issue and the
workaround of reading the id first then delegating to
getStepExecution(long).Note: open PR #5133 still performs
getJobExecutioninside the openResultSetcallback, so it does not address GH-5470.Testing
JdbcStepExecutionDaoTests(6 tests, including new coverage for same-joband cross-job-execution “last step” selection)
./mvnw -pl spring-batch-core -am test -Dtest=JdbcStepExecutionDaoTests