0

I'm trying to use Gremlin sessions with Amazon Neptune and using GroovyTranslator to submit String queries, as shown in below snippet

 Client.SessionedClient sclient = cluster.connect(sessionId, false);
 GraphTraversalSource g = EmptyGraph.instance().traversal().withRemote(DriverRemoteConnection.using(sclient))
 
 Traversal t1 = g.addV("Person").property(T.id, 1).property("Name", "Justin"); ------ 1
 sclient.submit(GroovyTranslator.of("g").translate(t1.asAdmin().getBytecode()))
 
 Traversal t2 = g.addV("Person").property(T.id, 2).property("Name", "Langer"); ------ 2
 sclient.submit(GroovyTranslator.of("g").translate(t2.asAdmin().getBytecode()))
 
 
 // throw SomeException("some exeception....")      ------------------------------ 3
 
 Traversal t4 = g.addE("Edge Label").from(g.V(1)).to(g.V(2));    ------------------- 4
 sclient.submit(GroovyTranslator.of("g").translate(t2.asAdmin().getBytecode()))
 
 // all operations done now close sessioned client 
 sclient.close();      ------------------------------------------------------------- 

In above if an exception thrown from 3 then it won't close SessionedClient till it timeouts.

We can move sclient.close() to finally block using try-catch, this will execute 1 and 2 which actually should not be created as its executing as single transaction.

So I wanted to know if I can clear submitted queries (here in this case 1 and 2) and close the SessionedClient without executing already submitted queries.

Mayuresh
  • 11
  • 3

1 Answers1

0

This will be easier to do once Amazon Neptune moves up to the Apache TinkerPop 3.5.0 level. That release introduces session semantics and syntax for bytecode traversals so you will be able to explicitly rollback a session. In the meantime, if you issue a query that fails, such as trying to addV using an ID and label pair that already exists, that will cause the session to be aborted and rolled back. You will of course want to handle the exception that gets thrown. You should stay on a 3.4.x level Gremlin client driver also for this to work correctly.

Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38