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
spmallette15mo 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.brady15mo 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
spmallette15mo 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.brady15mo 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
spmallette15mo 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.brady15mo 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
More Posts
Extracting the ProjectStep of a GraphTraversal instance during unit testing**Tl;dr** Given an instance of `GraphTraversal<?, Map<String, Object>>`, is it possible to extract tWhen can we get a non-RC release for Python 3.11 support in Production Envs?There was a bug where the version of aiohttp was too strict and blocked Python 3.11 support. ( httpsSubgraph query returns String instead of TinkerGraph Object in Fluent Java APIHi guys. I am running the following query in the console and it works fine: `g.V().has('user', 'id'Multiple Graphs in Gremlin Server?How do I manage multiple graphs? Is there an option where I can select which graph to use for query Has anyone else encountered "NoSuchElementException" when calling getLeafTrees() on a tree objectDid a little bit of debugging and it seems that the issue has to do with a cast to Tree before calliThe query gets slower as the number of vertices that already exist in JanusGraph gets bigger and bigWhen i start JanusGraph and perform any query like : - g.V().has(properties).limit(10).toList() - g.Is there a limitation on Neptune HTTP API endpoint compatibility when using a proxy and IAM Auth?Hi, Got a weird one today. I'm working on bringing full compatibility for the use of proxies frontiPreventing Janusgraph crash on timeoutAccording to this: https://stackoverflow.com/questions/61985018/janusgraph-image-stop-responding-aftWay to update static vertexhttps://docs.janusgraph.org/schema/advschema/#static-vertices I read document about TTL vertex. And Dotnet best practice: converting Vertex properties to ModelA very common task in Dotnet is to convert a stored entity into a Model class. How is this best acco