sszuev commented on issue #1961:
URL: https://github.com/apache/jena/issues/1961#issuecomment-1900662518

   >  However, I'm puzzled about their practicality without transaction 
support. For instance, consider the following code snippet which lacks 
transactional context, leading to no guaranteed consistency between successive 
method calls to the graph
   
   Practical use is discussed above. I suggested considering adding a new 
functionality to Jena - a concurrent graph. It is needed for ONT-API. 
Additionally, I have provided an answer from Chat-GPT about when a 
non-transactional graph can be used.
   
   In short, the relationship between a concurrent and a transactional graph is 
similar to the relationship between a JDK's `ConcurrentHashMap` and a Redis.
   We still use `ConcurrentHashMap`, although there is no guarantee of 
consistency.
   Moreover, based on it you can make a cache, or even a transaction graph.
   
   > The wrapper is coded like this
   
   This code is already present in the `jena-5.x.x` & `jena-5.x.x-SWMR` branch, 
otherwise I would not be able to collect benchmarks due to 
`JenaTransactionException`:
   
   It is made via kotlin's extension functions, 
   see 
https://github.com/sszuev/concurrent-rdf-graph/blob/jena-5.x.x-SWMR/src/test/kotlin/TestGraphs.kt#L83
 :
   ```kotlin
   fun <X> Graph.transactionWrite(action: Graph.() -> X): X {
       try {
           startWrite()
           return action()
       } finally {
           endWrite()
       }
   }
   
   private fun Graph.startRead() {
       if (this is Transactional) {
           this.begin(TxnType.READ)
       }
   }
   
   private fun Graph.endRead() {
       if (this is Transactional) {
           this.end()
       }
   }
       fun createFrom(source: Graph): Graph {
           val res = createNew()
           res.transactionWrite {
               source.find().forEach { res.add(it) }
           }
           return res
       }
   ```


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to