You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@jena.apache.org by "sszuev (via GitHub)" <gi...@apache.org> on 2024/01/15 09:17:31 UTC

[I] [GraphTxn] upgrade 4.10.0 -> 5.0.0-SNAPSHOT: JenaTransactionException [jena]

sszuev opened a new issue, #2195:
URL: https://github.com/apache/jena/issues/2195

   ### Version
   
   5.0.0-SNAPSHOT
   
   ### What happened?
   
   The following code works fine in version 4.10.0, but throws an exception in version 5.0.0-SNAPSHOT:
   ```java
   Model m = ModelFactory.createModelForGraph(new GraphTxn());
   Node x = m.createResource("X", OWL.Class).asNode();
   Graph g = m.getGraph();
   ExtendedIterator<Triple> it = g.find(Triple.create(x, Node.ANY, Node.ANY));
   it.toList();
   g.add(Triple.create(NodeFactory.createURI("42"), Node.ANY, Node.ANY));
   ```
   
   see also https://github.com/apache/jena/issues/1961
   
   ### Relevant output and stacktrace
   
   ```shell
   org.apache.jena.sparql.JenaTransactionException: Tried to write inside a READ transaction!
   
   	at org.apache.jena.sparql.core.mem.DatasetGraphInMemory.mutate(DatasetGraphInMemory.java:378)
   	at org.apache.jena.sparql.core.mem.DatasetGraphInMemory.addToDftGraph(DatasetGraphInMemory.java:413)
   	at org.apache.jena.sparql.core.DatasetGraphTriplesQuads.add(DatasetGraphTriplesQuads.java:47)
   	at org.apache.jena.sparql.core.GraphView.performAdd(GraphView.java:147)
   	at org.apache.jena.graph.impl.GraphBase.add(GraphBase.java:158)
   	at org.apache.jena.sparql.graph.GraphWrapper.add(GraphWrapper.java:40)
   	at com.gitlab.sszuev.playjena.GraphTxnTest.test(GraphTxnTest.java:30)
   	at java.base/java.lang.reflect.Method.invoke(Method.java:577)
   	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
   	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
   ```
   ```
   
   
   ### Are you interested in making a pull request?
   
   None


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org
For additional commands, e-mail: issues-help@jena.apache.org


Re: [I] [GraphTxn] upgrade 4.10.0 -> 5.0.0-SNAPSHOT: JenaTransactionException [jena]

Posted by "sszuev (via GitHub)" <gi...@apache.org>.
sszuev commented on issue #2195:
URL: https://github.com/apache/jena/issues/2195#issuecomment-1891934937

   and for a general understanding:
   I see also `JenaTransactionException: Tried to write inside a READ transaction!`, or error about illegal nested transactions
   so, in concurrent environment, it won't work? or error is expected to appear only in single thread environment (when our code calls read inside write or the opposite)?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org
For additional commands, e-mail: issues-help@jena.apache.org


Re: [I] [GraphTxn] upgrade 4.10.0 -> 5.0.0-SNAPSHOT: JenaTransactionException [jena]

Posted by "afs (via GitHub)" <gi...@apache.org>.
afs closed issue #2195: [GraphTxn] upgrade 4.10.0 -> 5.0.0-SNAPSHOT: JenaTransactionException
URL: https://github.com/apache/jena/issues/2195


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org
For additional commands, e-mail: issues-help@jena.apache.org


Re: [I] [GraphTxn] upgrade 4.10.0 -> 5.0.0-SNAPSHOT: JenaTransactionException [jena]

Posted by "rvesse (via GitHub)" <gi...@apache.org>.
rvesse commented on issue #2195:
URL: https://github.com/apache/jena/issues/2195#issuecomment-1891786883

   `GraphTxn` is intended to provide auto-commit style semantics for `Graph`'s.  However there was a bug in the `GraphTxn` implementation in the 4.10.0 release (#2086) where it incorrectly determined the current transaction state and wasn't always creating a transaction when necessary (and conversely would try to incorrectly create a transaction when unnecessary)
   
   So the behaviour you are seeing with 5.0.0-SNAPSHOT is the correct expected behaviour
   
   Creating the iterator starts a read transaction that isn't committed until you explicitly `close()` the iterator.  Trying to do a `g.add()` tries to start a write transaction but it can't because the read transaction is still in progress.
   
   If you plan to use `GraphTxn` seriously then you should explicitly manage the transactions to get the transaction boundaries appropriate to your application.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org
For additional commands, e-mail: issues-help@jena.apache.org


Re: [I] [GraphTxn] upgrade 4.10.0 -> 5.0.0-SNAPSHOT: JenaTransactionException [jena]

Posted by "afs (via GitHub)" <gi...@apache.org>.
afs commented on issue #2195:
URL: https://github.com/apache/jena/issues/2195#issuecomment-1892822692

   See also #2086, which backports a Jena5 fix to the Jena4 branch.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org
For additional commands, e-mail: issues-help@jena.apache.org


Re: [I] [GraphTxn] upgrade 4.10.0 -> 5.0.0-SNAPSHOT: JenaTransactionException [jena]

Posted by "sszuev (via GitHub)" <gi...@apache.org>.
sszuev commented on issue #2195:
URL: https://github.com/apache/jena/issues/2195#issuecomment-1891818752

   this test works without exception in early releases, e.g. 4.7.0
   
   perhaps it was always working incorrectly? If so, it would be surprise for end-users.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org
For additional commands, e-mail: issues-help@jena.apache.org


Re: [I] [GraphTxn] upgrade 4.10.0 -> 5.0.0-SNAPSHOT: JenaTransactionException [jena]

Posted by "afs (via GitHub)" <gi...@apache.org>.
afs commented on issue #2195:
URL: https://github.com/apache/jena/issues/2195#issuecomment-1902759437

   There isn't anything remaining here outside of #2197 that I can see.
   Please reopen if anything has been missed.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org
For additional commands, e-mail: issues-help@jena.apache.org


Re: [I] [GraphTxn] upgrade 4.10.0 -> 5.0.0-SNAPSHOT: JenaTransactionException [jena]

Posted by "afs (via GitHub)" <gi...@apache.org>.
afs commented on issue #2195:
URL: https://github.com/apache/jena/issues/2195#issuecomment-1892798174

   > I guess the returned iterator isn't aware that toList() effectively consumes it so it isn't close()'d 
   
   Looks that way. The code isn't seeing hasNext: true -> false nor is `hasNext` being called.
   
   `GraphTxn.toList` uses `ExtendedIterator.forEachRemaining` which in `WrappedIterator` call the wrapped class and so bypasses `hasNext`.
   
   For clarity - there is now a specific issue for this: https://github.com/apache/jena/issues/2197
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org
For additional commands, e-mail: issues-help@jena.apache.org


Re: [I] [GraphTxn] upgrade 4.10.0 -> 5.0.0-SNAPSHOT: JenaTransactionException [jena]

Posted by "sszuev (via GitHub)" <gi...@apache.org>.
sszuev commented on issue #2195:
URL: https://github.com/apache/jena/issues/2195#issuecomment-1891974098

   > `GraphTxn` is intended to provide auto-commit style semantics for `Graph`'s. However there was a bug in the `GraphTxn` implementation in the 4.10.0 release (#2086) where it incorrectly determined the current transaction state and wasn't always creating a transaction when necessary (and conversely would try to incorrectly create a transaction when unnecessary)
   > 
   > So the behaviour you are seeing with 5.0.0-SNAPSHOT is the correct expected behaviour
   > 
   > Creating the iterator starts a read transaction that isn't committed until you explicitly `close()` the iterator. Trying to do a `g.add()` tries to start a write transaction but it can't because the read transaction is still in progress.
   > 
   > If you plan to use `GraphTxn` seriously then you should explicitly manage the transactions to get the transaction boundaries appropriate to your application.
   
   additional note about the original issue. the following test also works in < 5.0.0-SNAPSHOT.
   So, the easiest fix to add `close` in terminal operations (such as `toList`) won't help.
   ```
   Node x = NodeFactory.createURI("X");
   Node q = NodeFactory.createURI("Q");
   GraphTxn g = new GraphTxn();
   g.add(Triple.create(x, q, q));
   ExtendedIterator<Triple> it = g.find(Triple.create(x, Node.ANY, Node.ANY));
   it.next();
   g.add(Triple.create(q, q, x));
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org
For additional commands, e-mail: issues-help@jena.apache.org


