Gremlin rollback is not working

102 views
Skip to first unread message

smita padhy

unread,
Aug 6, 2019, 1:50:18 AM8/6/19
to Gremlin-users
Hi,
  I have a requirement where a list of requests which can add , delete or edit vertex in orient db need to be executed in batch. If any of the operation fails the system should rollback all the transactions. 
I am using orientdb.

Below is the pseudocode -

  public void changeData(List reqs)
 {
     Graph graph = OrientGraph.open(dbName , url , password);
     graph.tx().open();
     
      for(Req req: reqs)
      {
         try{
                 createVertex(req, graph);
graph.tx().commit();
}catch(Exception e)
{
graph.tx().rollback();
}
      }
 }
   
  public void createVertex(Req req , Graph g)
  {
  Vertex v = g.addVertex(req.getName());
nodeId = v.id();
Map<String , Object> attributes = req.getProperties();
attributes.forEach((key,val)->{
v.property(key ,val);
});
  //do some more processing logical processing which can throw error. When error is thrown after this line the vertex is created in dbName
  throw new Exception();
  }

The above code executes creation of vertex successfully , but after the error is thrown because of further processing the transaction is not rolled back. The vertex get created in db.

Please can you tell me how can i fix this issue.

Regards
Smita

Stephen Mallette

unread,
Aug 6, 2019, 7:08:50 AM8/6/19
to gremli...@googlegroups.com
fwiw, i would expect your code to behave as you expect. A g.tx().rollback() should clean up the failed transaction and not commit anything to the database. I'm not completely familiar with the transactional semantics that OrientDB implements under TinkerPop3, so you may need to ask OrientDB developers directly, but I noted that OrientDB transactions are not enabled by default. You must specifically enabled them via configuration:


I'm not sure if that's just for remote configurations or not.....docs are a bit confusing to me. 

Separately, I notice that you are using the Graph API to mutate your graph, meaning you are calling methods like:

Graph.addVertex()

Rather than do that, we recommend doing all your graph interaction operations with Gremlin (i.e. Traversal API), so prefer:

GraphTraversalSource g = graph.traversal()
g.addV().....

Here is some more information on the topic:




--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/05999a81-a5ed-427f-8895-141c90463fee%40googlegroups.com.

smita padhy

unread,
Aug 7, 2019, 4:52:24 AM8/7/19
to Gremlin-users
Hi Stephen,
  Thanks for your reply. 
   I am already opening the a transaction and then committing and  closing it. Also the add vertex is on g.traversal().addVertex(). Sorry missed in the psuedocode.
   I am not able to figure out why the data is getting committed before graph.tx().commit() is called. 
 
Regards
Smita

Stephen Mallette

unread,
Aug 7, 2019, 6:46:54 AM8/7/19
to gremli...@googlegroups.com
I'm not sure that we have too many OrientDB experts who follow this list - you might need to try their support channels for more help. This problem seems like one specific to OrientDB. To prove it to yourself, you might just changeout OrientDB for Neo4jGraph and see if your code still fails. 

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages