rdf4j icon indicating copy to clipboard operation
rdf4j copied to clipboard

Statement is incorrectly lost from memory store

Open ieurich opened this issue 3 years ago • 5 comments

Current Behavior

  1. Add a statement with a context to a memory store and commit.
  2. Start a new transaction and clear the context of that statement.
  3. Add the statement back in.
  4. Do a getStatements to fetch the statement but not passing any context in.
  5. Iterate the statements returned - the expected statement is correctly returned at this point.
  6. Close the results.
  7. Commit the transaction started in step 2.
  8. Do another getStatements to fetch the statement - the statement IS NOT returned.

Expected Behavior

  1. Add a statement with a context to a memory store and commit.
  2. Start a new transaction and clear the context of that statement.
  3. Add the statement back in.
  4. Do a getStatements to fetch the statement but not passing any context in.
  5. Iterate the statements returned - the expected statement is correctly returned at this point.
  6. Close the results.
  7. Commit the transaction started in step 2.
  8. Do another getStatements to fetch the statement - the statement IS returned.

Steps To Reproduce

  1. Add a statement with a context to a memory store and commit.
  2. Start a new transaction and clear the context of that statement.
  3. Add the statement back in.
  4. Do a getStatements to fetch the statement but not passing any context in.
  5. Iterate the statements returned - the expected statement is correctly returned at this point.
  6. Close the results.
  7. Commit the transaction started in step 2.
  8. 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?

MissingStatementTest.zip

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?

ieurich avatar Sep 09 '22 11:09 ieurich

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?

ieurich avatar Sep 09 '22 14:09 ieurich

You can try to backport it, but it might be hard because the Changeset code has had a complete overhaul recently.

hmottestad avatar Sep 09 '22 14:09 hmottestad

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.

hmottestad avatar Sep 09 '22 15:09 hmottestad

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 avatar Sep 09 '22 17:09 ieurich

@ieurich Will you be able to contribute a fix for this?

hmottestad avatar Sep 18 '22 05:09 hmottestad