How to Work with Transactions with Gremlin Python

I`m trying to implement transactions but I have two scenarios. I start a transaction but when I use iterate on every add_v it saves on my gremlin_server before the commit. The second situation is if if take out the .iterate() and run a commit() it doenst save on gremlin-server. What am I doing wrong?
No description
No description
3 Replies
Yang Xia
Yang Xia5d ago
Hi, for remote gremlin queries (using transaction or not), terminal steps have to be added in order for the traversal to be submitted to the server. So yes, iterate() will have to be included into each line, or else the driver is only constructing the queries but not sending them to the server. Another one that can be used is next(). For more information and a list of all terminal steps, see docs here.
Alex
AlexOP5d ago
Thanks for the response @Yang Xia, sorry for my lack of knowledge but what is the purpose of opening a transaction and commit its transaction if the iterate() send to the server already? Also the .rollback() doenst work if I try to use it after the iterate() on gremlin-server. I received this suggestion to use tranctions to try to have more performance than using query string, thats why I`m try to implement it and check the difference in performance.
Yang Xia
Yang Xia5d ago
Have to say I'm not the expert on transactions, but all transactional sessions are handled by the server side and not client side, so all traversals have to be submitted. To discard your changes, are you calling tx.rollback() before or after tx.commit()? The definition of rollback is that the server will roll back all the changes since the last commit, so what happens is when you iterate a traversal, it will be sent to the server and be processed. If you decide to keep the changes, you call tx.commit(), if you want to discard the changes you call tx.rollback() , which will discard up to the last tx.commit() call. Also to confirm, I see NEPTUNE inside your debug, are you using a local Gremlin Server or a Neptune database?
Want results from more Discord servers?
Add your server