Transactions - tx.commit vs tx.close

I have a question related to transactions. I'm having issues with tx.commit() hanging locally when running through Tinkerpop (this is fine when connected to Amazon Neptune), although tx.close() does seem to work instead. So I'm wondering whats the difference between tx.commit() and tx.close() ? Are they ok to be substituted for one another?
6 Replies
spmallette
spmallette2y ago
Could you please clarify what you mean by "hanging locally"? do you mean you are using Gremlin Server locally when testing in lieu of Neptune?
charlotte.brady
charlotte.bradyOP2y ago
correct - I'm writing/testing a script to update some edges. Locally we connect to Gremlin Server this is where I am having the issue
spmallette
spmallette2y ago
Gremlin Server uses TinkerGraph by default. TinkerGraph does not support transactions and I assume you've not changed the default graph configuration. I'm a bit surprised it ends in hanging though and if that is the case we should probably make some improvement there. For now, if you want to mimic Neptune behavior locally, you will want to use a graph that supports transactions in Gremlin Server. Options would include configuring Neo4j, an in-memory JanusGraph, Bitsy, or the like. In the future, there are plans to make it so that TinkerGraph has a very simple transaction system cc/ @Valentyn Kahamlyk which will make it a better default local testing system. does that make sense? I don't see a hanging behavior with the Java driver:
gremlin> g = traversal().withRemote(DriverRemoteConnection.using("localhost",8182,"g"))
==>graphtraversalsource[emptygraph[empty], standard]
gremlin> g.V()
gremlin> tx = g.tx()
==>org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteTransaction@3c46dcbe
gremlin> gtx = tx.begin()
==>graphtraversalsource[emptygraph[empty], standard]
gremlin> gtx.addV('person').iterate()
gremlin> tx.commit()
Transaction commit for Optional.empty failed
gremlin> g = traversal().withRemote(DriverRemoteConnection.using("localhost",8182,"g"))
==>graphtraversalsource[emptygraph[empty], standard]
gremlin> g.V()
gremlin> tx = g.tx()
==>org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteTransaction@3c46dcbe
gremlin> gtx = tx.begin()
==>graphtraversalsource[emptygraph[empty], standard]
gremlin> gtx.addV('person').iterate()
gremlin> tx.commit()
Transaction commit for Optional.empty failed
the error message is poor in Gremlin Console, but within the stack trace the reason is quite clear (and if you were building a Java application this is the message you would get:
Caused by: java.util.concurrent.CompletionException: org.apache.tinkerpop.gremlin.driver.exception.ResponseException: Graph does not support transactions
Caused by: java.util.concurrent.CompletionException: org.apache.tinkerpop.gremlin.driver.exception.ResponseException: Graph does not support transactions
Given the tag that you have on this question it appears you are using javascript. I've created: https://issues.apache.org/jira/browse/TINKERPOP-2913 to track this issue. Thank you for bringing it up.
charlotte.brady
charlotte.bradyOP2y ago
Interesting... the transaction seems to complete when I use tx.close() though (as my tests for the transaction result pass) which seems to conflict with the above?
spmallette
spmallette2y ago
There is something unique to Neptune that will commit the transaction on tx.close(). Note that in Java, I get the same error for trying to call that method:
gremlin> tx.close()
Transaction commit for Optional.empty failed
Type ':help' or ':h' for help.
Display stack trace? [yN]y
java.lang.RuntimeException: Transaction commit for Optional.empty failed
gremlin> tx.close()
Transaction commit for Optional.empty failed
Type ':help' or ':h' for help.
Display stack trace? [yN]y
java.lang.RuntimeException: Transaction commit for Optional.empty failed
Interesting that tx.close() works in Javascript. I'm not sure what Javascript is doing that is allowing tx.close() to work with TinkerGraph. I'll make a note on that JIRA to have that reviewed as well across programming languages. i think i'd avoid tx.close() if you can and prefer using a transactional graph for your local testing. it might be a bit annoying to have to setup Gremlin Server with in-memory JanusGraph or whatever you choose, but until TinkerGraph supports transactions i'd say that's the "right" way to do it. And, when TinkerGraph does support transactions you could simply swap back to it without having to change much.
charlotte.brady
charlotte.bradyOP2y ago
thanks for your help. It may be something to do with the docker image we are using for the gremlin server that this obscurity happens (that or our code!) I'll have a play around
Want results from more Discord servers?
Add your server