graph-databases - 泰坦图数据库 : handling Transaction in IdGraph

标签 graph-databases titan

我正在经历这个Titan article 。这里他们谈论的是泰坦图中的交易

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 是一个"new"图形实例,因此也需要对其进行包装以使用 IdGraph 功能进行装饰。请注意,在解决此问题之前,上述代码将不起作用:

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

直到这个问题出现之前,我才意识到这样的包装是不可能的。

关于graph-databases - 泰坦图数据库 : handling Transaction in IdGraph,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21658776/

相关文章:

python - 属性错误: 'module' object has no attribute 'GraphDatabaseService'

titan - Gremlin - 如何在不明确列出属性的情况下合并顶点以组合它们的属性?

Titan:索引 verticesIndex 上的某些键当前状态不为 REGISTERED

graph - 泰坦 : Gremlin query returns inconsistent results on repeated execution

graph - 如何使用 Spark 处理大型 Titan Graph

java - 找不到 jps 命令。将 JDK 的 jps 二进制文件放在命令路径上

csv - 将 LUBM 大学数据加载到 Neo4j

java - 如何将 gremlin 格式的 CSV 文件加载到 AWS Neptune 中

java - org.neo4j.ogm.exception.core.MappingException : More than one class has simple name

neo4j - 适用于电子商务网站的推荐算法,使用neo4j图数据库解决