-
Notifications
You must be signed in to change notification settings - Fork 2.4k
JdbcPagingItemReader with sort key crashes in multithreaded step for empty query #3898
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
Labels
for: backport-to-4.2.x
Issues that will be back-ported to the 4.2.x line
in: infrastructure
type: bug
Milestone
Comments
Thank you for reporting this issue. Indeed, the reader fails with an empty result set in a multi-threaded step. |
fmbenhassine
pushed a commit
that referenced
this issue
Sep 24, 2021
On empty input, the JdbcPagingItemReader cannot derive a start value for the sort key to be used in further queries. For multi-threaded steps, it is thus necessary to prevent the reader from trying to read further pages if the first page is empty. Issue #3898
Resolved with #3959. |
fmbenhassine
pushed a commit
that referenced
this issue
Sep 24, 2021
On empty input, the JdbcPagingItemReader cannot derive a start value for the sort key to be used in further queries. For multi-threaded steps, it is thus necessary to prevent the reader from trying to read further pages if the first page is empty. Issue #3898
fmbenhassine
pushed a commit
that referenced
this issue
Sep 24, 2021
On empty input, the JdbcPagingItemReader cannot derive a start value for the sort key to be used in further queries. For multi-threaded steps, it is thus necessary to prevent the reader from trying to read further pages if the first page is empty. Issue #3898
The fix is broken now as the "startAfterValues" is never null. I think an additional check on |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
for: backport-to-4.2.x
Issues that will be back-ported to the 4.2.x line
in: infrastructure
type: bug
Bug description
JdbcPagingItemReader cannot handle queries without results if multithreading and sorting are active together.
remainingPagesSql
is erroneously executed by other thread, if first thread found no results. SindstartAfterValues
was never set by first thread, any sort key parameters is missing.Environment
Java version: AdoptOpenJDK 11 (11.0.6)
Spring Batch version: spring-boot-starter-batch:2.4.3 (spring-batch-core:4.3.1)
Database: Postgres 13 (helm chart bitnami/postgres with image tags modified to 13.1.0-debian-10-r18)
Steps to reproduce
Expected behavior
If thread 1 already got 0 results, I would expect thread 2 to either never enter doPageRead or just return an empty page without performing the actual query. In any case. I expect my step not to crash, but to simply finish with readCount == 0.
I'm not sure which entry condition is the culprit. I suspect it might be the
current >= pageSize
in AbstractPagingItemReader::doRead, but I'm not sure if that's intentional. Seems strange to me though, to allow another page query ifcurrent == pageSize
, but there could be some finishing situations that I'm not considering.Minimal Complete Reproducible example
Simplified snippet from my own code at work. Not quite complete, so will take some massaging to hook it up to real types, tables, etc. but get's the point across. Parameter
import_timestamp
is found by both firstPageSql and remainingPagesSql, whereas the parameter_uuid
that is generated out of the sort condition is not found by remainingPagesSql if firstPageSql returns no results. This isn't an issue if single threaded because remainingPagesSql never runs, but if multithreaded, the other threads are already waiting at the lock and then run the remainingPagesSql anyway.The text was updated successfully, but these errors were encountered: