当我尝试创建新的索引时,也会发生这种情况。我使用脚本在某个属性下创建一个带有一些数据的新索引。该脚本来自于Titan 1.0.0文档。
graph.tx().rollback()
mgmt = graph.openManagement()
name = mgmt.getPropertyKey('name')
age = mgmt.getPropertyKey('age')
mgmt.buildIndex('byNameComposite', Vertex.class).addKey(name).buildCompositeIndex()
mgmt.buildIndex('byNameAndAgeComposite', Vertex.class).addKey(name).addKey(age).buildCompositeIndex()
mgmt.commit()
mgmt.awaitGraphIndexStatus(graph, 'byNameComposite').call()
mgmt.awaitGraphIndexStatus(graph, 'byNameAndAgeComposite').call()
mgmt = graph.openManagement()
mgmt.updateIndex(mgmt.getGraphIndex("byNameComposite"), SchemaAction.REINDEX).get()
mgmt.updateIndex(mgmt.getGraphIndex("byNameAndAgeComposite"), SchemaAction.REINDEX).get()
mgmt.commit()
经过多次实验,我发现graph.tx().rollback()
不能正常工作。
gremlin> :> graph.getOpenTransactions()
==>standardtitantx[0x1e14c346]
==>standardtitantx[0x7a0067f2]
==>standardtitantx[0x0de3ee40]
==>standardtitantx[0x47e19812]
==>standardtitantx[0x27b20549]
==>standardtitantx[0x0ee46d99]
gremlin> :> graph.tx().rollback()
==>null
gremlin> :> graph.getOpenTransactions()
==>standardtitantx[0x1e14c346]
==>standardtitantx[0x7a0067f2]
==>standardtitantx[0x0de3ee40]
==>standardtitantx[0x47e19812]
==>standardtitantx[0x093ac20f]
==>standardtitantx[0x27b20549]
==>standardtitantx[0x0ee46d99]
这就是为什么我无法创建一个新索引。因此,我用
graph.tx().rollback()
替换了它。
int size = graph.getOpenTransactions().size();
for(i=0;i<size;i++) {graph.getOpenTransactions().getAt(0).rollback()}
现在它运行良好。如果您使用集群,则需要确保仅一个实例生存。否则,您必须确保集群中所有实例的事务都回滚或提交。
希望这对其他人有所帮助。