Follow

So Gremlin Python ( Tinkerpop 3 ) does not have transaction support. So only way to get transaction like behavior is to make sure you do everything in a single database traversal.

Because I am writing an ORM / OGM model as my base that means I needed to implement something that looks like optimistic locking all my own (only works on immutable write-only graphs). Its a huge pain in the ass.

Anyway after half a day I finally figured out this is the traversal I need to resolve my optimistic lock when creating a single new node in the DB:

session.g.E().has('dirty',1).aggregate('x').fold().V().has('dirty',1).aggregate('x').choose(__.V().hasLabel('account').has("fingerprint", "DEADF00D").hasNot('dirty').count().is_(0), __.select('x').unfold().properties('dirty').drop()).iterate()

it looks for all nodes that have a property called "fingerprint" with a value called "DEADF00D" that does not have a property called "dirty".. If there are no nodes that match that criteria then it takes all nodes and edges with a property of "dirty" and a value of "1" and drops the dirty property from it.

I had to implement something akin to optimistic locking which means when i add a bunch of nodes and edges to the graph at first they get added one at a time with a property set called "dirty" and a value that is some sort of UUID for all the nodes/edges in the transaction.

Then I write a step that validates it and either drops the dirty property if the transaction is successful or if the transaction fails then all nodes/edges that are dirty are dropped entierly and the transaction can be reattempted.

Sign in to participate in the conversation
CleverLibre Social

CleverLibre Social is an inclusive social instance for open discussion, learning, and community.
All cultures welcome.
Hate speech and harassment strictly forbidden.