Skip to content
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

Large Bundles with lots of new CodeSystems and Ids hits JDBC Parameter Limit #3106

Closed
prb112 opened this issue Dec 9, 2021 · 4 comments
Closed
Assignees
Labels
bug Something isn't working persistence

Comments

@prb112
Copy link
Contributor

prb112 commented Dec 9, 2021

Describe the bug
A clear and concise description of what the bug is.

Caused by: java.io.IOException: Tried to send an out-of-range integer as a 2-byte value: 54842

Environment
Which version of IBM FHIR Server? main (and any with common_token_values)

To Reproduce
Steps to reproduce the behavior:

  1. Create an empty db
  2. Load fhir-server-test/src/test/resources/testdata/Bundle-ValueSets.json in a Transaction
  3. See the exception
Size 27421
[AUDIT   ] J2CA0056I: The Connection Manager received a fatal connection error from the Resource Adapter for resource jdbc/fhir_default_default. The exception is: org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.:java.io.IOException: Tried to send an out-of-range integer as a 2-byte value: 54842
[ERROR   ]  INSERT INTO common_token_values (token_value, code_system_id)       SELECT v.token_value, v.code_system_id         FROM (VALUES (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VAVARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS
....

1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)), (CAST(? AS VARCHAR(1024)),CAST(? AS INT)) ) AS v(token_value, code_system_id)     ORDER BY v.code_system_id, v.token_value  ON CONFLICT DO NOTHING 
An I/O error occurred while sending to the backend.
[ERROR   ] Unexpected error while processing token value records.
org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.
[ERROR   ] Failed persisting parameter transaction data. Marking transaction for rollback
Unexpected error while processing token value records.
[ERROR   ] DSRA0304E:  XAException occurred. XAException contents and details are: 
Caused by org.postgresql.util.PSQLException: This connection has been closed.
The error code is: 0
The SQL State is: 08003
.
[ERROR   ] DSRA0302E:  XAException occurred.  Error code is: XAER_RMFAIL (-7).  Exception is: Error rolling back prepared transaction. rollback xid={XidImpl: formatId(57415344), gtrid_length(36), bqual_length(54),
data(0000017da109aa890000000103e7bb10b25c34e944ee51fe8607ab962e5c11ff9c9386460000017da109aa890000000103e7bb10b25c34e944ee51fe8607ab962e5c11ff9c938646000000010000000000000000000000000001)}, preparedXid=null, currentXid={2}
[ERROR   ] failed to commit transaction
javax.transaction.RollbackException
[ERROR   ] Commit global transaction failed. See server log for details
Commit global transaction failed. See server log for details

Expected behavior
A clear and concise description of what you expected to happen.

Additional context
Add any other context about the problem here.

https://stackoverflow.com/questions/1009706/postgresql-max-number-of-parameters-in-in-clause
https://luppeng.wordpress.com/2020/05/20/postgresql-jdbc-driver-upper-limit-on-parameters-in-preparedstatement/

@prb112 prb112 added bug Something isn't working persistence labels Dec 9, 2021
@prb112 prb112 self-assigned this Dec 9, 2021
prb112 added a commit that referenced this issue Dec 10, 2021
Limit #3106

- Add Max Query Parameter for Postgres
- Add Test Updates for CQL

Signed-off-by: Paul Bastide <[email protected]>
@prb112
Copy link
Contributor Author

prb112 commented Feb 10, 2022

Refactored to be more deterministic and easier to read.
There is agreement that we won't implement a GTT and use a merge into at this juncture.

prb112 added a commit that referenced this issue Feb 15, 2022
…r Limit #3106 (#3108)

* From Execution/Code Review

- Add step to reset the resources with addToRegistry method which links
with the delete method in AfterClass
- Improve the toString for ReferenceParameter as it split multiple lines
with JSON output

Signed-off-by: Paul Bastide <[email protected]>

* Large Bundles with lots of new CodeSystems and Ids hits JDBC Parameter
Limit #3106

- Add Max Query Parameter for Postgres
- Add Test Updates for CQL

Signed-off-by: Paul Bastide <[email protected]>

* Update to use Optional

Signed-off-by: Paul Bastide <[email protected]>

* Optimizations to Tests and Cleanup System.out usage

Signed-off-by: Paul Bastide <[email protected]>

* Update for Java8 Support

Signed-off-by: Paul Bastide <[email protected]>

* Update Db2 Limit

Signed-off-by: Paul Bastide <[email protected]>

* Optimization to the Build Process for Export/Profiles/Import and Update ResourceReference DAO

Signed-off-by: Paul Bastide <[email protected]>

* Update to Optimize Metadata Fetch during integration test

Signed-off-by: Paul Bastide <[email protected]>

* Update per latest code in main

Signed-off-by: Paul Bastide <[email protected]>

* Update Operation test

Signed-off-by: Paul Bastide <[email protected]>

* Update per merge

Signed-off-by: Paul Bastide <[email protected]>

* Refactor per code review

Signed-off-by: Paul Bastide <[email protected]>

* Update fhir-persistence-jdbc/src/main/java/com/ibm/fhir/persistence/jdbc/dao/impl/ResourceReferenceDAO.java

Signed-off-by: Paul Bastide <[email protected]>
@punktilious
Copy link
Collaborator

Generates invalid SQL when there are more than 16383 items to process:

INSERT INTO common_token_values (token_value, code_system_id)       SELECT v.token_value, v.code_system_id         FROM (VALUES  ) AS v(token_value, code_system_id)     ORDER BY v.code_system_id, v.token_value  ON CONFLICT DO NOTHING
org.postgresql.util.PSQLException: ERROR: syntax error at or near ")"

@prb112
Copy link
Contributor Author

prb112 commented Feb 22, 2022

Ran through the code - the window was pruned, now a sliding window.

@punktilious
Copy link
Collaborator

Loaded fhir-server-test/src/test/resources/testdata/Bundle-ValueSets.json which created the new entries, then loaded the same bundle a few more times to make sure there is no regression in the parts of the code where the values already exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working persistence
Projects
None yet
Development

No branches or pull requests

2 participants