rdf4j
rdf4j copied to clipboard
Statement is incorrectly lost from memory store
Current Behavior
- Add a statement with a context to a memory store and commit.
- Start a new transaction and clear the context of that statement.
- Add the statement back in.
- Do a getStatements to fetch the statement but not passing any context in.
- Iterate the statements returned - the expected statement is correctly returned at this point.
- Close the results.
- Commit the transaction started in step 2.
- Do another getStatements to fetch the statement - the statement IS NOT returned.
Expected Behavior
- Add a statement with a context to a memory store and commit.
- Start a new transaction and clear the context of that statement.
- Add the statement back in.
- Do a getStatements to fetch the statement but not passing any context in.
- Iterate the statements returned - the expected statement is correctly returned at this point.
- Close the results.
- Commit the transaction started in step 2.
- Do another getStatements to fetch the statement - the statement IS returned.
Steps To Reproduce
- Add a statement with a context to a memory store and commit.
- Start a new transaction and clear the context of that statement.
- Add the statement back in.
- Do a getStatements to fetch the statement but not passing any context in.
- Iterate the statements returned - the expected statement is correctly returned at this point.
- Close the results.
- Commit the transaction started in step 2.
- Do another getStatements to fetch the statement - the statement IS NOT returned.
Version
3.7.7
Are you interested in contributing a solution yourself?
Perhaps?
Anything else?
Have attached a test case to reproduce the issue. The issue does seem to be fixed in v4 but we are unable to upgrade to that at the moment as we are not yet on Java 11. Is there any kind of patch that can be applied to fix this in v3?
Actually it looks like the issue was fixed by the changes to Changeset.java in this commit - https://github.com/eclipse/rdf4j/commit/84a6f7b59e19e15d7876f76aa2e0eb7f59088459#diff-ef3b3744327f7ef84b1c56e0b342b581dd8f7e6d286bdc5a4da5c4e89febba9f. The cleared statement was being returned by the main store incorrectly and then being removed from the changeset by DistinctModelReducingUnionIteration.getNextElement() to prevent duplicates being returned.
Would it be safe to just patch those hasDeprecated methods?
You can try to backport it, but it might be hard because the Changeset code has had a complete overhaul recently.
Otherwise I would highly recommend upgrading to Java 11 (or preferably 17) and take advantage of all the new features and performance improvements in the latest RDF4J release.
I understand it's hard to upgrade, it was quite hard for us too.
The fix seems quite self-contained to me. I think as long as the Changset.hasDeprecated methods are logically correct then we should be ok. I know there was another change to use explicit locks instead of synchronized blocks but we can live without that for now.
@ieurich Will you be able to contribute a fix for this?