Domanda

I was going through this Titan article. Here they are talking about transaction in Titan graph

Vertex v1 = g.addVertex(null);
//Do many other things
TransactionalGraph tx = g.newTransaction();
Vertex v2 = tx.addVertex(null);
v2.setProperty("uniqueName","foo");
tx.commit();
g.addEdge(null,v1,g.getVertex(v2),"related"); //Need to load v2 into outer transaction
//Do many other things
g.commit(); // Likely to fail due to lock congestion

This is ok if I am using TitanGraph but how should I handle transaction when using IdGraph? Shall i do something like below:

    // baseGraph is TitanGraph,   g is IdGraph

    TransactionalGraph tx = baseGraph.newTransaction();
    Vertex v = g.addVertex(pageId);

    v.setProperty("prop1",       prop1);
    v.setProperty("prop2",       prop2);
    v.setProperty("prop3",       prop3);

    tx.commit();

    .....create some edges here

    g.commit();
È stato utile?

Soluzione

Interesting question. If I were doing that, my instinct would be to use baseGraph to start the new transaction, then wrap the created tx in IdGraph as follows:

// baseGraph is TitanGraph,   g is IdGraph
TransactionalGraph tx = baseGraph.newTransaction();
IdGraph txId = new IdGraph(tx);
Vertex v = txId.addVertex(pageId);

v.setProperty("prop1",       prop1);
v.setProperty("prop2",       prop2);
v.setProperty("prop3",       prop3);

txId.commit();

.....create some edges here using txId

txId.commit();

Wrapping the baseGraph in IdGraph only decorates g with that feature. Since tx is a "new" graph instance, it too needs to be wrapped as well to get decorated with IdGraph features. Note that the above code will not work until this issue is resolved:

https://github.com/thinkaurelius/titan/issues/592

I didn't realize that such a wrapping was not possible until this question came up.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top