Re: [I] [GraphTxn] upgrade 4.10.0 -> 5.0.0-SNAPSHOT: JenaTransactionException [jena]

Posted by "sszuev (via GitHub)" <gi...@apache.org>.
sszuev commented on issue #2195:
URL: https://github.com/apache/jena/issues/2195#issuecomment-1892410709

   One more exception. This time "Transactions cannot be nested!"
   ```
   GraphTxn g = new GraphTxn();
   System.out.println(g.find().toList().size()); // if g.size() no exception
   
   g.begin(TxnType.READ);
   System.out.println(g.size());
   g.end();
   ```
   
   ```
   org.apache.jena.sparql.JenaTransactionException: Transactions cannot be nested!
   
   	at org.apache.jena.sparql.core.mem.DatasetGraphInMemory.begin(DatasetGraphInMemory.java:149)
   	at org.apache.jena.sparql.graph.GraphTxn.begin(GraphTxn.java:67)
   	at com.gitlab.sszuev.playjena.GraphTxnTest.test(GraphTxnTest.java:30)
   	at java.base/java.lang.reflect.Method.invoke(Method.java:577)
   	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
   	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
   
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org
For additional commands, e-mail: issues-help@jena.apache.org


Re: [I] [GraphTxn] upgrade 4.10.0 -> 5.0.0-SNAPSHOT: JenaTransactionException [jena]

Posted by "sszuev (via GitHub)" <gi...@apache.org>.
sszuev commented on issue #2195:
URL: https://github.com/apache/jena/issues/2195#issuecomment-1892473113

   5.0.0-SNAPSHOT
   as you said before `toList()` should cause an exception ? 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org
For additional commands, e-mail: issues-help@jena.apache.org


Re: [I] [GraphTxn] upgrade 4.10.0 -> 5.0.0-SNAPSHOT: JenaTransactionException [jena]

Posted by "rvesse (via GitHub)" <gi...@apache.org>.
rvesse commented on issue #2195:
URL: https://github.com/apache/jena/issues/2195#issuecomment-1892179687

   > this test works without exception in early versions, for example, 4.7.0
   > 
   > perhaps it has always worked incorrectly? If so, it would be a surprise to end users.
   
   Yes, that's related to your discussion in #1961 which @afs addressed in #1964.  In earlier releases of Jena the `GraphTxn.find()` was not run in a transaction at all.
   
   Sometimes bugs exist silently for a long time before a user/developer spots e.g. #2150 was only recently reported by a user and I complete coincidentally also hit another instance of that bug in the same week.  That's just the nature of any sufficiently large software project
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org
For additional commands, e-mail: issues-help@jena.apache.org


Re: [I] [GraphTxn] upgrade 4.10.0 -> 5.0.0-SNAPSHOT: JenaTransactionException [jena]

Posted by "rvesse (via GitHub)" <gi...@apache.org>.
rvesse commented on issue #2195:
URL: https://github.com/apache/jena/issues/2195#issuecomment-1892461884

   > One more exception. This time "Transactions cannot be nested!"
   > 
   > ```
   > GraphTxn g = new GraphTxn();
   > System.out.println(g.find().toList().size()); // if g.size() no exception
   > 
   > g.begin(TxnType.READ);
   > System.out.println(g.size());
   > g.end();
   > ```
   > 
   >  ```
   > org.apache.jena.sparql.JenaTransactionException: Transactions cannot be nested!
   > 
   > 	at org.apache.jena.sparql.core.mem.DatasetGraphInMemory.begin(DatasetGraphInMemory.java:149)
   > 	at org.apache.jena.sparql.graph.GraphTxn.begin(GraphTxn.java:67)
   > 	at com.gitlab.sszuev.playjena.GraphTxnTest.test(GraphTxnTest.java:30)
   > 	at java.base/java.lang.reflect.Method.invoke(Method.java:577)
   > 	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
   > 	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
   > ```
   
   In which Jena version?  5.0.0-SNAPSHOT?
   
   I guess the returned iterator isn't aware that `toList()` effectively consumes it so it isn't `close()`'d and thus never terminates the automatically begun transaction?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org
For additional commands, e-mail: issues-help@jena.apache.org


Re: [I] [GraphTxn] upgrade 4.10.0 -> 5.0.0-SNAPSHOT: JenaTransactionException [jena]

Posted by "afs (via GitHub)" <gi...@apache.org>.
afs commented on issue #2195:
URL: https://github.com/apache/jena/issues/2195#issuecomment-1892776947

   The `Txn` allows transaction-in-transaction. It is not full nested transactions. It tests whether the original outer transaction permits the inner one. Only committing the outer one will commit the externally visible transaction.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org
For additional commands, e-mail: issues-help@jena.apache.org