我正在阅读这篇泰坦文章。在这里,他们谈论的是泰坦图中的交易
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
如果我使用TitanGraph
这没关系,但是使用IdGraph
时我应该如何处理交易?我应该做如下的事情吗:
// 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();
有趣的问题。 如果我这样做,我的直觉是使用baseGraph
来启动新事务,然后将创建的tx
包装在IdGraph
中,如下所示:
// 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();
将baseGraph
包裹在IdGraph
中只会用该功能装饰g
。 由于tx
是一个"新"图形实例,因此也需要对其进行包装,以便使用IdGraph
特征进行装饰。 请注意,在解决此问题之前,上述代码将不起作用:
https://github.com/thinkaurelius/titan/issues/592
直到这个问题出现,我才意识到这样的包装是不可能的。